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\AdminBundle\Context; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Core\Model\AdminUserInterface; |
18
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
19
|
|
|
use Sylius\Component\Locale\Context\LocaleNotFoundException; |
20
|
|
|
use Sylius\Component\User\Model\UserInterface; |
21
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
22
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
23
|
|
|
|
24
|
|
|
final class AdminBasedLocaleContextSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function let(TokenStorageInterface $tokenStorage): void |
27
|
|
|
{ |
28
|
|
|
$this->beConstructedWith($tokenStorage); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_implements_locale_context_interface(): void |
32
|
|
|
{ |
33
|
|
|
$this->shouldImplement(LocaleContextInterface::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_throws_locale_not_found_exception_when_there_is_no_token(TokenStorageInterface $tokenStorage): void |
37
|
|
|
{ |
38
|
|
|
$tokenStorage->getToken()->willReturn(null); |
39
|
|
|
|
40
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_throws_locale_not_found_exception_when_there_is_no_user_in_the_token( |
44
|
|
|
TokenStorageInterface $tokenStorage, |
45
|
|
|
TokenInterface $token |
46
|
|
|
): void { |
47
|
|
|
$token->getUser()->willReturn(null); |
48
|
|
|
$tokenStorage->getToken()->willReturn($token); |
49
|
|
|
|
50
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_throws_locale_not_found_exception_when_the_user_taken_from_token_is_not_an_admin( |
54
|
|
|
TokenStorageInterface $tokenStorage, |
55
|
|
|
TokenInterface $token, |
56
|
|
|
UserInterface $user |
57
|
|
|
): void { |
58
|
|
|
$token->getUser()->willReturn($user); |
59
|
|
|
$tokenStorage->getToken()->willReturn($token); |
60
|
|
|
|
61
|
|
|
$this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_returns_locale_of_currently_logged_admin_user( |
65
|
|
|
TokenStorageInterface $tokenStorage, |
66
|
|
|
TokenInterface $token, |
67
|
|
|
AdminUserInterface $admin |
68
|
|
|
): void { |
69
|
|
|
$admin->getLocaleCode()->willReturn('en_US'); |
70
|
|
|
$token->getUser()->willreturn($admin); |
71
|
|
|
$tokenStorage->getToken()->willReturn($token); |
72
|
|
|
|
73
|
|
|
$this->getLocaleCode()->shouldReturn('en_US'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|