|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Bootstrap4\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Bootstrap4\Nav; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Tests for Nav widget. |
|
11
|
|
|
* |
|
12
|
|
|
* NavTest |
|
13
|
|
|
*/ |
|
14
|
|
|
final class NavTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testIds(): void |
|
17
|
|
|
{ |
|
18
|
|
|
Nav::counter(0); |
|
19
|
|
|
|
|
20
|
|
|
$html = Nav::widget() |
|
21
|
|
|
->items([ |
|
22
|
|
|
[ |
|
23
|
|
|
'label' => 'Page1', |
|
24
|
|
|
'content' => 'Page1', |
|
25
|
|
|
], |
|
26
|
|
|
[ |
|
27
|
|
|
'label' => 'Dropdown1', |
|
28
|
|
|
'items' => [ |
|
29
|
|
|
['label' => 'Page2', 'content' => 'Page2'], |
|
30
|
|
|
['label' => 'Page3', 'content' => 'Page3'], |
|
31
|
|
|
] |
|
32
|
|
|
], |
|
33
|
|
|
[ |
|
34
|
|
|
'label' => 'Dropdown2', |
|
35
|
|
|
'visible' => false, |
|
36
|
|
|
'items' => [ |
|
37
|
|
|
['label' => 'Page4', 'content' => 'Page4'], |
|
38
|
|
|
['label' => 'Page5', 'content' => 'Page5'], |
|
39
|
|
|
] |
|
40
|
|
|
] |
|
41
|
|
|
]) |
|
42
|
|
|
->render(); |
|
43
|
|
|
|
|
44
|
|
|
$expected = <<<EXPECTED |
|
45
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Page1</a></li> |
|
46
|
|
|
<li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Dropdown1</a><div id="w1-dropdown" class="dropdown-menu"><h6 class="dropdown-header">Page2</h6> |
|
47
|
|
|
<h6 class="dropdown-header">Page3</h6></div></li></ul> |
|
48
|
|
|
EXPECTED; |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testRenderDropdownWithDropdownOptions(): void |
|
54
|
|
|
{ |
|
55
|
|
|
Nav::counter(0); |
|
56
|
|
|
|
|
57
|
|
|
$html = Nav::widget() |
|
58
|
|
|
->items([ |
|
59
|
|
|
[ |
|
60
|
|
|
'label' => 'Page1', |
|
61
|
|
|
'content' => 'Page1', |
|
62
|
|
|
], |
|
63
|
|
|
[ |
|
64
|
|
|
'label' => 'Dropdown1', |
|
65
|
|
|
'dropdownOptions' => ['class' => 'test', 'data-id' => 't1', 'id' => 'test1'], |
|
66
|
|
|
'items' => [ |
|
67
|
|
|
['label' => 'Page2', 'content' => 'Page2'], |
|
68
|
|
|
['label' => 'Page3', 'content' => 'Page3'], |
|
69
|
|
|
] |
|
70
|
|
|
], |
|
71
|
|
|
[ |
|
72
|
|
|
'label' => 'Dropdown2', |
|
73
|
|
|
'visible' => false, |
|
74
|
|
|
'items' => [ |
|
75
|
|
|
['label' => 'Page4', 'content' => 'Page4'], |
|
76
|
|
|
['label' => 'Page5', 'content' => 'Page5'], |
|
77
|
|
|
] |
|
78
|
|
|
] |
|
79
|
|
|
]) |
|
80
|
|
|
->render(); |
|
81
|
|
|
|
|
82
|
|
|
$expected = <<<EXPECTED |
|
83
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Page1</a></li> |
|
84
|
|
|
<li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Dropdown1</a><div id="test1" class="test dropdown-menu" data-id="t1"><h6 class="dropdown-header">Page2</h6> |
|
85
|
|
|
<h6 class="dropdown-header">Page3</h6></div></li></ul> |
|
86
|
|
|
EXPECTED; |
|
87
|
|
|
|
|
88
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testEmptyItems(): void |
|
92
|
|
|
{ |
|
93
|
|
|
Nav::counter(0); |
|
94
|
|
|
|
|
95
|
|
|
$html = Nav::widget() |
|
96
|
|
|
->items([ |
|
97
|
|
|
[ |
|
98
|
|
|
'label' => 'Page1', |
|
99
|
|
|
'items' => null, |
|
100
|
|
|
], |
|
101
|
|
|
[ |
|
102
|
|
|
'label' => 'Dropdown1', |
|
103
|
|
|
'items' => [ |
|
104
|
|
|
['label' => 'Page2', 'content' => 'Page2'], |
|
105
|
|
|
['label' => 'Page3', 'content' => 'Page3'], |
|
106
|
|
|
], |
|
107
|
|
|
], |
|
108
|
|
|
[ |
|
109
|
|
|
'label' => 'Page4', |
|
110
|
|
|
'items' => [], |
|
111
|
|
|
], |
|
112
|
|
|
]) |
|
113
|
|
|
->render(); |
|
114
|
|
|
|
|
115
|
|
|
$expected = <<<EXPECTED |
|
116
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Page1</a></li> |
|
117
|
|
|
<li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Dropdown1</a><div id="w1-dropdown" class="dropdown-menu"><h6 class="dropdown-header">Page2</h6> |
|
118
|
|
|
<h6 class="dropdown-header">Page3</h6></div></li> |
|
119
|
|
|
<li class="nav-item"><a class="nav-link" href="#">Page4</a></li></ul> |
|
120
|
|
|
EXPECTED; |
|
121
|
|
|
|
|
122
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/162 |
|
127
|
|
|
*/ |
|
128
|
|
|
public function testExplicitActive(): void |
|
129
|
|
|
{ |
|
130
|
|
|
Nav::counter(0); |
|
131
|
|
|
|
|
132
|
|
|
$html = Nav::widget() |
|
133
|
|
|
->activateItems(false) |
|
134
|
|
|
->items([ |
|
135
|
|
|
[ |
|
136
|
|
|
'label' => 'Item1', |
|
137
|
|
|
'active' => true, |
|
138
|
|
|
], |
|
139
|
|
|
[ |
|
140
|
|
|
'label' => 'Item2', |
|
141
|
|
|
'url' => '/site/index', |
|
142
|
|
|
], |
|
143
|
|
|
]) |
|
144
|
|
|
->render(); |
|
145
|
|
|
|
|
146
|
|
|
$expected = <<<EXPECTED |
|
147
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Item1</a></li> |
|
148
|
|
|
<li class="nav-item"><a class="nav-link" href="/site/index">Item2</a></li></ul> |
|
149
|
|
|
EXPECTED; |
|
150
|
|
|
|
|
151
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/162 |
|
156
|
|
|
*/ |
|
157
|
|
|
public function testImplicitActive(): void |
|
158
|
|
|
{ |
|
159
|
|
|
Nav::counter(0); |
|
160
|
|
|
|
|
161
|
|
|
$html = Nav::widget() |
|
162
|
|
|
->currentPath('/site/index') |
|
163
|
|
|
->items([ |
|
164
|
|
|
[ |
|
165
|
|
|
'label' => 'Item1', |
|
166
|
|
|
'active' => true, |
|
167
|
|
|
], |
|
168
|
|
|
[ |
|
169
|
|
|
'label' => 'Item2', |
|
170
|
|
|
'url' => '/site/index', |
|
171
|
|
|
], |
|
172
|
|
|
]) |
|
173
|
|
|
->render(); |
|
174
|
|
|
|
|
175
|
|
|
$expected = <<<EXPECTED |
|
176
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link active" href="#">Item1</a></li> |
|
177
|
|
|
<li class="nav-item"><a class="nav-link active" href="/site/index">Item2</a></li></ul> |
|
178
|
|
|
EXPECTED; |
|
179
|
|
|
|
|
180
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/162 |
|
185
|
|
|
*/ |
|
186
|
|
|
public function testExplicitActiveSubitems(): void |
|
187
|
|
|
{ |
|
188
|
|
|
Nav::counter(0); |
|
189
|
|
|
|
|
190
|
|
|
$html = Nav::widget() |
|
191
|
|
|
->activateItems(false) |
|
192
|
|
|
->currentPath('/site/index') |
|
193
|
|
|
->items([ |
|
194
|
|
|
[ |
|
195
|
|
|
'label' => 'Item1', |
|
196
|
|
|
], |
|
197
|
|
|
[ |
|
198
|
|
|
'label' => 'Item2', |
|
199
|
|
|
'items' => [ |
|
200
|
|
|
['label' => 'Page2', 'content' => 'Page2', 'url' => 'site/index'], |
|
201
|
|
|
['label' => 'Page3', 'content' => 'Page3', 'active' => true], |
|
202
|
|
|
], |
|
203
|
|
|
], |
|
204
|
|
|
]) |
|
205
|
|
|
->render(); |
|
206
|
|
|
|
|
207
|
|
|
$expected = <<<EXPECTED |
|
208
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Item1</a></li> |
|
209
|
|
|
<li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Item2</a><div id="w1-dropdown" class="dropdown-menu"><a class="dropdown-item" href="site/index">Page2</a> |
|
210
|
|
|
<h6 class="dropdown-header">Page3</h6></div></li></ul> |
|
211
|
|
|
EXPECTED; |
|
212
|
|
|
|
|
213
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/162 |
|
218
|
|
|
*/ |
|
219
|
|
|
public function testImplicitActiveSubitems(): void |
|
220
|
|
|
{ |
|
221
|
|
|
Nav::counter(0); |
|
222
|
|
|
|
|
223
|
|
|
$html = Nav::widget() |
|
224
|
|
|
->items([ |
|
225
|
|
|
[ |
|
226
|
|
|
'label' => 'Item1', |
|
227
|
|
|
], |
|
228
|
|
|
[ |
|
229
|
|
|
'label' => 'Item2', |
|
230
|
|
|
'items' => [ |
|
231
|
|
|
['label' => 'Page2', 'content' => 'Page2', 'url' => '/site/index'], |
|
232
|
|
|
['label' => 'Page3', 'content' => 'Page3', 'active' => true], |
|
233
|
|
|
], |
|
234
|
|
|
], |
|
235
|
|
|
]) |
|
236
|
|
|
->render(); |
|
237
|
|
|
|
|
238
|
|
|
$expected = <<<EXPECTED |
|
239
|
|
|
<ul id="w0-nav" class="nav"><li class="nav-item"><a class="nav-link" href="#">Item1</a></li> |
|
240
|
|
|
<li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Item2</a><div id="w1-dropdown" class="dropdown-menu"><a class="dropdown-item" href="/site/index">Page2</a> |
|
241
|
|
|
<h6 class="dropdown-header">Page3</h6></div></li></ul> |
|
242
|
|
|
EXPECTED; |
|
243
|
|
|
|
|
244
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/96 |
|
249
|
|
|
* @see https://github.com/yiisoft/yii2-bootstrap/issues/157 |
|
250
|
|
|
*/ |
|
251
|
|
|
public function testDeepActivateParents(): void |
|
252
|
|
|
{ |
|
253
|
|
|
Nav::counter(0); |
|
254
|
|
|
|
|
255
|
|
|
$html = Nav::widget() |
|
256
|
|
|
->activateParents(true) |
|
257
|
|
|
->items([ |
|
258
|
|
|
[ |
|
259
|
|
|
'label' => 'Dropdown', |
|
260
|
|
|
'items' => [ |
|
261
|
|
|
[ |
|
262
|
|
|
'label' => 'Sub-dropdown', |
|
263
|
|
|
'items' => [ |
|
264
|
|
|
['label' => 'Page', 'content' => 'Page', 'active' => true], |
|
265
|
|
|
], |
|
266
|
|
|
], |
|
267
|
|
|
], |
|
268
|
|
|
], |
|
269
|
|
|
]) |
|
270
|
|
|
->render(); |
|
271
|
|
|
|
|
272
|
|
|
$expected = <<<EXPECTED |
|
273
|
|
|
<ul id="w0-nav" class="nav"><li class="dropdown nav-item"><a class="dropdown-toggle nav-link active" href="#" data-toggle="dropdown">Dropdown</a><div id="w1-dropdown" class="dropdown-menu"><div class="dropdown active" aria-expanded="false"> |
|
274
|
|
|
<a class="dropdown-item dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button">Sub-dropdown</a> |
|
275
|
|
|
<div id="w2-dropdown" class="dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page</h6></div> |
|
276
|
|
|
</div></div></li></ul> |
|
277
|
|
|
EXPECTED; |
|
278
|
|
|
|
|
279
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|