|
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\Manager; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use WBW\Bundle\CoreBundle\Manager\ThemeManager; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\ApplicationThemeProviderInterface; |
|
17
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\BreadcrumbsThemeProviderInterface; |
|
18
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\FooterThemeProviderInterface; |
|
19
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\HookDropDownThemeProviderInterface; |
|
20
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\NavigationThemeProviderInterface; |
|
21
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\NotificationsDropDownThemeProviderInterface; |
|
22
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\SearchThemeProviderInterface; |
|
23
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\TasksDropDownThemeProviderInterface; |
|
24
|
|
|
use WBW\Bundle\CoreBundle\Provider\Theme\UserInfoThemeProviderInterface; |
|
25
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Theme manager test. |
|
29
|
|
|
* |
|
30
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
31
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Manager |
|
32
|
|
|
*/ |
|
33
|
|
|
class ThemeManagerTest extends AbstractTestCase { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Tests the addGlobal() method. |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testAddGlobal(): void { |
|
42
|
|
|
|
|
43
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
44
|
|
|
|
|
45
|
|
|
// Set the Theme provider mocks. |
|
46
|
|
|
$obj->setApplicationThemeProvider($this->getMockBuilder(ApplicationThemeProviderInterface::class)->getMock()); |
|
47
|
|
|
$obj->setBreadcrumbsThemeProvider($this->getMockBuilder(BreadcrumbsThemeProviderInterface::class)->getMock()); |
|
48
|
|
|
$obj->setHookDropDownThemeProvider($this->getMockBuilder(HookDropDownThemeProviderInterface::class)->getMock()); |
|
49
|
|
|
$obj->setFooterThemeProvider($this->getMockBuilder(FooterThemeProviderInterface::class)->getMock()); |
|
50
|
|
|
$obj->setNavigationThemeProvider($this->getMockBuilder(NavigationThemeProviderInterface::class)->getMock()); |
|
51
|
|
|
$obj->setNotificationsDropDownThemeProvider($this->getMockBuilder(NotificationsDropDownThemeProviderInterface::class)->getMock()); |
|
52
|
|
|
$obj->setSearchThemeProvider($this->getMockBuilder(SearchThemeProviderInterface::class)->getMock()); |
|
53
|
|
|
$obj->setTasksDropDownThemeProvider($this->getMockBuilder(TasksDropDownThemeProviderInterface::class)->getMock()); |
|
54
|
|
|
$obj->setUserInfoThemeProvider($this->getMockBuilder(UserInfoThemeProviderInterface::class)->getMock()); |
|
55
|
|
|
|
|
56
|
|
|
$obj->addGlobal(); |
|
57
|
|
|
|
|
58
|
|
|
$res = $this->twigEnvironment->getGlobals(); |
|
59
|
|
|
$this->assertCount(9, $res); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertArrayHasKey("ApplicationThemeProvider", $res); |
|
62
|
|
|
$this->assertInstanceOf(ApplicationThemeProviderInterface::class, $res["ApplicationThemeProvider"]); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertArrayHasKey("BreadcrumbsThemeProvider", $res); |
|
65
|
|
|
$this->assertInstanceOf(BreadcrumbsThemeProviderInterface::class, $res["BreadcrumbsThemeProvider"]); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertArrayHasKey("FooterThemeProvider", $res); |
|
68
|
|
|
$this->assertInstanceOf(FooterThemeProviderInterface::class, $res["FooterThemeProvider"]); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertArrayHasKey("HookDropDownThemeProvider", $res); |
|
71
|
|
|
$this->assertInstanceOf(HookDropDownThemeProviderInterface::class, $res["HookDropDownThemeProvider"]); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertArrayHasKey("NavigationThemeProvider", $res); |
|
74
|
|
|
$this->assertInstanceOf(NavigationThemeProviderInterface::class, $res["NavigationThemeProvider"]); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertArrayHasKey("NotificationsDropDownThemeProvider", $res); |
|
77
|
|
|
$this->assertInstanceOf(NotificationsDropDownThemeProviderInterface::class, $res["NotificationsDropDownThemeProvider"]); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertArrayHasKey("TasksDropDownThemeProvider", $res); |
|
80
|
|
|
$this->assertInstanceOf(TasksDropDownThemeProviderInterface::class, $res["TasksDropDownThemeProvider"]); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertArrayHasKey("SearchThemeProvider", $res); |
|
83
|
|
|
$this->assertInstanceOf(SearchThemeProviderInterface::class, $res["SearchThemeProvider"]); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertArrayHasKey("UserInfoThemeProvider", $res); |
|
86
|
|
|
$this->assertInstanceOf(UserInfoThemeProviderInterface::class, $res["UserInfoThemeProvider"]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Tests the hasProviders() method. |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
94
|
|
|
*/ |
|
95
|
|
|
public function testHasProviders(): void { |
|
96
|
|
|
|
|
97
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertFalse($obj->hasProviders()); |
|
100
|
|
|
|
|
101
|
|
|
$obj->setApplicationThemeProvider($this->getMockBuilder(ApplicationThemeProviderInterface::class)->getMock()); |
|
102
|
|
|
$this->assertTrue($obj->hasProviders()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Tests the setApplicationThemeProvider() method. |
|
107
|
|
|
* |
|
108
|
|
|
* @return void |
|
109
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
110
|
|
|
*/ |
|
111
|
|
|
public function testSetApplicationThemeProvider(): void { |
|
112
|
|
|
|
|
113
|
|
|
// Set a Application theme provider mock. |
|
114
|
|
|
$provider = $this->getMockBuilder(ApplicationThemeProviderInterface::class)->getMock(); |
|
115
|
|
|
|
|
116
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
117
|
|
|
|
|
118
|
|
|
$obj->setApplicationThemeProvider($this->getMockBuilder(ApplicationThemeProviderInterface::class)->getMock()); |
|
119
|
|
|
$this->assertNotSame($provider, $obj->getApplicationThemeProvider()); |
|
120
|
|
|
|
|
121
|
|
|
$obj->setApplicationThemeProvider($provider); |
|
122
|
|
|
$this->assertSame($provider, $obj->getApplicationThemeProvider()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Tests the setBreadcrumbsThemeProvider() method. |
|
127
|
|
|
* |
|
128
|
|
|
* @return void |
|
129
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
130
|
|
|
*/ |
|
131
|
|
|
public function testSetBreadcrumbsThemeProvider(): void { |
|
132
|
|
|
|
|
133
|
|
|
// Set a Breadcrumbs theme provider mock. |
|
134
|
|
|
$provider = $this->getMockBuilder(BreadcrumbsThemeProviderInterface::class)->getMock(); |
|
135
|
|
|
|
|
136
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
137
|
|
|
|
|
138
|
|
|
$obj->setBreadcrumbsThemeProvider($provider); |
|
139
|
|
|
$this->assertSame($provider, $obj->getBreadcrumbsThemeProvider()); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Tests the setFooterThemeProvider() method. |
|
144
|
|
|
* |
|
145
|
|
|
* @return void |
|
146
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
147
|
|
|
*/ |
|
148
|
|
|
public function testSetFooterThemeProvider(): void { |
|
149
|
|
|
|
|
150
|
|
|
// Set a Footer theme provider mock. |
|
151
|
|
|
$provider = $this->getMockBuilder(FooterThemeProviderInterface::class)->getMock(); |
|
152
|
|
|
|
|
153
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
154
|
|
|
|
|
155
|
|
|
$obj->setFooterThemeProvider($provider); |
|
156
|
|
|
$this->assertSame($provider, $obj->getFooterThemeProvider()); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Tests the setHookDropDownThemeProvider() method. |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function testSetHookDropDownThemeProvider(): void { |
|
166
|
|
|
|
|
167
|
|
|
// Set a Hook drop down theme provider mock. |
|
168
|
|
|
$provider = $this->getMockBuilder(HookDropDownThemeProviderInterface::class)->getMock(); |
|
169
|
|
|
|
|
170
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
171
|
|
|
|
|
172
|
|
|
$obj->setHookDropDownThemeProvider($provider); |
|
173
|
|
|
$this->assertSame($provider, $obj->getHookDropDownThemeProvider()); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Tests the setNavigationThemeProvider() method. |
|
178
|
|
|
* |
|
179
|
|
|
* @return void |
|
180
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
181
|
|
|
*/ |
|
182
|
|
|
public function testSetNavigationThemeProvider(): void { |
|
183
|
|
|
|
|
184
|
|
|
// Set a Navigation theme provider mock. |
|
185
|
|
|
$provider = $this->getMockBuilder(NavigationThemeProviderInterface::class)->getMock(); |
|
186
|
|
|
|
|
187
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
188
|
|
|
|
|
189
|
|
|
$obj->setNavigationThemeProvider($provider); |
|
190
|
|
|
$this->assertSame($provider, $obj->getNavigationThemeProvider()); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Tests the setNotificationsDropDownThemeProvider() method. |
|
195
|
|
|
* |
|
196
|
|
|
* @return void |
|
197
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
198
|
|
|
*/ |
|
199
|
|
|
public function testSetNotificationsDropDownThemeProvider(): void { |
|
200
|
|
|
|
|
201
|
|
|
// Set a Notifications drop down theme provider mock. |
|
202
|
|
|
$provider = $this->getMockBuilder(NotificationsDropDownThemeProviderInterface::class)->getMock(); |
|
203
|
|
|
|
|
204
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
205
|
|
|
|
|
206
|
|
|
$obj->setNotificationsDropDownThemeProvider($provider); |
|
207
|
|
|
$this->assertSame($provider, $obj->getNotificationsDropDownThemeProvider()); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Tests the setSearchThemeProvider() method. |
|
212
|
|
|
* |
|
213
|
|
|
* @return void |
|
214
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
215
|
|
|
*/ |
|
216
|
|
|
public function testSetSearchThemeProvider(): void { |
|
217
|
|
|
|
|
218
|
|
|
// Set a Search theme provider mock. |
|
219
|
|
|
$provider = $this->getMockBuilder(SearchThemeProviderInterface::class)->getMock(); |
|
220
|
|
|
|
|
221
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
222
|
|
|
|
|
223
|
|
|
$obj->setSearchThemeProvider($provider); |
|
224
|
|
|
$this->assertSame($provider, $obj->getSearchThemeProvider()); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Tests the setTasksDropDownThemeProvider() method. |
|
229
|
|
|
* |
|
230
|
|
|
* @return void |
|
231
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
232
|
|
|
*/ |
|
233
|
|
|
public function testSetTasksDropDownThemeProvider(): void { |
|
234
|
|
|
|
|
235
|
|
|
// Set a Tasks drop down theme provider mock. |
|
236
|
|
|
$provider = $this->getMockBuilder(TasksDropDownThemeProviderInterface::class)->getMock(); |
|
237
|
|
|
|
|
238
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
239
|
|
|
|
|
240
|
|
|
$obj->setTasksDropDownThemeProvider($provider); |
|
241
|
|
|
$this->assertSame($provider, $obj->getTasksDropDownThemeProvider()); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Tests the setUserInfoThemeProvider() method. |
|
246
|
|
|
* |
|
247
|
|
|
* @return void |
|
248
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
249
|
|
|
*/ |
|
250
|
|
|
public function testSetUserInfoThemeProvider(): void { |
|
251
|
|
|
|
|
252
|
|
|
// Set the mocks. |
|
253
|
|
|
$provider = $this->getMockBuilder(UserInfoThemeProviderInterface::class)->getMock(); |
|
254
|
|
|
|
|
255
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
256
|
|
|
|
|
257
|
|
|
$obj->setUserInfoThemeProvider($provider); |
|
258
|
|
|
$this->assertSame($provider, $obj->getUserInfoThemeProvider()); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Tests the __construct() method. |
|
263
|
|
|
* |
|
264
|
|
|
* @return void |
|
265
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
266
|
|
|
*/ |
|
267
|
|
|
public function test__construct(): void { |
|
268
|
|
|
|
|
269
|
|
|
$this->assertEquals("wbw.core.manager.theme", ThemeManager::SERVICE_NAME); |
|
270
|
|
|
|
|
271
|
|
|
$obj = new ThemeManager($this->logger, $this->twigEnvironment); |
|
272
|
|
|
|
|
273
|
|
|
$this->assertNull($obj->getApplicationThemeProvider()); |
|
274
|
|
|
$this->assertNull($obj->getBreadcrumbsThemeProvider()); |
|
275
|
|
|
$this->assertNull($obj->getFooterThemeProvider()); |
|
276
|
|
|
$this->assertNull($obj->getHookDropDownThemeProvider()); |
|
277
|
|
|
$this->assertNull($obj->getNavigationThemeProvider()); |
|
278
|
|
|
$this->assertNull($obj->getNotificationsDropDownThemeProvider()); |
|
279
|
|
|
$this->assertNull($obj->getSearchThemeProvider()); |
|
280
|
|
|
$this->assertNull($obj->getTasksDropDownThemeProvider()); |
|
281
|
|
|
$this->assertNull($obj->getUserInfoThemeProvider()); |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|