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 Doctrine\Persistence\Mapping\ClassMetadata; |
15
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
16
|
|
|
use Throwable; |
17
|
|
|
use WBW\Bundle\CoreBundle\Command\CopySkeletonCommand; |
18
|
|
|
use WBW\Bundle\CoreBundle\Command\UnzipAssetsCommand; |
19
|
|
|
use WBW\Bundle\CoreBundle\Controller\HostController; |
20
|
|
|
use WBW\Bundle\CoreBundle\Controller\TwigController; |
21
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\Configuration; |
22
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\WBWCoreExtension; |
23
|
|
|
use WBW\Bundle\CoreBundle\EventListener\KernelEventListener; |
24
|
|
|
use WBW\Bundle\CoreBundle\EventListener\NotificationEventListener; |
25
|
|
|
use WBW\Bundle\CoreBundle\EventListener\SecurityEventListener; |
26
|
|
|
use WBW\Bundle\CoreBundle\EventListener\ToastEventListener; |
27
|
|
|
use WBW\Bundle\CoreBundle\Helper\FormHelper; |
28
|
|
|
use WBW\Bundle\CoreBundle\Manager\ThemeManager; |
29
|
|
|
use WBW\Bundle\CoreBundle\Provider\JavascriptProvider; |
30
|
|
|
use WBW\Bundle\CoreBundle\Provider\SyntaxHighlighterProvider; |
31
|
|
|
use WBW\Bundle\CoreBundle\Service\CompatibilityService; |
32
|
|
|
use WBW\Bundle\CoreBundle\Service\RepositoryService; |
33
|
|
|
use WBW\Bundle\CoreBundle\Service\StatementService; |
34
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
35
|
|
|
use WBW\Bundle\CoreBundle\Tests\Fixtures\Model\TestUser; |
36
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\FontAwesomeTwigExtension; |
37
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\JQueryInputMaskTwigExtension; |
38
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\MaterialDesignColorPaletteTwigExtension; |
39
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\MaterialDesignIconicFontTwigExtension; |
40
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\MeteoconsTwigExtension; |
41
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\SyntaxHighlighterTwigExtension; |
42
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\AssetsTwigExtension; |
43
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\ContainerTwigExtension; |
44
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\QuoteTwigExtension; |
45
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\StringTwigExtension; |
46
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\AmberColorProvider; |
47
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\BlueColorProvider; |
48
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\BlueGreyColorProvider; |
49
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\BrownColorProvider; |
50
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\CyanColorProvider; |
51
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\DeepOrangeColorProvider; |
52
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\DeepPurpleColorProvider; |
53
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\GreenColorProvider; |
54
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\GreyColorProvider; |
55
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\IndigoColorProvider; |
56
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\LightBlueColorProvider; |
57
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\LightGreenColorProvider; |
58
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\LimeColorProvider; |
59
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\OrangeColorProvider; |
60
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\PinkColorProvider; |
61
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\PurpleColorProvider; |
62
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\RedColorProvider; |
63
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\TealColorProvider; |
64
|
|
|
use WBW\Library\Symfony\Color\MaterialDesignColorPalette\YellowColorProvider; |
65
|
|
|
use WBW\Library\Symfony\Manager\ColorManager; |
66
|
|
|
use WBW\Library\Symfony\Manager\JavascriptManager; |
67
|
|
|
use WBW\Library\Symfony\Manager\QuoteManager; |
68
|
|
|
use WBW\Library\Symfony\Manager\StylesheetManager; |
69
|
|
|
use WBW\Library\Symfony\Provider\Quote\WorldsWisdomQuoteProvider; |
70
|
|
|
use WBW\Library\Symfony\Provider\Quote\YamlQuoteProvider; |
71
|
|
|
use WBW\Library\Symfony\Service\TokenGeneratorService; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Core extension test. |
75
|
|
|
* |
76
|
|
|
* @author webeweb <https://github.com/webeweb> |
77
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\DependencyInjection |
78
|
|
|
*/ |
79
|
|
|
class WBWCoreExtensionTest extends AbstractTestCase { |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Configs. |
83
|
|
|
* |
84
|
|
|
* @var array |
85
|
|
|
*/ |
86
|
|
|
private $configs; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
protected function setUp(): void { |
92
|
|
|
parent::setUp(); |
93
|
|
|
|
94
|
|
|
// Set a configs array mock. |
95
|
|
|
$this->configs = [ |
96
|
|
|
WBWCoreExtension::EXTENSION_ALIAS => [ |
97
|
|
|
"quote" => [], |
98
|
|
|
], |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
// Set a Class metadata mock. |
102
|
|
|
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->getMock(); |
103
|
|
|
$classMetadata->expects($this->any())->method("getName")->willReturn(TestUser::class); |
104
|
|
|
|
105
|
|
|
// Set the Entity manager mock. |
106
|
|
|
$this->entityManager->expects($this->any())->method("getClassMetadata")->willReturn($classMetadata); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Tests getAlias() |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function testGetAlias(): void { |
115
|
|
|
|
116
|
|
|
$obj = new WBWCoreExtension(); |
117
|
|
|
|
118
|
|
|
$this->assertEquals("wbw_core", $obj->getAlias()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Tests getConfiguration() |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function testGetConfiguration(): void { |
127
|
|
|
|
128
|
|
|
$obj = new WBWCoreExtension(); |
129
|
|
|
|
130
|
|
|
$this->assertInstanceOf(Configuration::class, $obj->getConfiguration([], $this->containerBuilder)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Tests load() |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
138
|
|
|
*/ |
139
|
|
|
public function testLoad(): void { |
140
|
|
|
|
141
|
|
|
$obj = new WBWCoreExtension(); |
142
|
|
|
|
143
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
|
|
|
|
144
|
|
|
|
145
|
|
|
// Commands |
146
|
|
|
$this->assertInstanceOf(CopySkeletonCommand::class, $this->containerBuilder->get(CopySkeletonCommand::SERVICE_NAME)); |
147
|
|
|
$this->assertInstanceOf(UnzipAssetsCommand::class, $this->containerBuilder->get(UnzipAssetsCommand::SERVICE_NAME)); |
148
|
|
|
|
149
|
|
|
// Controllers |
150
|
|
|
$this->assertInstanceOf(HostController::class, $this->containerBuilder->get(HostController::SERVICE_NAME)); |
151
|
|
|
$this->assertInstanceOf(TwigController::class, $this->containerBuilder->get(TwigController::SERVICE_NAME)); |
152
|
|
|
|
153
|
|
|
// Event listeners |
154
|
|
|
$this->assertInstanceOf(KernelEventListener::class, $this->containerBuilder->get(KernelEventListener::SERVICE_NAME)); |
155
|
|
|
$this->assertInstanceOf(NotificationEventListener::class, $this->containerBuilder->get(NotificationEventListener::SERVICE_NAME)); |
156
|
|
|
$this->assertInstanceOf(ToastEventListener::class, $this->containerBuilder->get(ToastEventListener::SERVICE_NAME)); |
157
|
|
|
|
158
|
|
|
try { |
159
|
|
|
|
160
|
|
|
$this->containerBuilder->get(SecurityEventListener::SERVICE_NAME); |
161
|
|
|
} catch (Throwable $ex) { |
162
|
|
|
|
163
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
164
|
|
|
$this->assertStringContainsString(SecurityEventListener::SERVICE_NAME, $ex->getMessage()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// Helpers |
168
|
|
|
$this->assertInstanceOf(FormHelper::class, $this->containerBuilder->get(FormHelper::SERVICE_NAME)); |
169
|
|
|
|
170
|
|
|
// Managers |
171
|
|
|
$this->assertInstanceOf(ColorManager::class, $this->containerBuilder->get(ColorManager::SERVICE_NAME)); |
172
|
|
|
$this->assertInstanceOf(JavascriptManager::class, $this->containerBuilder->get(JavascriptManager::SERVICE_NAME)); |
173
|
|
|
$this->assertInstanceOf(QuoteManager::class, $this->containerBuilder->get(QuoteManager::SERVICE_NAME)); |
174
|
|
|
$this->assertInstanceOf(StylesheetManager::class, $this->containerBuilder->get(StylesheetManager::SERVICE_NAME)); |
175
|
|
|
$this->assertInstanceOf(ThemeManager::class, $this->containerBuilder->get(ThemeManager::SERVICE_NAME)); |
176
|
|
|
|
177
|
|
|
// Providers |
178
|
|
|
$this->assertInstanceOf(AmberColorProvider::class, $this->containerBuilder->get(AmberColorProvider::SERVICE_NAME)); |
179
|
|
|
$this->assertInstanceOf(BlueColorProvider::class, $this->containerBuilder->get(BlueColorProvider::SERVICE_NAME)); |
180
|
|
|
$this->assertInstanceOf(BlueGreyColorProvider::class, $this->containerBuilder->get(BlueGreyColorProvider::SERVICE_NAME)); |
181
|
|
|
$this->assertInstanceOf(BrownColorProvider::class, $this->containerBuilder->get(BrownColorProvider::SERVICE_NAME)); |
182
|
|
|
$this->assertInstanceOf(CyanColorProvider::class, $this->containerBuilder->get(CyanColorProvider::SERVICE_NAME)); |
183
|
|
|
$this->assertInstanceOf(DeepOrangeColorProvider::class, $this->containerBuilder->get(DeepOrangeColorProvider::SERVICE_NAME)); |
184
|
|
|
$this->assertInstanceOf(DeepPurpleColorProvider::class, $this->containerBuilder->get(DeepPurpleColorProvider::SERVICE_NAME)); |
185
|
|
|
$this->assertInstanceOf(GreenColorProvider::class, $this->containerBuilder->get(GreenColorProvider::SERVICE_NAME)); |
186
|
|
|
$this->assertInstanceOf(GreyColorProvider::class, $this->containerBuilder->get(GreyColorProvider::SERVICE_NAME)); |
187
|
|
|
$this->assertInstanceOf(IndigoColorProvider::class, $this->containerBuilder->get(IndigoColorProvider::SERVICE_NAME)); |
188
|
|
|
$this->assertInstanceOf(LightBlueColorProvider::class, $this->containerBuilder->get(LightBlueColorProvider::SERVICE_NAME)); |
189
|
|
|
$this->assertInstanceOf(LightGreenColorProvider::class, $this->containerBuilder->get(LightGreenColorProvider::SERVICE_NAME)); |
190
|
|
|
$this->assertInstanceOf(LimeColorProvider::class, $this->containerBuilder->get(LimeColorProvider::SERVICE_NAME)); |
191
|
|
|
$this->assertInstanceOf(OrangeColorProvider::class, $this->containerBuilder->get(OrangeColorProvider::SERVICE_NAME)); |
192
|
|
|
$this->assertInstanceOf(PinkColorProvider::class, $this->containerBuilder->get(PinkColorProvider::SERVICE_NAME)); |
193
|
|
|
$this->assertInstanceOf(PurpleColorProvider::class, $this->containerBuilder->get(PurpleColorProvider::SERVICE_NAME)); |
194
|
|
|
$this->assertInstanceOf(RedColorProvider::class, $this->containerBuilder->get(RedColorProvider::SERVICE_NAME)); |
195
|
|
|
$this->assertInstanceOf(TealColorProvider::class, $this->containerBuilder->get(TealColorProvider::SERVICE_NAME)); |
196
|
|
|
$this->assertInstanceOf(YellowColorProvider::class, $this->containerBuilder->get(YellowColorProvider::SERVICE_NAME)); |
197
|
|
|
|
198
|
|
|
$this->assertInstanceOf(JavascriptProvider::class, $this->containerBuilder->get(JavascriptProvider::SERVICE_NAME)); |
199
|
|
|
$this->assertInstanceOf(SyntaxHighlighterProvider::class, $this->containerBuilder->get(SyntaxHighlighterProvider::SERVICE_NAME)); |
200
|
|
|
|
201
|
|
|
try { |
202
|
|
|
|
203
|
|
|
$this->containerBuilder->get(WorldsWisdomQuoteProvider::SERVICE_NAME); |
204
|
|
|
} catch (Throwable $ex) { |
205
|
|
|
|
206
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
207
|
|
|
$this->assertStringContainsString(WorldsWisdomQuoteProvider::SERVICE_NAME, $ex->getMessage()); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
// Services |
211
|
|
|
$this->assertInstanceOf(CompatibilityService::class, $this->containerBuilder->get(CompatibilityService::SERVICE_NAME)); |
212
|
|
|
$this->assertInstanceOf(RepositoryService::class, $this->containerBuilder->get(RepositoryService::SERVICE_NAME)); |
213
|
|
|
$this->assertInstanceOf(StatementService::class, $this->containerBuilder->get(StatementService::SERVICE_NAME)); |
214
|
|
|
$this->assertInstanceOf(TokenGeneratorService::class, $this->containerBuilder->get(TokenGeneratorService::SERVICE_NAME)); |
215
|
|
|
|
216
|
|
|
// Twig extensions |
217
|
|
|
$this->assertInstanceOf(AssetsTwigExtension::class, $this->containerBuilder->get(AssetsTwigExtension::SERVICE_NAME)); |
218
|
|
|
$this->assertInstanceOf(ContainerTwigExtension::class, $this->containerBuilder->get(ContainerTwigExtension::SERVICE_NAME)); |
219
|
|
|
$this->assertInstanceOf(QuoteTwigExtension::class, $this->containerBuilder->get(QuoteTwigExtension::SERVICE_NAME)); |
220
|
|
|
$this->assertInstanceOf(StringTwigExtension::class, $this->containerBuilder->get(StringTwigExtension::SERVICE_NAME)); |
221
|
|
|
|
222
|
|
|
// Assets Twig extensions |
223
|
|
|
$this->assertInstanceOf(FontAwesomeTwigExtension::class, $this->containerBuilder->get(FontAwesomeTwigExtension::SERVICE_NAME)); |
224
|
|
|
$this->assertInstanceOf(JQueryInputMaskTwigExtension::class, $this->containerBuilder->get(JQueryInputMaskTwigExtension::SERVICE_NAME)); |
225
|
|
|
$this->assertInstanceOf(MaterialDesignColorPaletteTwigExtension::class, $this->containerBuilder->get(MaterialDesignColorPaletteTwigExtension::SERVICE_NAME)); |
226
|
|
|
$this->assertInstanceOf(MaterialDesignIconicFontTwigExtension::class, $this->containerBuilder->get(MaterialDesignIconicFontTwigExtension::SERVICE_NAME)); |
227
|
|
|
$this->assertInstanceOf(MeteoconsTwigExtension::class, $this->containerBuilder->get(MeteoconsTwigExtension::SERVICE_NAME)); |
228
|
|
|
$this->assertInstanceOf(SyntaxHighlighterTwigExtension::class, $this->containerBuilder->get(SyntaxHighlighterTwigExtension::SERVICE_NAME)); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Tests load() |
233
|
|
|
* |
234
|
|
|
* @return void |
235
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
236
|
|
|
*/ |
237
|
|
|
public function testLoadWithSecurity(): void { |
238
|
|
|
|
239
|
|
|
// Set the configs mock. |
240
|
|
|
$this->configs[WBWCoreExtension::EXTENSION_ALIAS]["security"] = true; |
241
|
|
|
|
242
|
|
|
$obj = new WBWCoreExtension(); |
243
|
|
|
|
244
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
|
|
|
|
245
|
|
|
|
246
|
|
|
$this->assertInstanceOf(SecurityEventListener::class, $this->containerBuilder->get(SecurityEventListener::SERVICE_NAME)); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Tests load() |
251
|
|
|
* |
252
|
|
|
* @return void |
253
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
254
|
|
|
*/ |
255
|
|
|
public function testLoadWithWorldsWisdomQuote(): void { |
256
|
|
|
|
257
|
|
|
// Set the configs mock. |
258
|
|
|
$this->configs[WBWCoreExtension::EXTENSION_ALIAS]["quote"]["worlds_wisdom"] = true; |
259
|
|
|
|
260
|
|
|
$obj = new WBWCoreExtension(); |
261
|
|
|
|
262
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
|
|
|
|
263
|
|
|
|
264
|
|
|
$this->assertInstanceOf(YamlQuoteProvider::class, $this->containerBuilder->get(WorldsWisdomQuoteProvider::SERVICE_NAME)); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.