|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests\Menu; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Yiisoft\Definitions\Exception\CircularReferenceException; |
|
9
|
|
|
use Yiisoft\Definitions\Exception\InvalidConfigException; |
|
10
|
|
|
use Yiisoft\Definitions\Exception\NotInstantiableException; |
|
11
|
|
|
use Yiisoft\Factory\NotFoundException; |
|
12
|
|
|
use Yiisoft\Yii\Widgets\Menu; |
|
13
|
|
|
use Yiisoft\Yii\Widgets\Tests\Support\Assert; |
|
14
|
|
|
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
|
18
|
|
|
*/ |
|
19
|
|
|
final class MenuTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
use TestTrait; |
|
22
|
|
|
|
|
23
|
|
|
private array $items = [ |
|
24
|
|
|
['label' => 'item', 'link' => '/path'], |
|
25
|
|
|
]; |
|
26
|
|
|
private array $itemsWithOptions = [ |
|
27
|
|
|
['label' => 'Active', 'link' => '/active'], |
|
28
|
|
|
['label' => 'Much longer nav link', 'link' => '#'], |
|
29
|
|
|
['label' => 'Link', 'link' => '#'], |
|
30
|
|
|
['label' => 'Disabled', 'link' => '#', 'disabled' => true], |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @throws CircularReferenceException |
|
35
|
|
|
* @throws InvalidConfigException |
|
36
|
|
|
* @throws NotFoundException |
|
37
|
|
|
* @throws NotInstantiableException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testAttributes(): void |
|
40
|
|
|
{ |
|
41
|
|
|
Assert::equalsWithoutLE( |
|
42
|
|
|
<<<HTML |
|
43
|
|
|
<ul class="test-class"> |
|
44
|
|
|
<li><a href="/path">item</a></li> |
|
45
|
|
|
</ul> |
|
46
|
|
|
HTML, |
|
47
|
|
|
Menu::widget()->attributes(['class' => 'test-class'])->items($this->items)->render(), |
|
|
|
|
|
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @throws CircularReferenceException |
|
53
|
|
|
* @throws InvalidConfigException |
|
54
|
|
|
* @throws NotFoundException |
|
55
|
|
|
* @throws NotInstantiableException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testActiveItemsWithFalse(): void |
|
58
|
|
|
{ |
|
59
|
|
|
Assert::equalsWithoutLE( |
|
60
|
|
|
<<<HTML |
|
61
|
|
|
<ul> |
|
62
|
|
|
<li><a href="/path">item</a></li> |
|
63
|
|
|
</ul> |
|
64
|
|
|
HTML, |
|
65
|
|
|
Menu::widget()->activateItems(false)->currentPath('/path')->items($this->items)->render(), |
|
|
|
|
|
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @throws CircularReferenceException |
|
71
|
|
|
* @throws InvalidConfigException |
|
72
|
|
|
* @throws NotFoundException |
|
73
|
|
|
* @throws NotInstantiableException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testAfter(): void |
|
76
|
|
|
{ |
|
77
|
|
|
Assert::equalsWithoutLE( |
|
78
|
|
|
<<<HTML |
|
79
|
|
|
<ul> |
|
80
|
|
|
<li><a class="active" href="/path" aria-current="page">item</a></li> |
|
81
|
|
|
</ul> |
|
82
|
|
|
<a class="navbar-brand">Hidden brand</a> |
|
83
|
|
|
HTML, |
|
84
|
|
|
Menu::widget() |
|
85
|
|
|
->afterClass('navbar-brand') |
|
|
|
|
|
|
86
|
|
|
->afterContent('Hidden brand') |
|
87
|
|
|
->afterTag('a') |
|
88
|
|
|
->currentPath('/path') |
|
89
|
|
|
->items($this->items) |
|
90
|
|
|
->render(), |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
Assert::equalsWithoutLE( |
|
94
|
|
|
<<<HTML |
|
95
|
|
|
<ul> |
|
96
|
|
|
<li><a class="active" href="/path" aria-current="page">item</a></li> |
|
97
|
|
|
</ul> |
|
98
|
|
|
<span class="d-flex" role="search"><input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> |
|
99
|
|
|
<button class="btn btn-outline-success" type="submit">Search</button></span> |
|
100
|
|
|
HTML, |
|
101
|
|
|
Menu::widget() |
|
102
|
|
|
->afterAttributes(['role' => 'search']) |
|
|
|
|
|
|
103
|
|
|
->afterClass('d-flex') |
|
104
|
|
|
->afterContent( |
|
105
|
|
|
<<<HTML |
|
106
|
|
|
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> |
|
107
|
|
|
<button class="btn btn-outline-success" type="submit">Search</button> |
|
108
|
|
|
HTML, |
|
109
|
|
|
) |
|
110
|
|
|
->currentPath('/path') |
|
111
|
|
|
->items($this->items) |
|
112
|
|
|
->render(), |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @throws CircularReferenceException |
|
118
|
|
|
* @throws InvalidConfigException |
|
119
|
|
|
* @throws NotFoundException |
|
120
|
|
|
* @throws NotInstantiableException |
|
121
|
|
|
*/ |
|
122
|
|
|
public function testActiveWithNotBool(): void |
|
123
|
|
|
{ |
|
124
|
|
|
Assert::equalsWithoutLE( |
|
125
|
|
|
<<<HTML |
|
126
|
|
|
<ul> |
|
127
|
|
|
<li><a href="/path">item</a></li> |
|
128
|
|
|
</ul> |
|
129
|
|
|
HTML, |
|
130
|
|
|
Menu::widget() |
|
131
|
|
|
->currentPath('/path') |
|
|
|
|
|
|
132
|
|
|
->items([['label' => 'item', 'link' => '/path', 'active' => 'not-bool']]) |
|
133
|
|
|
->render(), |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @throws CircularReferenceException |
|
139
|
|
|
* @throws InvalidConfigException |
|
140
|
|
|
* @throws NotFoundException |
|
141
|
|
|
* @throws NotInstantiableException |
|
142
|
|
|
*/ |
|
143
|
|
|
public function testBefore(): void |
|
144
|
|
|
{ |
|
145
|
|
|
Assert::equalsWithoutLE( |
|
146
|
|
|
<<<HTML |
|
147
|
|
|
<a class="navbar-brand">Hidden brand</a> |
|
148
|
|
|
<ul> |
|
149
|
|
|
<li><a class="active" href="/path" aria-current="page">item</a></li> |
|
150
|
|
|
</ul> |
|
151
|
|
|
HTML, |
|
152
|
|
|
Menu::widget() |
|
153
|
|
|
->beforeClass('navbar-brand') |
|
|
|
|
|
|
154
|
|
|
->beforeContent('Hidden brand') |
|
155
|
|
|
->beforeTag('a') |
|
156
|
|
|
->currentPath('/path') |
|
157
|
|
|
->items($this->items) |
|
158
|
|
|
->render(), |
|
159
|
|
|
); |
|
160
|
|
|
|
|
161
|
|
|
Assert::equalsWithoutLE( |
|
162
|
|
|
<<<HTML |
|
163
|
|
|
<span class="d-flex" role="search"><input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> |
|
164
|
|
|
<button class="btn btn-outline-success" type="submit">Search</button></span> |
|
165
|
|
|
<ul> |
|
166
|
|
|
<li><a class="active" href="/path" aria-current="page">item</a></li> |
|
167
|
|
|
</ul> |
|
168
|
|
|
HTML, |
|
169
|
|
|
Menu::widget() |
|
170
|
|
|
->beforeAttributes(['role' => 'search']) |
|
|
|
|
|
|
171
|
|
|
->beforeClass('d-flex') |
|
172
|
|
|
->beforeContent( |
|
173
|
|
|
<<<HTML |
|
174
|
|
|
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> |
|
175
|
|
|
<button class="btn btn-outline-success" type="submit">Search</button> |
|
176
|
|
|
HTML, |
|
177
|
|
|
) |
|
178
|
|
|
->currentPath('/path') |
|
179
|
|
|
->items($this->items) |
|
180
|
|
|
->render(), |
|
181
|
|
|
); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @throws CircularReferenceException |
|
186
|
|
|
* @throws InvalidConfigException |
|
187
|
|
|
* @throws NotFoundException |
|
188
|
|
|
* @throws NotInstantiableException |
|
189
|
|
|
*/ |
|
190
|
|
|
public function testClass(): void |
|
191
|
|
|
{ |
|
192
|
|
|
Assert::equalsWithoutLE( |
|
193
|
|
|
<<<HTML |
|
194
|
|
|
<ul class="test-class"> |
|
195
|
|
|
<li><a href="/path">item</a></li> |
|
196
|
|
|
</ul> |
|
197
|
|
|
HTML, |
|
198
|
|
|
Menu::widget()->class('test-class')->items($this->items)->render(), |
|
|
|
|
|
|
199
|
|
|
); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @throws CircularReferenceException |
|
204
|
|
|
* @throws InvalidConfigException |
|
205
|
|
|
* @throws NotFoundException |
|
206
|
|
|
* @throws NotInstantiableException |
|
207
|
|
|
*/ |
|
208
|
|
|
public function testContainerWithFalse(): void |
|
209
|
|
|
{ |
|
210
|
|
|
Assert::equalsWithoutLE( |
|
211
|
|
|
<<<HTML |
|
212
|
|
|
<li><a href="/active">Active</a></li> |
|
213
|
|
|
<li><a href="#">Much longer nav link</a></li> |
|
214
|
|
|
<li><a href="#">Link</a></li> |
|
215
|
|
|
<li><a class="disabled" href="#">Disabled</a></li> |
|
216
|
|
|
HTML, |
|
217
|
|
|
Menu::widget()->container(false)->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
218
|
|
|
); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @throws CircularReferenceException |
|
223
|
|
|
* @throws InvalidConfigException |
|
224
|
|
|
* @throws NotFoundException |
|
225
|
|
|
* @throws NotInstantiableException |
|
226
|
|
|
*/ |
|
227
|
|
|
public function testDisabledClass(): void |
|
228
|
|
|
{ |
|
229
|
|
|
Assert::equalsWithoutLE( |
|
230
|
|
|
<<<HTML |
|
231
|
|
|
<ul> |
|
232
|
|
|
<li><a href="/active">Active</a></li> |
|
233
|
|
|
<li><a href="#">Much longer nav link</a></li> |
|
234
|
|
|
<li><a href="#">Link</a></li> |
|
235
|
|
|
<li><a class="disabled-class" href="#">Disabled</a></li> |
|
236
|
|
|
</ul> |
|
237
|
|
|
HTML, |
|
238
|
|
|
Menu::widget()->disabledClass('disabled-class')->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
239
|
|
|
); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @throws CircularReferenceException |
|
244
|
|
|
* @throws InvalidConfigException |
|
245
|
|
|
* @throws NotFoundException |
|
246
|
|
|
* @throws NotInstantiableException |
|
247
|
|
|
*/ |
|
248
|
|
|
public function testDropdown(): void |
|
249
|
|
|
{ |
|
250
|
|
|
Assert::equalsWithoutLE( |
|
251
|
|
|
<<<HTML |
|
252
|
|
|
<ul> |
|
253
|
|
|
<li><a class="active" href="/active" aria-current="page">Active</a></li> |
|
254
|
|
|
<li> |
|
255
|
|
|
<a href="#" aria-expanded="false" data-bs-toggle="dropdown" role="button">Dropdown</a> |
|
256
|
|
|
<ul> |
|
257
|
|
|
<li><a href="#">Action</a></li> |
|
258
|
|
|
<li><a href="#">Another action</a></li> |
|
259
|
|
|
<li><a href="#">Something else here</a></li> |
|
260
|
|
|
<li><hr class="dropdown-divider"></li> |
|
261
|
|
|
<li><a href="#">Separated link</a></li> |
|
262
|
|
|
</ul> |
|
263
|
|
|
</li> |
|
264
|
|
|
<li><a href="#">Link</a></li> |
|
265
|
|
|
<li><a class="disabled" href="#">Disabled</a></li> |
|
266
|
|
|
</ul> |
|
267
|
|
|
HTML, |
|
268
|
|
|
Menu::widget() |
|
269
|
|
|
->currentPath('/active') |
|
270
|
|
|
->items( |
|
271
|
|
|
[ |
|
272
|
|
|
['label' => 'Active', 'link' => '/active'], |
|
273
|
|
|
[ |
|
274
|
|
|
'label' => 'Dropdown', |
|
275
|
|
|
'link' => '#', |
|
276
|
|
|
'items' => [ |
|
277
|
|
|
['label' => 'Action', 'link' => '#'], |
|
278
|
|
|
['label' => 'Another action', 'link' => '#'], |
|
279
|
|
|
['label' => 'Something else here', 'link' => '#'], |
|
280
|
|
|
'-', |
|
281
|
|
|
['label' => 'Separated link', 'link' => '#'], |
|
282
|
|
|
], |
|
283
|
|
|
], |
|
284
|
|
|
['label' => 'Link', 'link' => '#'], |
|
285
|
|
|
['label' => 'Disabled', 'link' => '#', 'disabled' => true], |
|
286
|
|
|
] |
|
287
|
|
|
) |
|
288
|
|
|
->render(), |
|
289
|
|
|
); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @throws CircularReferenceException |
|
294
|
|
|
* @throws InvalidConfigException |
|
295
|
|
|
* @throws NotFoundException |
|
296
|
|
|
* @throws NotInstantiableException |
|
297
|
|
|
*/ |
|
298
|
|
|
public function testDropdownContainerClass(): void |
|
299
|
|
|
{ |
|
300
|
|
|
Assert::equalsWithoutLE( |
|
301
|
|
|
<<<HTML |
|
302
|
|
|
<ul> |
|
303
|
|
|
<li><a class="active" href="/active" aria-current="page">Active</a></li> |
|
304
|
|
|
<li class="nav-item dropdown"> |
|
305
|
|
|
<a href="#" aria-expanded="false" data-bs-toggle="dropdown" role="button">Dropdown</a> |
|
306
|
|
|
<ul> |
|
307
|
|
|
<li><a href="#">Action</a></li> |
|
308
|
|
|
<li><a href="#">Another action</a></li> |
|
309
|
|
|
<li><a href="#">Something else here</a></li> |
|
310
|
|
|
<li><hr class="dropdown-divider"></li> |
|
311
|
|
|
<li><a href="#">Separated link</a></li> |
|
312
|
|
|
</ul> |
|
313
|
|
|
</li> |
|
314
|
|
|
<li><a href="#">Link</a></li> |
|
315
|
|
|
<li><a class="disabled" href="#">Disabled</a></li> |
|
316
|
|
|
</ul> |
|
317
|
|
|
HTML, |
|
318
|
|
|
Menu::widget() |
|
319
|
|
|
->currentPath('/active') |
|
320
|
|
|
->dropdownContainerClass('nav-item dropdown') |
|
321
|
|
|
->items( |
|
322
|
|
|
[ |
|
323
|
|
|
['label' => 'Active', 'link' => '/active'], |
|
324
|
|
|
[ |
|
325
|
|
|
'label' => 'Dropdown', |
|
326
|
|
|
'link' => '#', |
|
327
|
|
|
'items' => [ |
|
328
|
|
|
['label' => 'Action', 'link' => '#'], |
|
329
|
|
|
['label' => 'Another action', 'link' => '#'], |
|
330
|
|
|
['label' => 'Something else here', 'link' => '#'], |
|
331
|
|
|
'-', |
|
332
|
|
|
['label' => 'Separated link', 'link' => '#'], |
|
333
|
|
|
], |
|
334
|
|
|
], |
|
335
|
|
|
['label' => 'Link', 'link' => '#'], |
|
336
|
|
|
['label' => 'Disabled', 'link' => '#', 'disabled' => true], |
|
337
|
|
|
] |
|
338
|
|
|
) |
|
339
|
|
|
->render(), |
|
340
|
|
|
); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @throws CircularReferenceException |
|
345
|
|
|
* @throws InvalidConfigException |
|
346
|
|
|
* @throws NotFoundException |
|
347
|
|
|
* @throws NotInstantiableException |
|
348
|
|
|
*/ |
|
349
|
|
|
public function testDropdownDefinitions(): void |
|
350
|
|
|
{ |
|
351
|
|
|
Assert::equalsWithoutLE( |
|
352
|
|
|
<<<HTML |
|
353
|
|
|
<ul> |
|
354
|
|
|
<li><a class="active" href="/active" aria-current="page">Active</a></li> |
|
355
|
|
|
<li> |
|
356
|
|
|
<a class="dropdown-toggle" href="#" aria-expanded="false" data-bs-toggle="dropdown" role="button">Dropdown</a> |
|
357
|
|
|
<ul class="dropdown-menu"> |
|
358
|
|
|
<li><a class="dropdown-item" href="#">Action</a></li> |
|
359
|
|
|
<li><a class="dropdown-item" href="#">Another action</a></li> |
|
360
|
|
|
<li><a class="dropdown-item" href="#">Something else here</a></li> |
|
361
|
|
|
<li><hr class="dropdown-divider"></li> |
|
362
|
|
|
<li><a class="dropdown-item" href="#">Separated link</a></li> |
|
363
|
|
|
</ul> |
|
364
|
|
|
</li> |
|
365
|
|
|
<li><a href="#">Link</a></li> |
|
366
|
|
|
<li><a class="disabled" href="#">Disabled</a></li> |
|
367
|
|
|
</ul> |
|
368
|
|
|
HTML, |
|
369
|
|
|
Menu::widget() |
|
370
|
|
|
->currentPath('/active') |
|
371
|
|
|
->dropdownDefinitions( |
|
372
|
|
|
[ |
|
373
|
|
|
'container()' => [false], |
|
374
|
|
|
'dividerClass()' => ['dropdown-divider'], |
|
375
|
|
|
'headerClass()' => ['dropdown-header'], |
|
376
|
|
|
'itemClass()' => ['dropdown-item'], |
|
377
|
|
|
'itemsContainerClass()' => ['dropdown-menu'], |
|
378
|
|
|
'toggleAttributes()' => [ |
|
379
|
|
|
[ |
|
380
|
|
|
'aria-expanded' => 'false', |
|
381
|
|
|
'data-bs-toggle' => 'dropdown', |
|
382
|
|
|
'role' => 'button', |
|
383
|
|
|
], |
|
384
|
|
|
], |
|
385
|
|
|
'toggleClass()' => ['dropdown-toggle'], |
|
386
|
|
|
'toggleType()' => ['link'], |
|
387
|
|
|
] |
|
388
|
|
|
) |
|
389
|
|
|
->items( |
|
390
|
|
|
[ |
|
391
|
|
|
['label' => 'Active', 'link' => '/active'], |
|
392
|
|
|
[ |
|
393
|
|
|
'label' => 'Dropdown', |
|
394
|
|
|
'link' => '#', |
|
395
|
|
|
'items' => [ |
|
396
|
|
|
['label' => 'Action', 'link' => '#'], |
|
397
|
|
|
['label' => 'Another action', 'link' => '#'], |
|
398
|
|
|
['label' => 'Something else here', 'link' => '#'], |
|
399
|
|
|
'-', |
|
400
|
|
|
['label' => 'Separated link', 'link' => '#'], |
|
401
|
|
|
], |
|
402
|
|
|
], |
|
403
|
|
|
['label' => 'Link', 'link' => '#'], |
|
404
|
|
|
['label' => 'Disabled', 'link' => '#', 'disabled' => true], |
|
405
|
|
|
] |
|
406
|
|
|
) |
|
407
|
|
|
->render(), |
|
408
|
|
|
); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* @throws CircularReferenceException |
|
413
|
|
|
* @throws InvalidConfigException |
|
414
|
|
|
* @throws NotFoundException |
|
415
|
|
|
* @throws NotInstantiableException |
|
416
|
|
|
*/ |
|
417
|
|
|
public function testFirstItemCssClass(): void |
|
418
|
|
|
{ |
|
419
|
|
|
Assert::equalsWithoutLE( |
|
420
|
|
|
<<<HTML |
|
421
|
|
|
<ul> |
|
422
|
|
|
<li class="first-item-class"><a href="/active">Active</a></li> |
|
423
|
|
|
<li><a href="#">Much longer nav link</a></li> |
|
424
|
|
|
<li><a href="#">Link</a></li> |
|
425
|
|
|
<li><a class="disabled" href="#">Disabled</a></li> |
|
426
|
|
|
</ul> |
|
427
|
|
|
HTML, |
|
428
|
|
|
Menu::widget()->firstItemClass('first-item-class')->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
429
|
|
|
); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* @throws CircularReferenceException |
|
434
|
|
|
* @throws InvalidConfigException |
|
435
|
|
|
* @throws NotFoundException |
|
436
|
|
|
* @throws NotInstantiableException |
|
437
|
|
|
*/ |
|
438
|
|
|
public function testItemsClassAsArray(): void |
|
439
|
|
|
{ |
|
440
|
|
|
$items = [ |
|
441
|
|
|
[ |
|
442
|
|
|
'label' => 'item1', |
|
443
|
|
|
'link' => '#', |
|
444
|
|
|
'active' => true, |
|
445
|
|
|
'itemsContainerAttributes' => ['class' => ['some-class']], |
|
446
|
|
|
], |
|
447
|
|
|
[ |
|
448
|
|
|
'label' => 'item2', |
|
449
|
|
|
'link' => '#', |
|
450
|
|
|
'itemsContainerAttributes' => ['class' => ['another-class', 'other--class', 'two classes']], |
|
451
|
|
|
], |
|
452
|
|
|
[ |
|
453
|
|
|
'label' => 'item3', |
|
454
|
|
|
'link' => '#', |
|
455
|
|
|
], |
|
456
|
|
|
[ |
|
457
|
|
|
'label' => 'item4', |
|
458
|
|
|
'link' => '#', |
|
459
|
|
|
'itemsContainerAttributes' => ['class' => ['some-other-class', 'foo_bar_baz_class']], |
|
460
|
|
|
], |
|
461
|
|
|
[ |
|
462
|
|
|
'label' => 'item5', |
|
463
|
|
|
'link' => '#', |
|
464
|
|
|
'attributes' => ['class' => ['some-other-class', 'foo_bar_baz_class']], |
|
465
|
|
|
'visible' => false, |
|
466
|
|
|
], |
|
467
|
|
|
]; |
|
468
|
|
|
|
|
469
|
|
|
Assert::equalsWithoutLE( |
|
470
|
|
|
<<<HTML |
|
471
|
|
|
<ul> |
|
472
|
|
|
<li class="some-class"><a class="item-active" href="#" aria-current="page">item1</a></li> |
|
473
|
|
|
<li class="another-class other--class two classes"><a href="#">item2</a></li> |
|
474
|
|
|
<li><a href="#">item3</a></li> |
|
475
|
|
|
<li class="some-other-class foo_bar_baz_class"><a href="#">item4</a></li> |
|
476
|
|
|
</ul> |
|
477
|
|
|
HTML, |
|
478
|
|
|
Menu::widget()->activeClass('item-active')->items($items)->render(), |
|
|
|
|
|
|
479
|
|
|
); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* @throws CircularReferenceException |
|
484
|
|
|
* @throws InvalidConfigException |
|
485
|
|
|
* @throws NotFoundException |
|
486
|
|
|
* @throws NotInstantiableException |
|
487
|
|
|
*/ |
|
488
|
|
|
public function testItemsContainerAttributes(): void |
|
489
|
|
|
{ |
|
490
|
|
|
Assert::equalsWithoutLE( |
|
491
|
|
|
<<<HTML |
|
492
|
|
|
<ul> |
|
493
|
|
|
<li class="nav-item"><a href="/active">Active</a></li> |
|
494
|
|
|
<li class="nav-item"><a href="#">Much longer nav link</a></li> |
|
495
|
|
|
<li class="nav-item"><a href="#">Link</a></li> |
|
496
|
|
|
<li class="nav-item"><a class="disabled" href="#">Disabled</a></li> |
|
497
|
|
|
</ul> |
|
498
|
|
|
HTML, |
|
499
|
|
|
Menu::widget()->itemsContainerAttributes(['class' => 'nav-item'])->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
500
|
|
|
); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* @throws CircularReferenceException |
|
505
|
|
|
* @throws InvalidConfigException |
|
506
|
|
|
* @throws NotFoundException |
|
507
|
|
|
* @throws NotInstantiableException |
|
508
|
|
|
*/ |
|
509
|
|
|
public function testItemsContainerClass(): void |
|
510
|
|
|
{ |
|
511
|
|
|
Assert::equalsWithoutLE( |
|
512
|
|
|
<<<HTML |
|
513
|
|
|
<ul> |
|
514
|
|
|
<li class="nav-item"><a href="/active">Active</a></li> |
|
515
|
|
|
<li class="nav-item"><a href="#">Much longer nav link</a></li> |
|
516
|
|
|
<li class="nav-item"><a href="#">Link</a></li> |
|
517
|
|
|
<li class="nav-item"><a class="disabled" href="#">Disabled</a></li> |
|
518
|
|
|
</ul> |
|
519
|
|
|
HTML, |
|
520
|
|
|
Menu::widget()->itemsContainerClass('nav-item')->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
521
|
|
|
); |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/** |
|
525
|
|
|
* @throws CircularReferenceException |
|
526
|
|
|
* @throws InvalidConfigException |
|
527
|
|
|
* @throws NotFoundException |
|
528
|
|
|
* @throws NotInstantiableException |
|
529
|
|
|
*/ |
|
530
|
|
|
public function testItemsContainerWithFalse(): void |
|
531
|
|
|
{ |
|
532
|
|
|
Assert::equalsWithoutLE( |
|
533
|
|
|
<<<HTML |
|
534
|
|
|
<ul> |
|
535
|
|
|
<a href="/active">Active</a> |
|
536
|
|
|
<a href="#">Much longer nav link</a> |
|
537
|
|
|
<a href="#">Link</a> |
|
538
|
|
|
<a class="disabled" href="#">Disabled</a> |
|
539
|
|
|
</ul> |
|
540
|
|
|
HTML, |
|
541
|
|
|
Menu::widget()->itemsContainer(false)->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
542
|
|
|
); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* @throws CircularReferenceException |
|
547
|
|
|
* @throws InvalidConfigException |
|
548
|
|
|
* @throws NotFoundException |
|
549
|
|
|
* @throws NotInstantiableException |
|
550
|
|
|
*/ |
|
551
|
|
|
public function testItemsEncodeDefault(): void |
|
552
|
|
|
{ |
|
553
|
|
|
Assert::equalsWithoutLE( |
|
554
|
|
|
<<<HTML |
|
555
|
|
|
<ul> |
|
556
|
|
|
<li>Black & White</li> |
|
557
|
|
|
</ul> |
|
558
|
|
|
HTML, |
|
559
|
|
|
Menu::widget()->items([['label' => 'Black & White']])->render(), |
|
|
|
|
|
|
560
|
|
|
); |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
/** |
|
564
|
|
|
* @throws CircularReferenceException |
|
565
|
|
|
* @throws InvalidConfigException |
|
566
|
|
|
* @throws NotFoundException |
|
567
|
|
|
* @throws NotInstantiableException |
|
568
|
|
|
*/ |
|
569
|
|
|
public function testItemsEncodeWithFalse(): void |
|
570
|
|
|
{ |
|
571
|
|
|
Assert::equalsWithoutLE( |
|
572
|
|
|
<<<HTML |
|
573
|
|
|
<ul> |
|
574
|
|
|
<li>Black & White</li> |
|
575
|
|
|
</ul> |
|
576
|
|
|
HTML, |
|
577
|
|
|
Menu::widget()->items([['label' => 'Black & White', 'encode' => false]])->render(), |
|
578
|
|
|
); |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
/** |
|
582
|
|
|
* @throws CircularReferenceException |
|
583
|
|
|
* @throws InvalidConfigException |
|
584
|
|
|
* @throws NotFoundException |
|
585
|
|
|
* @throws NotInstantiableException |
|
586
|
|
|
*/ |
|
587
|
|
|
public function testItemsIcon(): void |
|
588
|
|
|
{ |
|
589
|
|
|
Assert::equalsWithoutLE( |
|
590
|
|
|
<<<HTML |
|
591
|
|
|
<ul> |
|
592
|
|
|
<li><a class="me-2" href="/active"><span class="me-2"><i>🏠</i></span>Home</a></li> |
|
593
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i>📧</i></span>Contact</a></li> |
|
594
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i>🔑</i></span>Login</a></li> |
|
595
|
|
|
</ul> |
|
596
|
|
|
HTML, |
|
597
|
|
|
Menu::widget() |
|
598
|
|
|
->iconContainerAttributes(['class' => 'me-2']) |
|
|
|
|
|
|
599
|
|
|
->linkAttributes(['class' => 'me-2']) |
|
600
|
|
|
->items( |
|
601
|
|
|
[ |
|
602
|
|
|
['label' => 'Home', 'link' => '/active', 'icon' => '🏠'], |
|
603
|
|
|
['label' => 'Contact', 'link' => '#', 'icon' => '📧'], |
|
604
|
|
|
['label' => 'Login', 'link' => '#', 'icon' => '🔑'], |
|
605
|
|
|
], |
|
606
|
|
|
) |
|
607
|
|
|
->render(), |
|
608
|
|
|
); |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
/** |
|
612
|
|
|
* @throws CircularReferenceException |
|
613
|
|
|
* @throws InvalidConfigException |
|
614
|
|
|
* @throws NotFoundException |
|
615
|
|
|
* @throws NotInstantiableException |
|
616
|
|
|
*/ |
|
617
|
|
|
public function testItemsIconAttributes(): void |
|
618
|
|
|
{ |
|
619
|
|
|
Assert::equalsWithoutLE( |
|
620
|
|
|
<<<HTML |
|
621
|
|
|
<ul> |
|
622
|
|
|
<li><a class="me-2" href="/active"><span class="me-2"><i class="bi bi-house"></i></span>Home</a></li> |
|
623
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i class="bi bi-envelope"></i></span>Contact</a></li> |
|
624
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i class="bi bi-lock"></i></span>Login</a></li> |
|
625
|
|
|
</ul> |
|
626
|
|
|
HTML, |
|
627
|
|
|
Menu::widget() |
|
628
|
|
|
->iconContainerAttributes(['class' => 'me-2']) |
|
629
|
|
|
->linkAttributes(['class' => 'me-2']) |
|
630
|
|
|
->items( |
|
631
|
|
|
[ |
|
632
|
|
|
['label' => 'Home', 'link' => '/active', 'iconAttributes' => ['class' => 'bi bi-house']], |
|
633
|
|
|
['label' => 'Contact', 'link' => '#', 'iconAttributes' => ['class' => 'bi bi-envelope']], |
|
634
|
|
|
['label' => 'Login', 'link' => '#', 'iconAttributes' => ['class' => 'bi bi-lock']], |
|
635
|
|
|
], |
|
636
|
|
|
) |
|
637
|
|
|
->render(), |
|
638
|
|
|
); |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
|
|
/** |
|
642
|
|
|
* @throws CircularReferenceException |
|
643
|
|
|
* @throws InvalidConfigException |
|
644
|
|
|
* @throws NotFoundException |
|
645
|
|
|
* @throws NotInstantiableException |
|
646
|
|
|
*/ |
|
647
|
|
|
public function testItemsIconClass(): void |
|
648
|
|
|
{ |
|
649
|
|
|
Assert::equalsWithoutLE( |
|
650
|
|
|
<<<HTML |
|
651
|
|
|
<ul> |
|
652
|
|
|
<li><a class="me-2" href="/active"><span class="me-2"><i class="bi bi-house"></i></span>Home</a></li> |
|
653
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i class="bi bi-envelope"></i></span>Contact</a></li> |
|
654
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i class="bi bi-lock"></i></span>Login</a></li> |
|
655
|
|
|
</ul> |
|
656
|
|
|
HTML, |
|
657
|
|
|
Menu::widget() |
|
658
|
|
|
->iconContainerAttributes(['class' => 'me-2']) |
|
659
|
|
|
->linkAttributes(['class' => 'me-2']) |
|
660
|
|
|
->items( |
|
661
|
|
|
[ |
|
662
|
|
|
['label' => 'Home', 'link' => '/active', 'iconClass' => 'bi bi-house'], |
|
663
|
|
|
['label' => 'Contact', 'link' => '#', 'iconClass' => 'bi bi-envelope'], |
|
664
|
|
|
['label' => 'Login', 'link' => '#', 'iconClass' => 'bi bi-lock'], |
|
665
|
|
|
], |
|
666
|
|
|
) |
|
667
|
|
|
->render(), |
|
668
|
|
|
); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* @throws CircularReferenceException |
|
673
|
|
|
* @throws InvalidConfigException |
|
674
|
|
|
* @throws NotFoundException |
|
675
|
|
|
* @throws NotInstantiableException |
|
676
|
|
|
*/ |
|
677
|
|
|
public function testItemsIconContainerAttributes(): void |
|
678
|
|
|
{ |
|
679
|
|
|
Assert::equalsWithoutLE( |
|
680
|
|
|
<<<HTML |
|
681
|
|
|
<ul> |
|
682
|
|
|
<li><a class="me-2" href="/active"><span class="me-2"><i class="bi bi-house"></i></span>Home</a></li> |
|
683
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i class="bi bi-envelope"></i></span>Contact</a></li> |
|
684
|
|
|
<li><a class="me-2" href="#"><span class="me-3"><i class="bi bi-lock"></i></span>Login</a></li> |
|
685
|
|
|
</ul> |
|
686
|
|
|
HTML, |
|
687
|
|
|
Menu::widget() |
|
688
|
|
|
->iconContainerAttributes(['class' => 'me-2']) |
|
689
|
|
|
->linkAttributes(['class' => 'me-2']) |
|
690
|
|
|
->items( |
|
691
|
|
|
[ |
|
692
|
|
|
['label' => 'Home', 'link' => '/active', 'iconClass' => 'bi bi-house'], |
|
693
|
|
|
['label' => 'Contact', 'link' => '#', 'iconClass' => 'bi bi-envelope'], |
|
694
|
|
|
[ |
|
695
|
|
|
'label' => 'Login', |
|
696
|
|
|
'link' => '#', |
|
697
|
|
|
'iconClass' => 'bi bi-lock', |
|
698
|
|
|
'iconContainerAttributes' => ['class' => 'me-3'], |
|
699
|
|
|
], |
|
700
|
|
|
], |
|
701
|
|
|
) |
|
702
|
|
|
->render(), |
|
703
|
|
|
); |
|
704
|
|
|
} |
|
705
|
|
|
|
|
706
|
|
|
/** |
|
707
|
|
|
* @throws CircularReferenceException |
|
708
|
|
|
* @throws InvalidConfigException |
|
709
|
|
|
* @throws NotFoundException |
|
710
|
|
|
* @throws NotInstantiableException |
|
711
|
|
|
*/ |
|
712
|
|
|
public function testItemsIconWithEmptyStringLabel(): void |
|
713
|
|
|
{ |
|
714
|
|
|
Assert::equalsWithoutLE( |
|
715
|
|
|
<<<HTML |
|
716
|
|
|
<ul> |
|
717
|
|
|
<li><a class="me-2" href="/active"><span class="me-2"><i>🏠</i></span></a></li> |
|
718
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i>📧</i></span></a></li> |
|
719
|
|
|
<li><a class="me-2" href="#"><span class="me-2"><i>🔑</i></span></a></li> |
|
720
|
|
|
</ul> |
|
721
|
|
|
HTML, |
|
722
|
|
|
Menu::widget() |
|
723
|
|
|
->iconContainerAttributes(['class' => 'me-2']) |
|
724
|
|
|
->linkAttributes(['class' => 'me-2']) |
|
725
|
|
|
->items( |
|
726
|
|
|
[ |
|
727
|
|
|
['label' => '', 'link' => '/active', 'icon' => '🏠'], |
|
728
|
|
|
['label' => '', 'link' => '#', 'icon' => '📧'], |
|
729
|
|
|
['label' => '', 'link' => '#', 'icon' => '🔑'], |
|
730
|
|
|
], |
|
731
|
|
|
) |
|
732
|
|
|
->render(), |
|
733
|
|
|
); |
|
734
|
|
|
} |
|
735
|
|
|
|
|
736
|
|
|
/** |
|
737
|
|
|
* @throws CircularReferenceException |
|
738
|
|
|
* @throws InvalidConfigException |
|
739
|
|
|
* @throws NotFoundException |
|
740
|
|
|
* @throws NotInstantiableException |
|
741
|
|
|
*/ |
|
742
|
|
|
public function testLastItemCssClass(): void |
|
743
|
|
|
{ |
|
744
|
|
|
Assert::equalsWithoutLE( |
|
745
|
|
|
<<<HTML |
|
746
|
|
|
<ul> |
|
747
|
|
|
<li><a href="/active">Active</a></li> |
|
748
|
|
|
<li><a href="#">Much longer nav link</a></li> |
|
749
|
|
|
<li><a href="#">Link</a></li> |
|
750
|
|
|
<li class="last-item-class"><a class="disabled" href="#">Disabled</a></li> |
|
751
|
|
|
</ul> |
|
752
|
|
|
HTML, |
|
753
|
|
|
Menu::widget()->lastItemClass('last-item-class')->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
754
|
|
|
); |
|
755
|
|
|
} |
|
756
|
|
|
|
|
757
|
|
|
/** |
|
758
|
|
|
* @throws CircularReferenceException |
|
759
|
|
|
* @throws InvalidConfigException |
|
760
|
|
|
* @throws NotFoundException |
|
761
|
|
|
* @throws NotInstantiableException |
|
762
|
|
|
*/ |
|
763
|
|
|
public function testLinkClass(): void |
|
764
|
|
|
{ |
|
765
|
|
|
Assert::equalsWithoutLE( |
|
766
|
|
|
<<<HTML |
|
767
|
|
|
<ul> |
|
768
|
|
|
<li><a class="test-class" href="/active">Active</a></li> |
|
769
|
|
|
<li><a class="test-class" href="#">Much longer nav link</a></li> |
|
770
|
|
|
<li><a class="test-class" href="#">Link</a></li> |
|
771
|
|
|
<li><a class="test-class disabled" href="#">Disabled</a></li> |
|
772
|
|
|
</ul> |
|
773
|
|
|
HTML, |
|
774
|
|
|
Menu::widget()->linkClass('test-class')->items($this->itemsWithOptions)->render(), |
|
|
|
|
|
|
775
|
|
|
); |
|
776
|
|
|
} |
|
777
|
|
|
|
|
778
|
|
|
/** |
|
779
|
|
|
* @throws CircularReferenceException |
|
780
|
|
|
* @throws InvalidConfigException |
|
781
|
|
|
* @throws NotFoundException |
|
782
|
|
|
* @throws NotInstantiableException |
|
783
|
|
|
*/ |
|
784
|
|
|
public function testRender(): void |
|
785
|
|
|
{ |
|
786
|
|
|
$this->assertEmpty(Menu::widget()->render()); |
|
787
|
|
|
} |
|
788
|
|
|
|
|
789
|
|
|
/** |
|
790
|
|
|
* @throws CircularReferenceException |
|
791
|
|
|
* @throws InvalidConfigException |
|
792
|
|
|
* @throws NotFoundException |
|
793
|
|
|
* @throws NotInstantiableException |
|
794
|
|
|
*/ |
|
795
|
|
|
public function testTemplate(): void |
|
796
|
|
|
{ |
|
797
|
|
|
Assert::equalsWithoutLE( |
|
798
|
|
|
<<<HTML |
|
799
|
|
|
<ul> |
|
800
|
|
|
<div class="test-class"><li><a href="/active">Active</a></li></div> |
|
801
|
|
|
<div class="test-class"><li><a href="#">Much longer nav link</a></li></div> |
|
802
|
|
|
<div class="test-class"><li><a href="#">Link</a></li></div> |
|
803
|
|
|
<div class="test-class"><li><a class="disabled" href="#">Disabled</a></li></div> |
|
804
|
|
|
</ul> |
|
805
|
|
|
HTML, |
|
806
|
|
|
Menu::widget()->items($this->itemsWithOptions)->template('<div class="test-class">{items}</div>')->render(), |
|
807
|
|
|
); |
|
808
|
|
|
} |
|
809
|
|
|
} |
|
810
|
|
|
|