generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathBooleanInputTagTest.php
More file actions
238 lines (217 loc) · 6.81 KB
/
BooleanInputTagTest.php
File metadata and controls
238 lines (217 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
declare(strict_types=1);
namespace Yiisoft\Html\Tests\Tag\Base;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Html\Tests\Objects\TestBooleanInputTag;
final class BooleanInputTagTest extends TestCase
{
public function testChecked(): void
{
$this->assertSame('<input checked type="test">', (string)TestBooleanInputTag::tag()->checked());
$this->assertSame('<input type="test">', (string)TestBooleanInputTag::tag()->checked(false));
$this->assertSame('<input type="test">', (string)TestBooleanInputTag::tag()
->checked(true)
->checked(false));
}
public static function dataLabel(): array
{
return [
[
'<label><input type="test"> One</label>',
'One',
[],
],
[
'<label><input type="test"> <b>One</b></label>',
'<b>One</b>',
[],
],
[
'<label class="red"><input type="test"> One</label>',
'One',
['class' => 'red'],
],
[
'<label><input type="test"></label>',
'',
[],
],
[
'<input type="test">',
null,
[],
],
];
}
#[DataProvider('dataLabel')]
public function testLabel(string $expected, ?string $label, array $attributes): void
{
$this->assertSame(
$expected,
TestBooleanInputTag::tag()
->label($label, $attributes)
->render()
);
}
public function testLabelNoWrap(): void
{
$this->assertSame(
'<input id="ID" type="test"> <label for="ID">Voronezh</label>',
(string) TestBooleanInputTag::tag()
->id('ID')
->label('Voronezh', wrap: false),
);
}
public function testLabelWithId(): void
{
$this->assertSame(
'<label><input id="Test" type="test"> One</label>',
TestBooleanInputTag::tag()
->id('Test')
->label('One')
->render()
);
}
public function testSideLabel(): void
{
$this->assertMatchesRegularExpression(
'~<input id="i(\d*?)" type="test"> <label for="i\1">One</label>~',
TestBooleanInputTag::tag()
->sideLabel('One')
->render()
);
}
public function testSideLabelEmpty(): void
{
$this->assertMatchesRegularExpression(
'~<input id="i(\d*?)" type="test"> <label for="i\1"></label>~',
TestBooleanInputTag::tag()
->sideLabel('')
->render()
);
}
public function testSideLabelNull(): void
{
$this->assertSame(
'<input type="test">',
TestBooleanInputTag::tag()
->sideLabel(null)
->render()
);
}
public function testSideLabelWithId(): void
{
$this->assertSame(
'<input id="Test" type="test"> <label for="Test">One</label>',
TestBooleanInputTag::tag()
->id('Test')
->sideLabel('One')
->render()
);
}
public function testSideLabelWithAttributes(): void
{
$this->assertMatchesRegularExpression(
'~<input id="i(\d*?)" type="test"> <label class="red" for="i\1">One</label>~',
TestBooleanInputTag::tag()
->sideLabel('One', ['class' => 'red'])
->render()
);
}
public function testSideLabelId(): void
{
$this->assertSame(
'<input id="count" type="test"> <label for="count">One</label>',
TestBooleanInputTag::tag()
->sideLabel('One')
->id('count')
->render()
);
}
public function testWithoutLabelEncode(): void
{
$this->assertSame(
'<label><input type="test"> <b>One</b></label>',
TestBooleanInputTag::tag()
->label('<b>One</b>')
->labelEncode(false)
->render()
);
}
public static function dataUncheckValue(): array
{
return [
['<input type="test">', null, null],
['<input type="test">', null, 7],
['<input name="color" type="test">', 'color', null],
['<input name="color[]" type="test">', 'color[]', null],
[
'<input type="hidden" name="color" value="7"><input name="color" type="test">',
'color',
7,
],
[
'<input type="hidden" name="color" value="7"><input name="color[]" type="test">',
'color[]',
7,
],
];
}
#[DataProvider('dataUncheckValue')]
public function testUncheckValue(string $expected, ?string $name, $value): void
{
$this->assertSame(
$expected,
TestBooleanInputTag::tag()
->name($name)
->uncheckValue($value)
->render()
);
}
public function testUncheckValueDisabled(): void
{
$this->assertSame(
'<input type="hidden" name="color" value="7" disabled>' .
'<input name="color" disabled type="test">',
TestBooleanInputTag::tag()
->name('color')
->uncheckValue(7)
->disabled()
->render()
);
}
public function testUncheckValueForm(): void
{
$this->assertSame(
'<input type="hidden" name="color" value="7" form="post">' .
'<input name="color" form="post" type="test">',
TestBooleanInputTag::tag()
->name('color')
->uncheckValue(7)
->form('post')
->render()
);
}
public function testUncheckValueWithLabel(): void
{
$this->assertSame(
'<input type="hidden" name="color" value="7">' .
'<label><input name="color" type="test"> Seven</label>',
TestBooleanInputTag::tag()
->name('color')
->uncheckValue(7)
->label('Seven')
->render()
);
}
public function testImmutability(): void
{
$input = TestBooleanInputTag::tag();
$this->assertNotSame($input, $input->checked());
$this->assertNotSame($input, $input->label(''));
$this->assertNotSame($input, $input->sideLabel(''));
$this->assertNotSame($input, $input->labelEncode(true));
$this->assertNotSame($input, $input->uncheckValue(null));
}
}