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)); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
35 | $this->assertFalse(isset($handler->value)); |
||
0 ignored issues
–
show
The property
value does not exist on Suricate\FormItem . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
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 | |||
107 | $res = FormItem::select('my-input-name', [1, 2, 3], 2, 'Mon input'); |
||
108 | $this->assertEquals( |
||
109 | '<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>', |
||
110 | $res |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | public function testInputSelectWithEscapedOptGroup() |
||
115 | { |
||
116 | $res = FormItem::select( |
||
117 | 'my-input-name', |
||
118 | ["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], |
||
119 | 2, |
||
120 | 'Mon input' |
||
121 | ); |
||
122 | $this->assertEquals( |
||
123 | '<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>', |
||
124 | $res |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | public function testInputSelectWithEscapedOptGroupAndKeyValuesOptions() |
||
129 | { |
||
130 | $res = FormItem::select( |
||
131 | 'my-input-name', |
||
132 | [ |
||
133 | "é\"" => ['a', 'b'], |
||
134 | 2, |
||
135 | 3 => ['c' => 'option c', 'd' => 'option d'] |
||
136 | ], |
||
137 | 'c', |
||
138 | 'Mon input' |
||
139 | ); |
||
140 | $this->assertEquals( |
||
141 | '<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="c" selected>option c</option><option value="d">option d</option></optgroup></select>', |
||
142 | $res |
||
143 | ); |
||
144 | } |
||
145 | |||
146 | public function testInputSelectWithMultipleValues() |
||
147 | { |
||
148 | $res = FormItem::select( |
||
149 | 'my-input-name', |
||
150 | [1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'], // Available values |
||
151 | [2, 1], // selected values |
||
152 | 'Mon input' |
||
153 | ); |
||
154 | $this->assertEquals( |
||
155 | '<label>Mon input</label>' . |
||
156 | '<select name="my-input-name">' . |
||
157 | '<option value="1" selected>Value 1</option>' . |
||
158 | '<option value="2" selected>Value 2</option>' . |
||
159 | '<option value="3">Value 3</option>' . |
||
160 | '</select>', |
||
161 | $res |
||
162 | ); |
||
163 | } |
||
164 | |||
165 | public function testInputFile() |
||
166 | { |
||
167 | $res = FormItem::file('my-input-name', "Mon input"); |
||
168 | $this->assertEquals( |
||
169 | '<label for="my-input-name">Mon input</label><input type="file" name="my-input-name" id="my-input-name"/>', |
||
170 | $res |
||
171 | ); |
||
172 | } |
||
173 | |||
174 | public function testInputHidden() |
||
175 | { |
||
176 | $res = FormItem::hidden('my-input-name', "accentué"); |
||
177 | $this->assertEquals( |
||
178 | '<input type="hidden" name="my-input-name" value="accentué"/>', |
||
179 | $res |
||
180 | ); |
||
181 | } |
||
182 | |||
183 | public function testInputImage() |
||
184 | { |
||
185 | $res = FormItem::image( |
||
186 | 'my-input-name', |
||
187 | "https://gsuite.google.com/img/icons/product-lockup.png" |
||
188 | ); |
||
189 | $this->assertEquals( |
||
190 | '<input type="image" name="my-input-name" src="https://gsuite.google.com/img/icons/product-lockup.png"/>', |
||
191 | $res |
||
192 | ); |
||
193 | } |
||
194 | |||
195 | public function testInputSubmit() |
||
196 | { |
||
197 | $res = FormItem::submit('my-input-name', "accentué", 'Mon input'); |
||
198 | $this->assertEquals( |
||
199 | '<label for="my-input-name">Mon input</label><input type="submit" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
200 | $res |
||
201 | ); |
||
202 | } |
||
203 | |||
204 | public function testInputTextarea() |
||
205 | { |
||
206 | $res = FormItem::textarea('my-input-name', "accentué", 'Mon input'); |
||
207 | $this->assertEquals( |
||
208 | '<label for="my-input-name">Mon input</label><textarea name="my-input-name" id="my-input-name">accentué</textarea>', |
||
209 | $res |
||
210 | ); |
||
211 | } |
||
212 | |||
213 | public function testInputTel() |
||
214 | { |
||
215 | $res = FormItem::tel('my-input-name', "accentué", 'Mon input'); |
||
216 | $this->assertEquals( |
||
217 | '<label for="my-input-name">Mon input</label><input type="tel" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
218 | $res |
||
219 | ); |
||
220 | } |
||
221 | |||
222 | public function testInputUrl() |
||
223 | { |
||
224 | $res = FormItem::url('my-input-name', "accentué", 'Mon input'); |
||
225 | $this->assertEquals( |
||
226 | '<label for="my-input-name">Mon input</label><input type="url" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
227 | $res |
||
228 | ); |
||
229 | } |
||
230 | |||
231 | public function testInputEmail() |
||
232 | { |
||
233 | $res = FormItem::email('my-input-name', "accentué", 'Mon input'); |
||
234 | $this->assertEquals( |
||
235 | '<label for="my-input-name">Mon input</label><input type="email" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
236 | $res |
||
237 | ); |
||
238 | } |
||
239 | |||
240 | public function testInputSearch() |
||
241 | { |
||
242 | $res = FormItem::search('my-input-name', "accentué", 'Mon input'); |
||
243 | $this->assertEquals( |
||
244 | '<label for="my-input-name">Mon input</label><input type="search" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
245 | $res |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | public function testInputDate() |
||
250 | { |
||
251 | $res = FormItem::date('my-input-name', "accentué", 'Mon input'); |
||
252 | $this->assertEquals( |
||
253 | '<label for="my-input-name">Mon input</label><input type="date" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
254 | $res |
||
255 | ); |
||
256 | } |
||
257 | |||
258 | public function testInputDateTime() |
||
259 | { |
||
260 | $res = FormItem::datetime('my-input-name', "accentué", 'Mon input'); |
||
261 | $this->assertEquals( |
||
262 | '<label for="my-input-name">Mon input</label><input type="datetime-local" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
263 | $res |
||
264 | ); |
||
265 | } |
||
266 | |||
267 | public function testInputTime() |
||
268 | { |
||
269 | $res = FormItem::time('my-input-name', "accentué", 'Mon input'); |
||
270 | $this->assertEquals( |
||
271 | '<label for="my-input-name">Mon input</label><input type="time" name="my-input-name" id="my-input-name" value="accentué"/>', |
||
272 | $res |
||
273 | ); |
||
274 | } |
||
275 | } |
||
276 |