|
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() |
|
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
|
|
|
/** |
|
89
|
|
|
* @expectedException \InvalidArgumentException |
|
90
|
|
|
* @expectedExceptionMessage The bundle TwigBundle is not registered in the kernel. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testNotRegisteredBundle() |
|
93
|
|
|
{ |
|
94
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
|
95
|
|
|
|
|
96
|
|
|
$config = array('extraction' => array('bundles' => array('TwigBundle'))); |
|
97
|
|
|
|
|
98
|
|
|
$extension->load(array($config), $this->containerBuilder); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function testJsExtractionPaths() |
|
102
|
|
|
{ |
|
103
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
|
104
|
|
|
|
|
105
|
|
|
$config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js')))); |
|
106
|
|
|
|
|
107
|
|
|
$extension->load(array($config), $this->containerBuilder); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
|
110
|
|
|
|
|
111
|
|
|
$def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js'); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0)); |
|
114
|
|
|
$this->assertEquals('messages', $def->getArgument(1)); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function testJsExtractionDomain() |
|
118
|
|
|
{ |
|
119
|
|
|
$extension = new IncenteevTranslationCheckerExtension(); |
|
120
|
|
|
|
|
121
|
|
|
$config = array('extraction' => array('js' => array('paths' => array('%kernel.project_dir%/web/js'), 'default_domain' => 'js_messages'))); |
|
122
|
|
|
|
|
123
|
|
|
$extension->load(array($config), $this->containerBuilder); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertTrue($this->containerBuilder->hasDefinition('incenteev_translation_checker.extractor.js')); |
|
126
|
|
|
|
|
127
|
|
|
$def = $this->containerBuilder->getDefinition('incenteev_translation_checker.extractor.js'); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertEquals(array('%kernel.project_dir%/web/js'), $def->getArgument(0)); |
|
130
|
|
|
$this->assertEquals('js_messages', $def->getArgument(1)); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param mixed $value |
|
135
|
|
|
* @param string $key |
|
136
|
|
|
*/ |
|
137
|
|
|
private function assertParameter($value, $key) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->assertEquals($value, $this->containerBuilder->getParameter($key), sprintf('%s parameter is correct', $key)); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|