1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Suricate\FormItem; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @SuppressWarnings("StaticAccess") |
7
|
|
|
*/ |
8
|
|
|
class FormItemTest extends \PHPUnit\Framework\TestCase |
9
|
|
|
{ |
10
|
|
|
public function testInput() |
11
|
|
|
{ |
12
|
|
|
$res = FormItem::input('text', 'myInput', "accentué", 'Mon input'); |
13
|
|
|
$this->assertEquals( |
14
|
|
|
'<label for="myInput">Mon input</label><input type="text" name="myInput" id="myInput" value="accentué"/>', |
15
|
|
|
$res |
16
|
|
|
); |
17
|
|
|
|
18
|
|
|
$res = FormItem::input('text', 'myInput', null, 'Mon input'); |
19
|
|
|
$this->assertEquals( |
20
|
|
|
'<label for="myInput">Mon input</label><input type="text" name="myInput" id="myInput"/>', |
21
|
|
|
$res |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$res = FormItem::input('text', 'myInput', "testval"); |
25
|
|
|
$this->assertEquals( |
26
|
|
|
'<input type="text" name="myInput" value="testval"/>', |
27
|
|
|
$res |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testIsset() |
32
|
|
|
{ |
33
|
|
|
$handler = new FormItem(['src' => 'http://']); |
34
|
|
|
$this->assertTrue(isset($handler->src)); |
|
|
|
|
35
|
|
|
$this->assertFalse(isset($handler->value)); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testInputText() |
39
|
|
|
{ |
40
|
|
|
$res = FormItem::text('my-input-name', "accentué", 'Mon input'); |
41
|
|
|
$this->assertEquals( |
42
|
|
|
'<label for="my-input-name">Mon input</label><input type="text" name="my-input-name" id="my-input-name" value="accentué"/>', |
43
|
|
|
$res |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testInputPassword() |
48
|
|
|
{ |
49
|
|
|
$res = FormItem::password('my-input-name', "accentué", 'Mon input'); |
50
|
|
|
$this->assertEquals( |
51
|
|
|
'<label for="my-input-name">Mon input</label><input type="password" name="my-input-name" id="my-input-name" value="accentué"/>', |
52
|
|
|
$res |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testInputNumber() |
57
|
|
|
{ |
58
|
|
|
$res = FormItem::number('my-input-name', "accentué", 'Mon input'); |
59
|
|
|
$this->assertEquals( |
60
|
|
|
'<label for="my-input-name">Mon input</label><input type="number" name="my-input-name" id="my-input-name" value="accentué"/>', |
61
|
|
|
$res |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testInputButton() |
66
|
|
|
{ |
67
|
|
|
$res = FormItem::button('my-input-name', "accentué", 'Mon input'); |
68
|
|
|
$this->assertEquals( |
69
|
|
|
'<label for="my-input-name">Mon input</label><input type="button" name="my-input-name" id="my-input-name" value="accentué"/>', |
70
|
|
|
$res |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testInputCheckbox() |
75
|
|
|
{ |
76
|
|
|
$res = FormItem::checkbox('my-input-name', 2, true, 'Mon input'); |
77
|
|
|
$this->assertEquals( |
78
|
|
|
'<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2" checked="checked"/>', |
79
|
|
|
$res |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$res = FormItem::checkbox('my-input-name', 2, false, 'Mon input'); |
83
|
|
|
$this->assertEquals( |
84
|
|
|
'<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2"/>', |
85
|
|
|
$res |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testInputRadio() |
90
|
|
|
{ |
91
|
|
|
$res = FormItem::radio('my-input-name', [1, 2, 3], 2, 'Mon input'); |
92
|
|
|
$this->assertEquals( |
93
|
|
|
'<label>Mon input</label><div class="radio-list"><div class="radio-item"><label for="my-input-name-0">1</label><input type="radio" name="my-input-name" id="my-input-name-0" value="0"/></div><div class="radio-item"><label for="my-input-name-1">2</label><input type="radio" name="my-input-name" id="my-input-name-1" value="1"/></div><div class="radio-item"><label for="my-input-name-2">3</label><input type="radio" name="my-input-name" id="my-input-name-2" value="2" checked="checked"/></div></div>', |
94
|
|
|
$res |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testInputReset() |
99
|
|
|
{ |
100
|
|
|
$res = FormItem::reset('val'); |
101
|
|
|
$this->assertEquals('<input type="reset" value="val"/>', $res); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testInputSelect() |
105
|
|
|
{ |
106
|
|
|
$res = FormItem::select('my-input-name', [1, 2, 3], 2, 'Mon input'); |
107
|
|
|
$this->assertEquals( |
108
|
|
|
'<label>Mon input</label><select name="my-input-name"><option value="0">1</option><option value="1">2</option><option value="2" selected>3</option></select>', |
109
|
|
|
$res |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$res = FormItem::select( |
113
|
|
|
'my-input-name', |
114
|
|
|
["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], |
115
|
|
|
2, |
116
|
|
|
'Mon input' |
117
|
|
|
); |
118
|
|
|
$this->assertEquals( |
119
|
|
|
'<label>Mon input</label><select name="my-input-name"><optgroup label="é""><option value="0">a</option><option value="1">b</option></optgroup><option value="0">2</option><optgroup label="3"><option value="0">c</option><option value="1">d</option></optgroup></select>', |
120
|
|
|
$res |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$res = FormItem::select( |
124
|
|
|
'my-input-name', |
125
|
|
|
["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], |
126
|
|
|
'c', |
127
|
|
|
'Mon input' |
128
|
|
|
); |
129
|
|
|
$this->assertEquals( |
130
|
|
|
'<label>Mon input</label><select name="my-input-name"><optgroup label="é""><option value="0" selected>a</option><option value="1">b</option></optgroup><option value="0" selected>2</option><optgroup label="3"><option value="0" selected>c</option><option value="1">d</option></optgroup></select>', |
131
|
|
|
$res |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$res = FormItem::select( |
135
|
|
|
'my-input-name', |
136
|
|
|
[1, 2, 3], |
137
|
|
|
[2, 1], |
138
|
|
|
'Mon input' |
139
|
|
|
); |
140
|
|
|
$this->assertEquals( |
141
|
|
|
'<label>Mon input</label><select name="my-input-name"><option value="0">1</option><option value="1" selected>2</option><option value="2" selected>3</option></select>', |
142
|
|
|
$res |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testInputFile() |
147
|
|
|
{ |
148
|
|
|
$res = FormItem::file('my-input-name', "Mon input"); |
149
|
|
|
$this->assertEquals( |
150
|
|
|
'<label for="my-input-name">Mon input</label><input type="file" name="my-input-name" id="my-input-name"/>', |
151
|
|
|
$res |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testInputHidden() |
156
|
|
|
{ |
157
|
|
|
$res = FormItem::hidden('my-input-name', "accentué"); |
158
|
|
|
$this->assertEquals( |
159
|
|
|
'<input type="hidden" name="my-input-name" value="accentué"/>', |
160
|
|
|
$res |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function testInputImage() |
165
|
|
|
{ |
166
|
|
|
$res = FormItem::image( |
167
|
|
|
'my-input-name', |
168
|
|
|
"https://gsuite.google.com/img/icons/product-lockup.png" |
169
|
|
|
); |
170
|
|
|
$this->assertEquals( |
171
|
|
|
'<input type="image" name="my-input-name" src="https://gsuite.google.com/img/icons/product-lockup.png"/>', |
172
|
|
|
$res |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function testInputSubmit() |
177
|
|
|
{ |
178
|
|
|
$res = FormItem::submit('my-input-name', "accentué", 'Mon input'); |
179
|
|
|
$this->assertEquals( |
180
|
|
|
'<label for="my-input-name">Mon input</label><input type="submit" name="my-input-name" id="my-input-name" value="accentué"/>', |
181
|
|
|
$res |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testInputTextarea() |
186
|
|
|
{ |
187
|
|
|
$res = FormItem::textarea('my-input-name', "accentué", 'Mon input'); |
188
|
|
|
$this->assertEquals( |
189
|
|
|
'<label for="my-input-name">Mon input</label><textarea name="my-input-name" id="my-input-name">accentué</textarea>', |
190
|
|
|
$res |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function testInputTel() |
195
|
|
|
{ |
196
|
|
|
$res = FormItem::tel('my-input-name', "accentué", 'Mon input'); |
197
|
|
|
$this->assertEquals( |
198
|
|
|
'<label for="my-input-name">Mon input</label><input type="tel" name="my-input-name" id="my-input-name" value="accentué"/>', |
199
|
|
|
$res |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testInputUrl() |
204
|
|
|
{ |
205
|
|
|
$res = FormItem::url('my-input-name', "accentué", 'Mon input'); |
206
|
|
|
$this->assertEquals( |
207
|
|
|
'<label for="my-input-name">Mon input</label><input type="url" name="my-input-name" id="my-input-name" value="accentué"/>', |
208
|
|
|
$res |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function testInputEmail() |
213
|
|
|
{ |
214
|
|
|
$res = FormItem::email('my-input-name', "accentué", 'Mon input'); |
215
|
|
|
$this->assertEquals( |
216
|
|
|
'<label for="my-input-name">Mon input</label><input type="email" name="my-input-name" id="my-input-name" value="accentué"/>', |
217
|
|
|
$res |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function testInputSearch() |
222
|
|
|
{ |
223
|
|
|
$res = FormItem::search('my-input-name', "accentué", 'Mon input'); |
224
|
|
|
$this->assertEquals( |
225
|
|
|
'<label for="my-input-name">Mon input</label><input type="search" name="my-input-name" id="my-input-name" value="accentué"/>', |
226
|
|
|
$res |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function testInputDate() |
231
|
|
|
{ |
232
|
|
|
$res = FormItem::date('my-input-name', "accentué", 'Mon input'); |
233
|
|
|
$this->assertEquals( |
234
|
|
|
'<label for="my-input-name">Mon input</label><input type="date" name="my-input-name" id="my-input-name" value="accentué"/>', |
235
|
|
|
$res |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public function testInputDateTime() |
240
|
|
|
{ |
241
|
|
|
$res = FormItem::datetime('my-input-name', "accentué", 'Mon input'); |
242
|
|
|
$this->assertEquals( |
243
|
|
|
'<label for="my-input-name">Mon input</label><input type="datetime" name="my-input-name" id="my-input-name" value="accentué"/>', |
244
|
|
|
$res |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testInputTime() |
249
|
|
|
{ |
250
|
|
|
$res = FormItem::time('my-input-name', "accentué", 'Mon input'); |
251
|
|
|
$this->assertEquals( |
252
|
|
|
'<label for="my-input-name">Mon input</label><input type="time" name="my-input-name" id="my-input-name" value="accentué"/>', |
253
|
|
|
$res |
254
|
|
|
); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|