Completed
Push — ezp26828-trigger_crowdin_in_co... ( fa2c05 )
by
unknown
19:34
created

testSetRequestsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.4285
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Bundle\EzPublishCoreBundle\Tests\EventSubscriber;
7
8
use eZ\Bundle\EzPublishCoreBundle\EventSubscriber\CrowdinRequestLocaleSubscriber;
9
use PHPUnit_Framework_TestCase;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
12
use Symfony\Component\HttpKernel\HttpKernelInterface;
13
14
class CrowdinRequestLocaleSubscriberTest extends PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @dataProvider testSetRequestsProvider
18
     */
19
    public function testSetLocale(Request $request, $shouldHaveCustomLocale)
20
    {
21
        $event = new GetResponseEvent(
22
            $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(),
23
            $request,
24
            HttpKernelInterface::MASTER_REQUEST
25
        );
26
27
        $subscriber = new CrowdinRequestLocaleSubscriber();
28
        $subscriber->setInContextAcceptLanguage($event);
29
30
        $this->assertEquals(
31
            $shouldHaveCustomLocale,
32
            'ach_UG' === $event->getRequest()->getPreferredLanguage(),
33
            'The custom ach_UG locale was expected to be set by the event subscriber'
34
        );
35
    }
36
37
    public function testSetRequestsProvider()
38
    {
39
        return [
40
            'with_ez_in_context_translation_cookie' => [
41
                new Request([], [], [], ['ez_in_context_translation' => '1']),
42
                true,
43
            ],
44
            'without_ez_in_context_translation_cookie' => [
45
                new Request([], [], [], []),
46
                false,
47
            ],
48
        ];
49
    }
50
}
51