|
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\TranslatorLoaderProviderPass; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Kamil Kokot <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class TranslatorLoaderProviderPassTest extends AbstractCompilerPassTestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @test |
|
27
|
|
|
*/ |
|
28
|
|
|
public function it_adds_translation_loaders_to_sylius_loader_provider() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); |
|
31
|
|
|
|
|
32
|
|
|
$translationLoaderDefinition = new Definition(); |
|
|
|
|
|
|
33
|
|
|
$translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']); |
|
34
|
|
|
$this->setDefinition('translation.loader.yml', $translationLoaderDefinition); |
|
35
|
|
|
|
|
36
|
|
|
$this->compile(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
39
|
|
|
'sylius.theme.translation.loader_provider', |
|
40
|
|
|
0, |
|
41
|
|
|
['yml' => new Reference('translation.loader.yml')] |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @test |
|
47
|
|
|
*/ |
|
48
|
|
|
public function it_adds_translation_loaders_with_its_legacy_alias_to_sylius_loader_provider() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); |
|
51
|
|
|
|
|
52
|
|
|
$translationLoaderDefinition = new Definition(); |
|
|
|
|
|
|
53
|
|
|
$translationLoaderDefinition->addTag('translation.loader', ['alias' => 'xlf', 'legacy-alias' => 'xliff']); |
|
54
|
|
|
$this->setDefinition('translation.loader.xliff', $translationLoaderDefinition); |
|
55
|
|
|
|
|
56
|
|
|
$this->compile(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
59
|
|
|
'sylius.theme.translation.loader_provider', |
|
60
|
|
|
0, |
|
61
|
|
|
['xlf' => new Reference('translation.loader.xliff'), 'xliff' => new Reference('translation.loader.xliff')] |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @test |
|
67
|
|
|
*/ |
|
68
|
|
|
public function it_adds_translation_loaders_using_only_the_first_tag_alias() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); |
|
71
|
|
|
|
|
72
|
|
|
$translationLoaderDefinition = new Definition(); |
|
|
|
|
|
|
73
|
|
|
$translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']); |
|
74
|
|
|
$translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yaml']); |
|
75
|
|
|
$this->setDefinition('translation.loader.yml', $translationLoaderDefinition); |
|
76
|
|
|
|
|
77
|
|
|
$this->compile(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
80
|
|
|
'sylius.theme.translation.loader_provider', |
|
81
|
|
|
0, |
|
82
|
|
|
['yml' => new Reference('translation.loader.yml')] |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @test |
|
88
|
|
|
*/ |
|
89
|
|
|
public function it_does_not_force_the_existence_of_translation_loaders() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); |
|
92
|
|
|
|
|
93
|
|
|
$this->compile(); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
96
|
|
|
'sylius.theme.translation.loader_provider', |
|
97
|
|
|
0, |
|
98
|
|
|
[] |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* {@inheritdoc} |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
106
|
|
|
{ |
|
107
|
|
|
$container->addCompilerPass(new TranslatorLoaderProviderPass()); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.