Completed
Push — locale-in-url ( 6507a9...826ca7 )
by Kamil
18:41
created

AdminBasedLocaleContextSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 52
rs 10

6 Methods

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