1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
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 WBW\Bundle\CoreBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Exception; |
15
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
16
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\AmberColorProvider; |
17
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\BlueColorProvider; |
18
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\BlueGreyColorProvider; |
19
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\BrownColorProvider; |
20
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\CyanColorProvider; |
21
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\DeepOrangeColorProvider; |
22
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\DeepPurpleColorProvider; |
23
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\GreenColorProvider; |
24
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\GreyColorProvider; |
25
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\IndigoColorProvider; |
26
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\LightBlueColorProvider; |
27
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\LightGreenColorProvider; |
28
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\LimeColorProvider; |
29
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\OrangeColorProvider; |
30
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\PinkColorProvider; |
31
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\PurpleColorProvider; |
32
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\RedColorProvider; |
33
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\TealColorProvider; |
34
|
|
|
use WBW\Bundle\CoreBundle\Color\MaterialDesignColorPalette\YellowColorProvider; |
35
|
|
|
use WBW\Bundle\CoreBundle\Command\CopySkeletonCommand; |
36
|
|
|
use WBW\Bundle\CoreBundle\Command\UnzipAssetsCommand; |
37
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\Configuration; |
38
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\WBWCoreExtension; |
39
|
|
|
use WBW\Bundle\CoreBundle\EventListener\KernelEventListener; |
40
|
|
|
use WBW\Bundle\CoreBundle\EventListener\NotificationEventListener; |
41
|
|
|
use WBW\Bundle\CoreBundle\EventListener\SecurityEventListener; |
42
|
|
|
use WBW\Bundle\CoreBundle\EventListener\ToastEventListener; |
43
|
|
|
use WBW\Bundle\CoreBundle\Helper\FormHelper; |
44
|
|
|
use WBW\Bundle\CoreBundle\Manager\ColorManager; |
45
|
|
|
use WBW\Bundle\CoreBundle\Manager\QuoteManager; |
46
|
|
|
use WBW\Bundle\CoreBundle\Manager\ThemeManager; |
47
|
|
|
use WBW\Bundle\CoreBundle\Provider\Asset\SyntaxHighlighterStringsProvider; |
48
|
|
|
use WBW\Bundle\CoreBundle\Quote\YamlQuoteProvider; |
49
|
|
|
use WBW\Bundle\CoreBundle\Repository\RepositoryHelper; |
50
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
51
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\FontAwesomeTwigExtension; |
52
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\JQueryInputMaskTwigExtension; |
53
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\MaterialDesignColorPaletteTwigExtension; |
54
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\MaterialDesignIconicFontTwigExtension; |
55
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\MeteoconsTwigExtension; |
56
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\SyntaxHighlighterTwigExtension; |
57
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\ContainerTwigExtension; |
58
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\JavascriptTwigExtension; |
59
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\QuoteTwigExtension; |
60
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension; |
61
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\StylesheetTwigExtension; |
62
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\UtilityTwigExtension; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Core extension test. |
66
|
|
|
* |
67
|
|
|
* @author webeweb <https://github.com/webeweb/> |
68
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\DependencyInjection |
69
|
|
|
*/ |
70
|
|
|
class WBWCoreExtensionTest extends AbstractTestCase { |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* World's wisdom quote provider. |
74
|
|
|
* |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
const WORLDS_WISDOM_QUOTE_PROVIDER_SERVICE_NAME = "wbw.core.provider.quote.worlds_wisdom"; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Configs. |
81
|
|
|
* |
82
|
|
|
* @var array |
83
|
|
|
*/ |
84
|
|
|
private $configs; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritDoc} |
88
|
|
|
*/ |
89
|
|
|
protected function setUp(): void { |
90
|
|
|
parent::setUp(); |
91
|
|
|
|
92
|
|
|
// Set a configs array mock. |
93
|
|
|
$this->configs = [ |
94
|
|
|
WBWCoreExtension::EXTENSION_ALIAS => [ |
95
|
|
|
"commands" => true, |
96
|
|
|
"event_listeners" => true, |
97
|
|
|
"providers" => true, |
98
|
|
|
"twig" => true, |
99
|
|
|
"quote_providers" => [], |
100
|
|
|
], |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Tests the getAlias() method. |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function testGetAlias(): void { |
110
|
|
|
|
111
|
|
|
$obj = new WBWCoreExtension(); |
112
|
|
|
|
113
|
|
|
$this->assertEquals("wbw_core", $obj->getAlias()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Tests the getConfiguration() method. |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
public function testGetConfiguration(): void { |
122
|
|
|
|
123
|
|
|
$obj = new WBWCoreExtension(); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf(Configuration::class, $obj->getConfiguration([], $this->containerBuilder)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Tests the load() method. |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
* @throws Exception Throws an exception if an error occurs. |
133
|
|
|
*/ |
134
|
|
|
public function testLoad(): void { |
135
|
|
|
|
136
|
|
|
$obj = new WBWCoreExtension(); |
137
|
|
|
|
138
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
139
|
|
|
|
140
|
|
|
// Commands |
141
|
|
|
$this->assertInstanceOf(CopySkeletonCommand::class, $this->containerBuilder->get(CopySkeletonCommand::SERVICE_NAME)); |
142
|
|
|
$this->assertInstanceOf(UnzipAssetsCommand::class, $this->containerBuilder->get(UnzipAssetsCommand::SERVICE_NAME)); |
143
|
|
|
|
144
|
|
|
// Event listeners |
145
|
|
|
$this->assertInstanceOf(KernelEventListener::class, $this->containerBuilder->get(KernelEventListener::SERVICE_NAME)); |
146
|
|
|
$this->assertInstanceOf(NotificationEventListener::class, $this->containerBuilder->get(NotificationEventListener::SERVICE_NAME)); |
147
|
|
|
$this->assertInstanceOf(ToastEventListener::class, $this->containerBuilder->get(ToastEventListener::SERVICE_NAME)); |
148
|
|
|
|
149
|
|
|
try { |
150
|
|
|
|
151
|
|
|
$this->containerBuilder->get(SecurityEventListener::SERVICE_NAME); |
152
|
|
|
} catch (Exception $ex) { |
153
|
|
|
|
154
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
155
|
|
|
$this->assertStringContainsString(SecurityEventListener::SERVICE_NAME, $ex->getMessage()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// Helpers |
159
|
|
|
$this->assertInstanceOf(FormHelper::class, $this->containerBuilder->get(FormHelper::SERVICE_NAME)); |
160
|
|
|
$this->assertInstanceOf(RepositoryHelper::class, $this->containerBuilder->get(RepositoryHelper::SERVICE_NAME)); |
161
|
|
|
|
162
|
|
|
// Managers |
163
|
|
|
$this->assertInstanceOf(ColorManager::class, $this->containerBuilder->get(ColorManager::SERVICE_NAME)); |
164
|
|
|
$this->assertInstanceOf(QuoteManager::class, $this->containerBuilder->get(QuoteManager::SERVICE_NAME)); |
165
|
|
|
$this->assertInstanceOf(ThemeManager::class, $this->containerBuilder->get(ThemeManager::SERVICE_NAME)); |
166
|
|
|
|
167
|
|
|
// Providers |
168
|
|
|
$this->assertInstanceOf(SyntaxHighlighterStringsProvider::class, $this->containerBuilder->get(SyntaxHighlighterStringsProvider::SERVICE_NAME)); |
169
|
|
|
$this->assertInstanceOf(AmberColorProvider::class, $this->containerBuilder->get(AmberColorProvider::SERVICE_NAME)); |
170
|
|
|
$this->assertInstanceOf(BlueColorProvider::class, $this->containerBuilder->get(BlueColorProvider::SERVICE_NAME)); |
171
|
|
|
$this->assertInstanceOf(BlueGreyColorProvider::class, $this->containerBuilder->get(BlueGreyColorProvider::SERVICE_NAME)); |
172
|
|
|
$this->assertInstanceOf(BrownColorProvider::class, $this->containerBuilder->get(BrownColorProvider::SERVICE_NAME)); |
173
|
|
|
$this->assertInstanceOf(CyanColorProvider::class, $this->containerBuilder->get(CyanColorProvider::SERVICE_NAME)); |
174
|
|
|
$this->assertInstanceOf(DeepOrangeColorProvider::class, $this->containerBuilder->get(DeepOrangeColorProvider::SERVICE_NAME)); |
175
|
|
|
$this->assertInstanceOf(DeepPurpleColorProvider::class, $this->containerBuilder->get(DeepPurpleColorProvider::SERVICE_NAME)); |
176
|
|
|
$this->assertInstanceOf(GreenColorProvider::class, $this->containerBuilder->get(GreenColorProvider::SERVICE_NAME)); |
177
|
|
|
$this->assertInstanceOf(GreyColorProvider::class, $this->containerBuilder->get(GreyColorProvider::SERVICE_NAME)); |
178
|
|
|
$this->assertInstanceOf(IndigoColorProvider::class, $this->containerBuilder->get(IndigoColorProvider::SERVICE_NAME)); |
179
|
|
|
$this->assertInstanceOf(LightBlueColorProvider::class, $this->containerBuilder->get(LightBlueColorProvider::SERVICE_NAME)); |
180
|
|
|
$this->assertInstanceOf(LightGreenColorProvider::class, $this->containerBuilder->get(LightGreenColorProvider::SERVICE_NAME)); |
181
|
|
|
$this->assertInstanceOf(LimeColorProvider::class, $this->containerBuilder->get(LimeColorProvider::SERVICE_NAME)); |
182
|
|
|
$this->assertInstanceOf(OrangeColorProvider::class, $this->containerBuilder->get(OrangeColorProvider::SERVICE_NAME)); |
183
|
|
|
$this->assertInstanceOf(PinkColorProvider::class, $this->containerBuilder->get(PinkColorProvider::SERVICE_NAME)); |
184
|
|
|
$this->assertInstanceOf(PurpleColorProvider::class, $this->containerBuilder->get(PurpleColorProvider::SERVICE_NAME)); |
185
|
|
|
$this->assertInstanceOf(RedColorProvider::class, $this->containerBuilder->get(RedColorProvider::SERVICE_NAME)); |
186
|
|
|
$this->assertInstanceOf(TealColorProvider::class, $this->containerBuilder->get(TealColorProvider::SERVICE_NAME)); |
187
|
|
|
$this->assertInstanceOf(YellowColorProvider::class, $this->containerBuilder->get(YellowColorProvider::SERVICE_NAME)); |
188
|
|
|
|
189
|
|
|
try { |
190
|
|
|
|
191
|
|
|
$this->containerBuilder->get(self::WORLDS_WISDOM_QUOTE_PROVIDER_SERVICE_NAME); |
192
|
|
|
} catch (Exception $ex) { |
193
|
|
|
|
194
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
195
|
|
|
$this->assertStringContainsString(self::WORLDS_WISDOM_QUOTE_PROVIDER_SERVICE_NAME, $ex->getMessage()); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
// Twig extensions |
199
|
|
|
$this->assertInstanceOf(ContainerTwigExtension::class, $this->containerBuilder->get(ContainerTwigExtension::SERVICE_NAME)); |
200
|
|
|
$this->assertInstanceOf(JavascriptTwigExtension::class, $this->containerBuilder->get(JavascriptTwigExtension::SERVICE_NAME)); |
201
|
|
|
$this->assertInstanceOf(QuoteTwigExtension::class, $this->containerBuilder->get(QuoteTwigExtension::SERVICE_NAME)); |
202
|
|
|
$this->assertInstanceOf(RendererTwigExtension::class, $this->containerBuilder->get(RendererTwigExtension::SERVICE_NAME)); |
203
|
|
|
$this->assertInstanceOf(StylesheetTwigExtension::class, $this->containerBuilder->get(StylesheetTwigExtension::SERVICE_NAME)); |
204
|
|
|
$this->assertInstanceOf(UtilityTwigExtension::class, $this->containerBuilder->get(UtilityTwigExtension::SERVICE_NAME)); |
205
|
|
|
|
206
|
|
|
// Assets Twig extensions |
207
|
|
|
$this->assertInstanceOf(FontAwesomeTwigExtension::class, $this->containerBuilder->get(FontAwesomeTwigExtension::SERVICE_NAME)); |
208
|
|
|
$this->assertInstanceOf(JQueryInputMaskTwigExtension::class, $this->containerBuilder->get(JQueryInputMaskTwigExtension::SERVICE_NAME)); |
209
|
|
|
$this->assertInstanceOf(MaterialDesignColorPaletteTwigExtension::class, $this->containerBuilder->get(MaterialDesignColorPaletteTwigExtension::SERVICE_NAME)); |
210
|
|
|
$this->assertInstanceOf(MaterialDesignIconicFontTwigExtension::class, $this->containerBuilder->get(MaterialDesignIconicFontTwigExtension::SERVICE_NAME)); |
211
|
|
|
$this->assertInstanceOf(MeteoconsTwigExtension::class, $this->containerBuilder->get(MeteoconsTwigExtension::SERVICE_NAME)); |
212
|
|
|
$this->assertInstanceOf(SyntaxHighlighterTwigExtension::class, $this->containerBuilder->get(SyntaxHighlighterTwigExtension::SERVICE_NAME)); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Tests the load() method. |
217
|
|
|
* |
218
|
|
|
* @return void |
219
|
|
|
* @throws Exception Throws an exception if an error occurs. |
220
|
|
|
*/ |
221
|
|
|
public function testLoadWithSecurityEventListener(): void { |
222
|
|
|
|
223
|
|
|
// Set the configs mock. |
224
|
|
|
$this->configs["wbw_core"]["security_event_listener"] = true; |
225
|
|
|
|
226
|
|
|
$obj = new WBWCoreExtension(); |
227
|
|
|
|
228
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
229
|
|
|
|
230
|
|
|
$this->assertInstanceOf(SecurityEventListener::class, $this->containerBuilder->get(SecurityEventListener::SERVICE_NAME)); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Tests the load() method. |
235
|
|
|
* |
236
|
|
|
* @return void |
237
|
|
|
* @throws Exception Throws an exception if an error occurs. |
238
|
|
|
*/ |
239
|
|
|
public function testLoadWithWorldsWisdomQuoteProvider(): void { |
240
|
|
|
|
241
|
|
|
// Set the configs mock. |
242
|
|
|
$this->configs["wbw_core"]["quote_providers"]["worlds_wisdom"] = true; |
243
|
|
|
|
244
|
|
|
$obj = new WBWCoreExtension(); |
245
|
|
|
|
246
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
247
|
|
|
|
248
|
|
|
$this->assertInstanceOf(YamlQuoteProvider::class, $this->containerBuilder->get(self::WORLDS_WISDOM_QUOTE_PROVIDER_SERVICE_NAME)); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Tests the load() method. |
253
|
|
|
* |
254
|
|
|
* @return void |
255
|
|
|
*/ |
256
|
|
|
public function testLoadWithoutCommands(): void { |
257
|
|
|
|
258
|
|
|
// Set the configs mock. |
259
|
|
|
$this->configs["wbw_core"]["commands"] = false; |
260
|
|
|
|
261
|
|
|
$obj = new WBWCoreExtension(); |
262
|
|
|
|
263
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
264
|
|
|
|
265
|
|
|
try { |
266
|
|
|
|
267
|
|
|
$this->containerBuilder->get(UnzipAssetsCommand::SERVICE_NAME); |
268
|
|
|
} catch (Exception $ex) { |
269
|
|
|
|
270
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
271
|
|
|
$this->assertStringContainsString(UnzipAssetsCommand::SERVICE_NAME, $ex->getMessage()); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Tests the load() method. |
277
|
|
|
* |
278
|
|
|
* @return void |
279
|
|
|
*/ |
280
|
|
|
public function testLoadWithoutEventListeners(): void { |
281
|
|
|
|
282
|
|
|
// Set the configs mock. |
283
|
|
|
$this->configs["wbw_core"]["event_listeners"] = false; |
284
|
|
|
|
285
|
|
|
$obj = new WBWCoreExtension(); |
286
|
|
|
|
287
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
288
|
|
|
|
289
|
|
|
try { |
290
|
|
|
|
291
|
|
|
$this->containerBuilder->get(KernelEventListener::SERVICE_NAME); |
292
|
|
|
} catch (Exception $ex) { |
293
|
|
|
|
294
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
295
|
|
|
$this->assertStringContainsString(KernelEventListener::SERVICE_NAME, $ex->getMessage()); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Tests the load() method. |
301
|
|
|
* |
302
|
|
|
* @return void |
303
|
|
|
*/ |
304
|
|
|
public function testLoadWithoutProviders(): void { |
305
|
|
|
|
306
|
|
|
// Set the configs mock. |
307
|
|
|
$this->configs["wbw_core"]["providers"] = false; |
308
|
|
|
|
309
|
|
|
$obj = new WBWCoreExtension(); |
310
|
|
|
|
311
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
312
|
|
|
|
313
|
|
|
try { |
314
|
|
|
|
315
|
|
|
$this->containerBuilder->get(RedColorProvider::SERVICE_NAME); |
316
|
|
|
} catch (Exception $ex) { |
317
|
|
|
|
318
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
319
|
|
|
$this->assertStringContainsString(RedColorProvider::SERVICE_NAME, $ex->getMessage()); |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Tests the load() method. |
325
|
|
|
* |
326
|
|
|
* @return void |
327
|
|
|
*/ |
328
|
|
|
public function testLoadWithoutTwig(): void { |
329
|
|
|
|
330
|
|
|
// Set the configs mock. |
331
|
|
|
$this->configs["wbw_core"]["twig"] = false; |
332
|
|
|
|
333
|
|
|
$obj = new WBWCoreExtension(); |
334
|
|
|
|
335
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
336
|
|
|
|
337
|
|
|
try { |
338
|
|
|
|
339
|
|
|
$this->containerBuilder->get(QuoteTwigExtension::SERVICE_NAME); |
340
|
|
|
} catch (Exception $ex) { |
341
|
|
|
|
342
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
343
|
|
|
$this->assertStringContainsString(QuoteTwigExtension::SERVICE_NAME, $ex->getMessage()); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|