|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Yiisoft\Widget\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use Yiisoft\Tests\TestCase; |
|
7
|
|
|
use Yiisoft\Widget\Breadcrumbs; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* BreadcrumbsTest. |
|
11
|
|
|
*/ |
|
12
|
|
|
class BreadcrumbsTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testHomeLinkTrue(): void |
|
15
|
|
|
{ |
|
16
|
|
|
ob_start(); |
|
17
|
|
|
ob_implicit_flush(0); |
|
18
|
|
|
|
|
19
|
|
|
echo Breadcrumbs::widget() |
|
20
|
|
|
->links([ |
|
21
|
|
|
'label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page' |
|
22
|
|
|
]); |
|
23
|
|
|
|
|
24
|
|
|
$actualHtml = ob_get_contents(); |
|
25
|
|
|
|
|
26
|
|
|
$expectedHtml = "<ul class=\"breadcrumb\"><li><a href=\"/\">Home</a></li>\n" . |
|
27
|
|
|
"<li class=\"active\">My Home Page</li>\n" . |
|
28
|
|
|
"<li class=\"active\">http://my.example.com/yii2/link/page</li>\n" . |
|
29
|
|
|
'</ul>'; |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals($expectedHtml, $actualHtml); |
|
32
|
|
|
|
|
33
|
|
|
ob_end_clean(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testEmptyLinks(): void |
|
37
|
|
|
{ |
|
38
|
|
|
ob_start(); |
|
39
|
|
|
ob_implicit_flush(0); |
|
40
|
|
|
|
|
41
|
|
|
echo Breadcrumbs::widget(); |
|
42
|
|
|
|
|
43
|
|
|
$actualHtml = ob_get_contents(); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEmpty($actualHtml); |
|
46
|
|
|
|
|
47
|
|
|
ob_end_clean(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testHomeLinkFalse(): void |
|
51
|
|
|
{ |
|
52
|
|
|
ob_start(); |
|
53
|
|
|
ob_implicit_flush(0); |
|
54
|
|
|
|
|
55
|
|
|
echo Breadcrumbs::widget() |
|
56
|
|
|
->homeLink(false) |
|
57
|
|
|
->links([ |
|
58
|
|
|
'label' => 'My Home Page', |
|
59
|
|
|
'url' => 'http://my.example.com/yii2/link/page' |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$actualHtml = ob_get_contents(); |
|
63
|
|
|
|
|
64
|
|
|
$expectedHtml = "<ul class=\"breadcrumb\"><li class=\"active\">My Home Page</li>\n" . |
|
65
|
|
|
"<li class=\"active\">http://my.example.com/yii2/link/page</li>\n" . |
|
66
|
|
|
'</ul>'; |
|
67
|
|
|
|
|
68
|
|
|
$this->assertEquals($expectedHtml, $actualHtml); |
|
69
|
|
|
|
|
70
|
|
|
ob_end_clean(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testHomeUrlLink(): void |
|
74
|
|
|
{ |
|
75
|
|
|
ob_start(); |
|
76
|
|
|
ob_implicit_flush(0); |
|
77
|
|
|
|
|
78
|
|
|
echo Breadcrumbs::widget() |
|
79
|
|
|
->homeLink(false) |
|
80
|
|
|
->homeUrlLink(['label' => 'home-link']) |
|
81
|
|
|
->links(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']); |
|
82
|
|
|
|
|
83
|
|
|
$expectedHtml = "<ul class=\"breadcrumb\"><li>home-link</li>\n" . |
|
84
|
|
|
"<li class=\"active\">My Home Page</li>\n" . |
|
85
|
|
|
"<li class=\"active\">http://my.example.com/yii2/link/page</li>\n" . |
|
86
|
|
|
'</ul>'; |
|
87
|
|
|
|
|
88
|
|
|
$actualHtml = ob_get_contents(); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertEquals($expectedHtml, $actualHtml); |
|
91
|
|
|
|
|
92
|
|
|
ob_end_clean(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testRenderItemException(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
98
|
|
|
|
|
99
|
|
|
echo Breadcrumbs::widget() |
|
100
|
|
|
->homeLink(false) |
|
101
|
|
|
->links([ |
|
102
|
|
|
'url' => 'http://my.example.com/yii2/link/page', |
|
103
|
|
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testRenderItemLabelOnlyEncodeLabelFalse(): void |
|
107
|
|
|
{ |
|
108
|
|
|
ob_start(); |
|
109
|
|
|
ob_implicit_flush(0); |
|
110
|
|
|
|
|
111
|
|
|
echo Breadcrumbs::widget() |
|
112
|
|
|
->activeItemTemplate("<li>{link}</li>\n") |
|
113
|
|
|
->encodeLabels(false) |
|
114
|
|
|
->homeLink(false) |
|
115
|
|
|
->links(['label' => 'My-<br>Test-Label']) |
|
116
|
|
|
->options([]) |
|
117
|
|
|
->tag(''); |
|
118
|
|
|
|
|
119
|
|
|
$actualHtml = ob_get_contents(); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertEquals("<li>My-<br>Test-Label</li>\n", $actualHtml); |
|
122
|
|
|
|
|
123
|
|
|
ob_end_clean(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testRenderItemLabelOnlyEncodeLabelTrue(): void |
|
128
|
|
|
{ |
|
129
|
|
|
ob_start(); |
|
130
|
|
|
ob_implicit_flush(0); |
|
131
|
|
|
|
|
132
|
|
|
echo Breadcrumbs::widget() |
|
133
|
|
|
->activeItemTemplate("<li>{link}</li>\n") |
|
134
|
|
|
->homeLink(false) |
|
135
|
|
|
->links(['label' => 'My-<br>Test-Label']) |
|
136
|
|
|
->options([]) |
|
137
|
|
|
->tag(''); |
|
138
|
|
|
|
|
139
|
|
|
$actualHtml = ob_get_contents(); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertEquals("<li>My-<br>Test-Label</li>\n", $actualHtml); |
|
142
|
|
|
|
|
143
|
|
|
ob_end_clean(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testOptions(): void |
|
147
|
|
|
{ |
|
148
|
|
|
ob_start(); |
|
149
|
|
|
ob_implicit_flush(0); |
|
150
|
|
|
|
|
151
|
|
|
echo Breadcrumbs::widget() |
|
152
|
|
|
->homeLink(false) |
|
153
|
|
|
->links(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']) |
|
154
|
|
|
->options(['class' => 'breadcrumb external']); |
|
155
|
|
|
|
|
156
|
|
|
$actualHtml = ob_get_contents(); |
|
157
|
|
|
|
|
158
|
|
|
$expectedHtml = "<ul class=\"breadcrumb external\"><li class=\"active\">My Home Page</li>\n"; |
|
159
|
|
|
|
|
160
|
|
|
$this->assertStringContainsString($expectedHtml, $actualHtml); |
|
161
|
|
|
|
|
162
|
|
|
ob_end_clean(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testTag(): void |
|
166
|
|
|
{ |
|
167
|
|
|
ob_start(); |
|
168
|
|
|
ob_implicit_flush(0); |
|
169
|
|
|
|
|
170
|
|
|
echo Breadcrumbs::widget() |
|
171
|
|
|
->activeItemTemplate("{link}\n") |
|
172
|
|
|
->itemTemplate("{link}\n") |
|
173
|
|
|
->homeLink(true) |
|
174
|
|
|
->links(['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']) |
|
175
|
|
|
->options(['class' => 'breadcrumb']) |
|
176
|
|
|
->tag('div'); |
|
177
|
|
|
|
|
178
|
|
|
$actualHtml = ob_get_contents(); |
|
179
|
|
|
|
|
180
|
|
|
$expectedHtml = "<div class=\"breadcrumb\"><a href=\"/\">Home</a>\n" . |
|
181
|
|
|
"My Home Page\n" . |
|
182
|
|
|
"http://my.example.com/yii2/link/page\n" . |
|
183
|
|
|
'</div>'; |
|
184
|
|
|
|
|
185
|
|
|
$this->assertEquals($expectedHtml, $actualHtml); |
|
186
|
|
|
|
|
187
|
|
|
ob_end_clean(); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|