1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests\Breadcrumbs; |
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\Breadcrumbs; |
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 BreadcrumbsTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use TestTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws CircularReferenceException |
25
|
|
|
* @throws InvalidConfigException |
26
|
|
|
* @throws NotFoundException |
27
|
|
|
* @throws NotInstantiableException |
28
|
|
|
*/ |
29
|
|
|
public function testAttributes(): void |
30
|
|
|
{ |
31
|
|
|
Assert::equalsWithoutLE( |
32
|
|
|
<<<HTML |
33
|
|
|
<ul class="breadcrumb external"> |
34
|
|
|
<li class="active">My Home Page</li> |
35
|
|
|
<li class="active">http://my.example.com/yii2/link/page</li> |
36
|
|
|
</ul> |
37
|
|
|
HTML, |
38
|
|
|
Breadcrumbs::widget() |
39
|
|
|
->attributes(['class' => 'breadcrumb external']) |
|
|
|
|
40
|
|
|
->homeItem(null) |
41
|
|
|
->items(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']) |
42
|
|
|
->render() |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @throws CircularReferenceException |
48
|
|
|
* @throws InvalidConfigException |
49
|
|
|
* @throws NotFoundException |
50
|
|
|
* @throws NotInstantiableException |
51
|
|
|
*/ |
52
|
|
|
public function testEmptyLinks(): void |
53
|
|
|
{ |
54
|
|
|
$this->assertEmpty(Breadcrumbs::widget()->render()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @throws CircularReferenceException |
59
|
|
|
* @throws InvalidConfigException |
60
|
|
|
* @throws NotFoundException |
61
|
|
|
* @throws NotInstantiableException |
62
|
|
|
*/ |
63
|
|
|
public function testHomeItem(): void |
64
|
|
|
{ |
65
|
|
|
Assert::equalsWithoutLE( |
66
|
|
|
<<<HTML |
67
|
|
|
<ul class="breadcrumb"> |
68
|
|
|
<li>home-link</li> |
69
|
|
|
<li class="active">My Home Page</li> |
70
|
|
|
<li class="active">http://my.example.com/yii2/link/page</li> |
71
|
|
|
</ul> |
72
|
|
|
HTML, |
73
|
|
|
Breadcrumbs::widget() |
74
|
|
|
->homeItem(['label' => 'home-link']) |
|
|
|
|
75
|
|
|
->items(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']) |
76
|
|
|
->render(), |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @throws CircularReferenceException |
82
|
|
|
* @throws InvalidConfigException |
83
|
|
|
* @throws NotFoundException |
84
|
|
|
* @throws NotInstantiableException |
85
|
|
|
*/ |
86
|
|
|
public function testItems(): void |
87
|
|
|
{ |
88
|
|
|
Assert::equalsWithoutLE( |
89
|
|
|
<<<HTML |
90
|
|
|
<ul class="breadcrumb"> |
91
|
|
|
<li><a href="/">Home</a></li> |
92
|
|
|
<li class="active">My Home Page</li> |
93
|
|
|
<li class="active">https://my.example.com/yii/link/page</li> |
94
|
|
|
</ul> |
95
|
|
|
HTML, |
96
|
|
|
Breadcrumbs::widget() |
97
|
|
|
->items(['label' => 'My Home Page', 'url' => 'https://my.example.com/yii/link/page']) |
|
|
|
|
98
|
|
|
->render(), |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @throws CircularReferenceException |
104
|
|
|
* @throws InvalidConfigException |
105
|
|
|
* @throws NotFoundException |
106
|
|
|
* @throws NotInstantiableException |
107
|
|
|
*/ |
108
|
|
|
public function testItemsWithTemplate(): void |
109
|
|
|
{ |
110
|
|
|
Assert::equalsWithoutLE( |
111
|
|
|
<<<HTML |
112
|
|
|
<ul class="breadcrumb"> |
113
|
|
|
<li><a href="/">Home</a></li> |
114
|
|
|
<li><a href="https://my.example.com/yii/link/page">Link</a></li> |
115
|
|
|
<span>Text</span> |
116
|
|
|
</ul> |
117
|
|
|
HTML, |
118
|
|
|
Breadcrumbs::widget() |
119
|
|
|
->items( |
120
|
|
|
[ |
121
|
|
|
['label' => 'Link', 'url' => 'https://my.example.com/yii/link/page'], |
122
|
|
|
['label' => 'Text', 'template' => "<span>{link}</span>\n"], |
123
|
|
|
] |
124
|
|
|
) |
125
|
|
|
->render(), |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @throws CircularReferenceException |
131
|
|
|
* @throws InvalidConfigException |
132
|
|
|
* @throws NotFoundException |
133
|
|
|
* @throws NotInstantiableException |
134
|
|
|
*/ |
135
|
|
|
public function testRenderItemLabelOnlyEncodeLabelFalse(): void |
136
|
|
|
{ |
137
|
|
|
$this->assertSame( |
138
|
|
|
"<li>My-<br>Test-Label</li>\n", |
139
|
|
|
Breadcrumbs::widget() |
140
|
|
|
->activeItemTemplate("<li>{link}</li>\n") |
|
|
|
|
141
|
|
|
->homeItem(null) |
142
|
|
|
->items([['label' => 'My-<br>Test-Label', 'encode' => false]]) // encode label false |
143
|
|
|
->tag('') |
144
|
|
|
->render() |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @throws CircularReferenceException |
150
|
|
|
* @throws InvalidConfigException |
151
|
|
|
* @throws NotFoundException |
152
|
|
|
* @throws NotInstantiableException |
153
|
|
|
*/ |
154
|
|
|
public function testRenderItemLabelOnlyEncodeLabelTrue(): void |
155
|
|
|
{ |
156
|
|
|
$this->assertSame( |
157
|
|
|
'<li>My-<br>Test-Label</li>', |
158
|
|
|
Breadcrumbs::widget() |
159
|
|
|
->activeItemTemplate('<li>{link}</li>') |
160
|
|
|
->homeItem(null) |
161
|
|
|
->items(['label' => 'My-<br>Test-Label']) |
162
|
|
|
->tag('') |
163
|
|
|
->render() |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @throws CircularReferenceException |
169
|
|
|
* @throws InvalidConfigException |
170
|
|
|
* @throws NotFoundException |
171
|
|
|
* @throws NotInstantiableException |
172
|
|
|
*/ |
173
|
|
|
public function testTag(): void |
174
|
|
|
{ |
175
|
|
|
Assert::equalsWithoutLE( |
176
|
|
|
<<<HTML |
177
|
|
|
<div class="breadcrumb"> |
178
|
|
|
<a href="/">Home</a> |
179
|
|
|
My Home Page |
180
|
|
|
http://my.example.com/yii2/link/page |
181
|
|
|
</div> |
182
|
|
|
HTML, |
183
|
|
|
Breadcrumbs::widget() |
184
|
|
|
->activeItemTemplate("{link}\n") |
185
|
|
|
->attributes(['class' => 'breadcrumb']) |
186
|
|
|
->items(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']) |
187
|
|
|
->itemTemplate("{link}\n") |
188
|
|
|
->tag('div') |
189
|
|
|
->render(), |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @throws CircularReferenceException |
195
|
|
|
* @throws InvalidConfigException |
196
|
|
|
* @throws NotFoundException |
197
|
|
|
* @throws NotInstantiableException |
198
|
|
|
*/ |
199
|
|
|
public function testWithoutHomeItem(): void |
200
|
|
|
{ |
201
|
|
|
Assert::equalsWithoutLE( |
202
|
|
|
<<<HTML |
203
|
|
|
<ul class="breadcrumb"> |
204
|
|
|
<li class="active">My Home Page</li> |
205
|
|
|
<li class="active">http://my.example.com/yii2/link/page</li> |
206
|
|
|
</ul> |
207
|
|
|
HTML, |
208
|
|
|
Breadcrumbs::widget() |
209
|
|
|
->homeItem(null) |
210
|
|
|
->items([ |
211
|
|
|
'label' => 'My Home Page', |
212
|
|
|
'url' => 'http://my.example.com/yii2/link/page', |
213
|
|
|
]) |
214
|
|
|
->render(), |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|