Completed
Push — master ( 4207f0...333332 )
by Kamil
23:19 queued 01:42
created

it_implements_translator_bag_interface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\ThemeBundle\Translation;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
17
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
18
use Sylius\Bundle\ThemeBundle\Translation\Translator;
19
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
20
use Symfony\Component\Translation\MessageCatalogueInterface;
21
use Symfony\Component\Translation\TranslatorBagInterface;
22
use Symfony\Component\Translation\TranslatorInterface;
23
24
/**
25
 * @mixin Translator
26
 *
27
 * @author Kamil Kokot <[email protected]>
28
 */
29
class TranslatorSpec extends ObjectBehavior
30
{
31
    function let(
32
        TranslatorInterface $translator,
33
        ThemeContextInterface $themeContext
34
    ) {
35
        $translator->implement(TranslatorBagInterface::class);
36
37
        $this->beConstructedWith($translator, $themeContext);
38
    }
39
40
    function it_is_initializable()
41
    {
42
        $this->shouldHaveType('Sylius\Bundle\ThemeBundle\Translation\Translator');
43
    }
44
45
    function it_implements_translator_interface()
46
    {
47
        $this->shouldImplement(TranslatorInterface::class);
48
    }
49
50
    function it_implements_translator_bag_interface()
51
    {
52
        $this->shouldImplement(TranslatorBagInterface::class);
53
    }
54
55
    function it_implements_warmable_interface()
56
    {
57
        $this->shouldImplement(WarmableInterface::class);
58
    }
59
60
    function it_proxies_getting_the_locale_to_the_decorated_translator(TranslatorInterface $translator)
61
    {
62
        $translator->getLocale()->willReturn('pl_PL');
63
64
        $this->getLocale()->shouldReturn('pl_PL');
65
    }
66
67
    function it_proxies_setting_the_locale_to_the_decorated_translator(TranslatorInterface $translator)
68
    {
69
        $translator->setLocale('pl_PL')->shouldBeCalled();
70
71
        $this->setLocale('pl_PL');
72
    }
73
74
    function it_translates_id_using_theme_translations(
75
        TranslatorInterface $translator,
76
        ThemeContextInterface $themeContext,
77
        ThemeInterface $theme
78
    ) {
79
        $theme->getSlug()->willReturn('theme/slug');
80
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
81
82
        $translator->trans('id|theme/slug', Argument::cetera())->willReturn('Theme translation');
83
        $translator->trans('id', Argument::cetera())->shouldNotBeCalled();
84
85
        $this->trans('id')->shouldReturn('Theme translation');
86
    }
87
88
    function it_translates_id_using_default_translations(
89
        TranslatorInterface $translator,
90
        ThemeContextInterface $themeContext,
91
        ThemeInterface $theme
92
    ) {
93
        $theme->getSlug()->willReturn('theme/slug');
94
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
95
96
        $translator->trans('id|theme/slug', Argument::cetera())->willReturn('id|theme/slug');
97
        $translator->trans('id', Argument::cetera())->willReturn('Default translation');
98
99
        $this->trans('id')->shouldReturn('Default translation');
100
    }
101
102
    function it_returns_id_if_there_is_no_given_translation(
103
        TranslatorInterface $translator,
104
        ThemeContextInterface $themeContext,
105
        ThemeInterface $theme
106
    ) {
107
        $theme->getSlug()->willReturn('theme/slug');
108
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
109
110
        $translator->trans('id|theme/slug', Argument::cetera())->willReturn('id|theme/slug');
111
        $translator->trans('id', Argument::cetera())->willReturn('id');
112
113
        $this->trans('id')->shouldReturn('id');
114
    }
115
116
    function it_choice_translates_id_using_theme_translations(
117
        TranslatorInterface $translator,
118
        ThemeContextInterface $themeContext,
119
        ThemeInterface $theme
120
    ) {
121
        $theme->getSlug()->willReturn('theme/slug');
122
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
123
124
        $translator->transChoice('id|theme/slug', 42, Argument::cetera())->willReturn('Theme translation');
125
        $translator->transChoice('id', 42, Argument::cetera())->shouldNotBeCalled();
126
127
        $this->transChoice('id', 42)->shouldReturn('Theme translation');
128
    }
129
130
    function it_choice_translates_id_using_default_translations(
131
        TranslatorInterface $translator,
132
        ThemeContextInterface $themeContext,
133
        ThemeInterface $theme
134
    ) {
135
        $theme->getSlug()->willReturn('theme/slug');
136
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
137
138
        $translator->transChoice('id|theme/slug', 42, Argument::cetera())->willReturn('id|theme/slug');
139
        $translator->transChoice('id', 42, Argument::cetera())->willReturn('Default translation');
140
141
        $this->transChoice('id', 42)->shouldReturn('Default translation');
142
    }
143
144
    function it_returns_id_if_there_is_no_given_choice_translation(
145
        TranslatorInterface $translator,
146
        ThemeContextInterface $themeContext,
147
        ThemeInterface $theme
148
    ) {
149
        $theme->getSlug()->willReturn('theme/slug');
150
        $themeContext->getThemeHierarchy()->willReturn([$theme]);
151
152
        $translator->transChoice('id|theme/slug', 42, Argument::cetera())->willReturn('id|theme/slug');
153
        $translator->transChoice('id', 42, Argument::cetera())->willReturn('id');
154
155
        $this->transChoice('id', 42)->shouldReturn('id');
156
    }
157
158
    function it_proxies_getting_catalogue_for_given_locale_to_the_decorated_translator(
159
        TranslatorBagInterface $translator,
160
        MessageCatalogueInterface $messageCatalogue
161
    ) {
162
        $translator->getCatalogue('pl_PL')->willReturn($messageCatalogue);
163
164
        $this->getCatalogue('pl_PL')->shouldReturn($messageCatalogue);
165
    }
166
167
    function it_does_not_warm_up_if_decorated_translator_is_not_warmable()
168
    {
169
        $this->warmUp('cache');
170
    }
171
172
    function it_warms_up_if_decorated_translator_is_warmable(WarmableInterface $translator)
173
    {
174
        $translator->warmUp('cache')->shouldBeCalled();
175
176
        $this->warmUp('cache');
177
    }
178
}
179