|
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 Sylius\Bundle\ThemeBundle\Tests\Translation\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
15
|
|
|
use Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler\TranslatorFallbackLocalesPass; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Kamil Kokot <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class TranslatorFallbackLocalesPassTest extends AbstractCompilerPassTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @test |
|
26
|
|
|
*/ |
|
27
|
|
|
public function it_copies_method_call_that_sets_fallback_locales_to_theme_translator() |
|
28
|
|
|
{ |
|
29
|
|
|
$symfonyTranslatorDefinition = new Definition(); |
|
|
|
|
|
|
30
|
|
|
$symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']); |
|
31
|
|
|
$this->setDefinition('translator.default', $symfonyTranslatorDefinition); |
|
32
|
|
|
|
|
33
|
|
|
$this->setDefinition('sylius.theme.translation.translator', new Definition()); |
|
34
|
|
|
|
|
35
|
|
|
$this->compile(); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
38
|
|
|
'sylius.theme.translation.translator', |
|
39
|
|
|
'setFallbackLocales', |
|
40
|
|
|
['pl_PL'] |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @test |
|
46
|
|
|
*/ |
|
47
|
|
|
public function it_filters_out_other_method_calls_to_symfony_translator() |
|
48
|
|
|
{ |
|
49
|
|
|
$symfonyTranslatorDefinition = new Definition(); |
|
|
|
|
|
|
50
|
|
|
$symfonyTranslatorDefinition->addMethodCall('doFooAndBar', ['argument1', 'argument2']); |
|
51
|
|
|
$symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']); |
|
52
|
|
|
$symfonyTranslatorDefinition->addMethodCall('doFoo', ['argument1']); |
|
53
|
|
|
$this->setDefinition('translator.default', $symfonyTranslatorDefinition); |
|
54
|
|
|
|
|
55
|
|
|
$this->setDefinition('sylius.theme.translation.translator', new Definition()); |
|
56
|
|
|
|
|
57
|
|
|
$this->compile(); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
60
|
|
|
'sylius.theme.translation.translator', |
|
61
|
|
|
'setFallbackLocales', |
|
62
|
|
|
['pl_PL'] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @test |
|
68
|
|
|
*/ |
|
69
|
|
|
public function it_copies_method_calls_that_set_fallback_locales_to_theme_translator() |
|
70
|
|
|
{ |
|
71
|
|
|
$symfonyTranslatorDefinition = new Definition(); |
|
|
|
|
|
|
72
|
|
|
$symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']); |
|
73
|
|
|
$symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['en_US']); |
|
74
|
|
|
$this->setDefinition('translator.default', $symfonyTranslatorDefinition); |
|
75
|
|
|
|
|
76
|
|
|
$this->setDefinition('sylius.theme.translation.translator', new Definition()); |
|
77
|
|
|
|
|
78
|
|
|
$this->compile(); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
81
|
|
|
'sylius.theme.translation.translator', |
|
82
|
|
|
'setFallbackLocales', |
|
83
|
|
|
['pl_PL'] |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
87
|
|
|
'sylius.theme.translation.translator', |
|
88
|
|
|
'setFallbackLocales', |
|
89
|
|
|
['en_US'] |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @test |
|
95
|
|
|
*/ |
|
96
|
|
|
public function it_does_not_force_symfony_translator_to_have_any_method_calls() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->setDefinition('translator.default', new Definition()); |
|
99
|
|
|
$this->setDefinition('sylius.theme.translation.translator', new Definition()); |
|
100
|
|
|
|
|
101
|
|
|
$this->compile(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
108
|
|
|
{ |
|
109
|
|
|
$container->addCompilerPass(new TranslatorFallbackLocalesPass()); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.