1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Incenteev\TranslationCheckerBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Incenteev\TranslationCheckerBundle\DependencyInjection\IncenteevTranslationCheckerExtension; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
|
9
|
|
|
class IncenteevTranslationCheckerExtensionTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ContainerBuilder |
13
|
|
|
*/ |
14
|
|
|
private $containerBuilder; |
15
|
|
|
|
16
|
|
|
protected function setUp(): void |
17
|
|
|
{ |
18
|
|
|
$this->containerBuilder = new ContainerBuilder(); |
19
|
|
|
$this->containerBuilder->setParameter('kernel.bundles', array( |
20
|
|
|
'IncenteevTranslationCheckerBundle' => 'Incenteev\TranslationCheckerBundle\IncenteevTranslationCheckerBundle', |
21
|
|
|
'FrameworkBundle' => 'Symfony\Bundle\FrameworkBundle\FrameworkBundle', |
22
|
|
|
)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testDefaultPaths() |
26
|
|
|
{ |
27
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
28
|
|
|
|
29
|
|
|
$extension->load(array(), $this->containerBuilder); |
30
|
|
|
|
31
|
|
|
$this->assertParameter(array('%kernel.project_dir%/templates'), 'incenteev_translation_checker.extractor.symfony.paths'); |
32
|
|
|
$this->assertFalse($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testDefaultPathsWithRootDir() |
36
|
|
|
{ |
37
|
|
|
$this->containerBuilder->setParameter('kernel.root_dir', __DIR__); |
38
|
|
|
|
39
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
40
|
|
|
|
41
|
|
|
$extension->load(array(), $this->containerBuilder); |
42
|
|
|
|
43
|
|
|
$this->assertParameter(array( |
44
|
|
|
'%kernel.root_dir%/Resources/views', |
45
|
|
|
'%kernel.project_dir%/templates', |
46
|
|
|
), 'incenteev_translation_checker.extractor.symfony.paths'); |
47
|
|
|
$this->assertFalse($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testBundlePaths() |
51
|
|
|
{ |
52
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
53
|
|
|
|
54
|
|
|
$config = array('extraction' => array('bundles' => array('IncenteevTranslationCheckerBundle'))); |
55
|
|
|
|
56
|
|
|
$extension->load(array($config), $this->containerBuilder); |
57
|
|
|
|
58
|
|
|
$expectedPaths = array( |
59
|
|
|
dirname(dirname(__DIR__)).'/src/Resources/views', |
60
|
|
|
'%kernel.project_dir%/templates/bundles/IncenteevTranslationCheckerBundle', |
61
|
|
|
'%kernel.project_dir%/templates', |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertParameter($expectedPaths, 'incenteev_translation_checker.extractor.symfony.paths'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testBundlePathsWithRootDir() |
68
|
|
|
{ |
69
|
|
|
$this->containerBuilder->setParameter('kernel.root_dir', __DIR__); |
70
|
|
|
|
71
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
72
|
|
|
|
73
|
|
|
$config = array('extraction' => array('bundles' => array('IncenteevTranslationCheckerBundle'))); |
74
|
|
|
|
75
|
|
|
$extension->load(array($config), $this->containerBuilder); |
76
|
|
|
|
77
|
|
|
$expectedPaths = array( |
78
|
|
|
dirname(dirname(__DIR__)).'/src/Resources/views', |
79
|
|
|
'%kernel.root_dir%/Resources/IncenteevTranslationCheckerBundle/views', |
80
|
|
|
'%kernel.project_dir%/templates/bundles/IncenteevTranslationCheckerBundle', |
81
|
|
|
'%kernel.root_dir%/Resources/views', |
82
|
|
|
'%kernel.project_dir%/templates', |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$this->assertParameter($expectedPaths, 'incenteev_translation_checker.extractor.symfony.paths'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testNotRegisteredBundle() |
89
|
|
|
{ |
90
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
91
|
|
|
|
92
|
|
|
$config = array('extraction' => array('bundles' => array('TwigBundle'))); |
93
|
|
|
|
94
|
|
|
$this->expectException(\InvalidArgumentException::class); |
95
|
|
|
$this->expectExceptionMessage('The bundle TwigBundle is not registered in the kernel.'); |
96
|
|
|
|
97
|
|
|
$extension->load(array($config), $this->containerBuilder); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testJsExtractionPaths() |
101
|
|
|
{ |
102
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
103
|
|
|
|
104
|
|
|
$config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js')))); |
105
|
|
|
|
106
|
|
|
$extension->load(array($config), $this->containerBuilder); |
107
|
|
|
|
108
|
|
|
$this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
109
|
|
|
|
110
|
|
|
$def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js'); |
111
|
|
|
|
112
|
|
|
$this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0)); |
113
|
|
|
$this->assertEquals('messages', $def->getArgument(1)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testJsExtractionDomain() |
117
|
|
|
{ |
118
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
119
|
|
|
|
120
|
|
|
$config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js'), 'default_domain' => 'js_messages'))); |
121
|
|
|
|
122
|
|
|
$extension->load(array($config), $this->containerBuilder); |
123
|
|
|
|
124
|
|
|
$this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
125
|
|
|
|
126
|
|
|
$def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js'); |
127
|
|
|
|
128
|
|
|
$this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0)); |
129
|
|
|
$this->assertEquals('js_messages', $def->getArgument(1)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param mixed $value |
134
|
|
|
*/ |
135
|
|
|
private function assertParameter($value, string $key): void |
136
|
|
|
{ |
137
|
|
|
$this->assertEquals($value, $this->containerBuilder->getParameter($key), sprintf('%s parameter is correct', $key)); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|