1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\LocaleBundle\Context; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\LocaleBundle\Context\RequestBasedLocaleContext; |
18
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
19
|
|
|
use Sylius\Component\Locale\Context\LocaleNotFoundException; |
20
|
|
|
use Sylius\Component\Locale\Provider\LocaleProviderInterface; |
21
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Kamil Kokot <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class RequestBasedLocaleContextSpec extends ObjectBehavior |
29
|
|
|
{ |
30
|
|
|
function let(RequestStack $requestStack, LocaleProviderInterface $localeProvider): void |
31
|
|
|
{ |
32
|
|
|
$this->beConstructedWith($requestStack, $localeProvider); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_is_a_locale_context(): void |
36
|
|
|
{ |
37
|
|
|
$this->shouldImplement(LocaleContextInterface::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_throws_locale_not_found_exception_if_master_request_is_not_found(RequestStack $requestStack): void |
41
|
|
|
{ |
42
|
|
|
$requestStack->getMasterRequest()->willReturn(null); |
43
|
|
|
|
44
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_throws_locale_not_found_exception_if_master_request_does_not_have_locale_attribute( |
48
|
|
|
RequestStack $requestStack, |
49
|
|
|
Request $request |
50
|
|
|
): void { |
51
|
|
|
$requestStack->getMasterRequest()->willReturn($request); |
52
|
|
|
|
53
|
|
|
$request->attributes = new ParameterBag(); |
54
|
|
|
|
55
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_throws_locale_not_found_exception_if_master_request_locale_code_is_not_among_available_ones( |
59
|
|
|
RequestStack $requestStack, |
60
|
|
|
LocaleProviderInterface $localeProvider, |
61
|
|
|
Request $request |
62
|
|
|
): void { |
63
|
|
|
$requestStack->getMasterRequest()->willReturn($request); |
64
|
|
|
|
65
|
|
|
$request->attributes = new ParameterBag(['_locale' => 'en_US']); |
66
|
|
|
|
67
|
|
|
$localeProvider->getAvailableLocalesCodes()->willReturn(['pl_PL', 'de_DE']); |
68
|
|
|
|
69
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function it_returns_master_request_locale_code( |
73
|
|
|
RequestStack $requestStack, |
74
|
|
|
LocaleProviderInterface $localeProvider, |
75
|
|
|
Request $request |
76
|
|
|
): void { |
77
|
|
|
$requestStack->getMasterRequest()->willReturn($request); |
78
|
|
|
|
79
|
|
|
$request->attributes = new ParameterBag(['_locale' => 'pl_PL']); |
80
|
|
|
|
81
|
|
|
$localeProvider->getAvailableLocalesCodes()->willReturn(['pl_PL', 'de_DE']); |
82
|
|
|
|
83
|
|
|
$this->getLocaleCode()->shouldReturn('pl_PL'); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|