1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests\Dropdown; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Yiisoft\Definitions\Exception\CircularReferenceException; |
10
|
|
|
use Yiisoft\Definitions\Exception\InvalidConfigException; |
11
|
|
|
use Yiisoft\Definitions\Exception\NotInstantiableException; |
12
|
|
|
use Yiisoft\Factory\NotFoundException; |
13
|
|
|
use Yiisoft\Yii\Widgets\Dropdown; |
14
|
|
|
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
18
|
|
|
*/ |
19
|
|
|
final class ExceptionTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use TestTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws CircularReferenceException |
25
|
|
|
* @throws InvalidArgumentException |
26
|
|
|
* @throws InvalidConfigException |
27
|
|
|
* @throws NotFoundException |
28
|
|
|
* @throws NotInstantiableException |
29
|
|
|
*/ |
30
|
|
|
public function testContainerTag(): void |
31
|
|
|
{ |
32
|
|
|
$this->expectException(InvalidArgumentException::class); |
33
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
34
|
|
|
Dropdown::widget()->containerTag('')->items([['label' => 'test']])->render(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws CircularReferenceException |
39
|
|
|
* @throws InvalidArgumentException |
40
|
|
|
* @throws InvalidConfigException |
41
|
|
|
* @throws NotFoundException |
42
|
|
|
* @throws NotInstantiableException |
43
|
|
|
*/ |
44
|
|
|
public function testHeaderTag(): void |
45
|
|
|
{ |
46
|
|
|
$this->expectException(InvalidArgumentException::class); |
47
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
48
|
|
|
Dropdown::widget() |
49
|
|
|
->headerTag('') |
|
|
|
|
50
|
|
|
->items( |
51
|
|
|
[ |
52
|
|
|
[ |
53
|
|
|
'label' => 'Dropdown', |
54
|
|
|
'link' => '#', |
55
|
|
|
'items' => [ |
56
|
|
|
['label' => 'Dropdown header', 'link' => ''], |
57
|
|
|
['label' => 'Action', 'link' => '#'], |
58
|
|
|
['label' => 'Another action', 'link' => '#'], |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
] |
62
|
|
|
) |
63
|
|
|
->render(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @throws CircularReferenceException |
68
|
|
|
* @throws InvalidArgumentException |
69
|
|
|
* @throws InvalidConfigException |
70
|
|
|
* @throws NotFoundException |
71
|
|
|
* @throws NotInstantiableException |
72
|
|
|
*/ |
73
|
|
|
public function testItemDividerTag(): void |
74
|
|
|
{ |
75
|
|
|
$this->expectException(InvalidArgumentException::class); |
76
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
77
|
|
|
Dropdown::widget()->dividerTag('')->items([['label' => 'test'], '-'])->render(); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @throws CircularReferenceException |
82
|
|
|
* @throws InvalidArgumentException |
83
|
|
|
* @throws InvalidConfigException |
84
|
|
|
* @throws NotFoundException |
85
|
|
|
* @throws NotInstantiableException |
86
|
|
|
*/ |
87
|
|
|
public function testItemContainerTag(): void |
88
|
|
|
{ |
89
|
|
|
$this->expectException(InvalidArgumentException::class); |
90
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
91
|
|
|
Dropdown::widget()->itemContainerTag('')->items([['label' => 'test']])->render(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @throws CircularReferenceException |
96
|
|
|
* @throws InvalidArgumentException |
97
|
|
|
* @throws InvalidConfigException |
98
|
|
|
* @throws NotFoundException |
99
|
|
|
* @throws NotInstantiableException |
100
|
|
|
*/ |
101
|
|
|
public function testItemTag(): void |
102
|
|
|
{ |
103
|
|
|
$this->expectException(InvalidArgumentException::class); |
104
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
105
|
|
|
Dropdown::widget()->itemTag('')->items([['label' => 'test']])->render(); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @throws CircularReferenceException |
110
|
|
|
* @throws InvalidArgumentException |
111
|
|
|
* @throws InvalidConfigException |
112
|
|
|
* @throws NotFoundException |
113
|
|
|
* @throws NotInstantiableException |
114
|
|
|
*/ |
115
|
|
|
public function testItemsContainerTag(): void |
116
|
|
|
{ |
117
|
|
|
$this->expectException(InvalidArgumentException::class); |
118
|
|
|
$this->expectExceptionMessage('Tag name must be a string and cannot be empty.'); |
119
|
|
|
Dropdown::widget() |
120
|
|
|
->itemsContainerTag('') |
|
|
|
|
121
|
|
|
->items( |
122
|
|
|
[ |
123
|
|
|
[ |
124
|
|
|
'label' => 'Dropdown', |
125
|
|
|
'link' => '#', |
126
|
|
|
'items' => [ |
127
|
|
|
['label' => 'Action', 'link' => '#'], |
128
|
|
|
['label' => 'Another action', 'link' => '#'], |
129
|
|
|
['label' => 'Something else here', 'link' => '#'], |
130
|
|
|
'-', |
131
|
|
|
['label' => 'Separated link', 'link' => '#'], |
132
|
|
|
], |
133
|
|
|
], |
134
|
|
|
] |
135
|
|
|
) |
136
|
|
|
->render(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @throws CircularReferenceException |
141
|
|
|
* @throws InvalidArgumentException |
142
|
|
|
* @throws InvalidConfigException |
143
|
|
|
* @throws NotFoundException |
144
|
|
|
* @throws NotInstantiableException |
145
|
|
|
*/ |
146
|
|
|
public function testLabelExceptionEmpty(): void |
147
|
|
|
{ |
148
|
|
|
$this->expectException(InvalidArgumentException::class); |
149
|
|
|
$this->expectExceptionMessage('The "label" option is required.'); |
150
|
|
|
Dropdown::widget()->items([['link' => '/home']])->render(); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @throws CircularReferenceException |
155
|
|
|
* @throws InvalidArgumentException |
156
|
|
|
* @throws InvalidConfigException |
157
|
|
|
* @throws NotFoundException |
158
|
|
|
* @throws NotInstantiableException |
159
|
|
|
*/ |
160
|
|
|
public function testLabelExceptionEmptyString(): void |
161
|
|
|
{ |
162
|
|
|
$this->expectException(InvalidArgumentException::class); |
163
|
|
|
$this->expectExceptionMessage('The "label" cannot be an empty string.'); |
164
|
|
|
Dropdown::widget()->items([['label' => '']])->render(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @throws CircularReferenceException |
169
|
|
|
* @throws InvalidArgumentException |
170
|
|
|
* @throws InvalidConfigException |
171
|
|
|
* @throws NotFoundException |
172
|
|
|
* @throws NotInstantiableException |
173
|
|
|
*/ |
174
|
|
|
public function testLabelExceptionNotString(): void |
175
|
|
|
{ |
176
|
|
|
$this->expectException(InvalidArgumentException::class); |
177
|
|
|
$this->expectExceptionMessage('The "label" option must be a string.'); |
178
|
|
|
Dropdown::widget()->items([['label' => 1]])->render(); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|