3d3040c2b889f4f43d1dc8a1a6953254eb6e9da4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / FormEngine / ElementsBasicInputCest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Codeception\Example;
19 use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
20 use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;
21
22 /**
23 * Tests for "elements_basic" simple input fields of ext:styleguide
24 */
25 class ElementsBasicInputCest extends AbstractElementsBasicCest
26 {
27 /**
28 * Open list module of styleguide elements basic page
29 *
30 * @param BackendTester $I
31 * @param PageTree $pageTree
32 */
33 public function _before(BackendTester $I, PageTree $pageTree)
34 {
35 $I->useExistingSession('admin');
36 $I->click('List');
37 $pageTree->openPath(['styleguide TCA demo', 'elements basic']);
38 $I->switchToContentFrame();
39
40 // Open record and wait until form is ready
41 $I->waitForText('elements basic', 20);
42 $editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[data-original-title="Edit record"]';
43 $I->click($editRecordLinkCssPath);
44 $I->waitForElementNotVisible('#t3js-ui-block');
45 $I->waitForText('Edit Form', 3, 'h1');
46 }
47
48 /**
49 * Data provider to check various type=input variants
50 */
51 protected function simpleInputFieldsDataProvider()
52 {
53 return [
54 [
55 'label' => 'input_1',
56 'inputValue' => 'This is a demo text',
57 'expectedValue' => 'This is a demo text',
58 'expectedInternalValue' => 'This is a demo text',
59 'expectedValueAfterSave' => 'This is a demo text',
60 'comment' => '',
61 ],
62 [
63 'label' => 'input_2, size=10',
64 'inputValue' => 'This is a demo text with numbers and other characters 42 #!',
65 'expectedValue' => 'This is a demo text with numbers and other characters 42 #!',
66 'expectedInternalValue' => 'This is a demo text with numbers and other characters 42 #!',
67 'expectedValueAfterSave' => 'This is a demo text with numbers and other characters 42 #!',
68 'comment' => '',
69 ],
70 [
71 'label' => 'input_3 max=4',
72 'inputValue' => 'Kasper',
73 'expectedValue' => 'Kasp',
74 'expectedInternalValue' => 'Kasp',
75 'expectedValueAfterSave' => 'Kasp',
76 'comment' => '',
77 ],
78 [
79 'label' => 'input_4 eval=alpha',
80 'inputValue' => 'Kasper = TYPO3',
81 'expectedValue' => 'KasperTYPO',
82 'expectedInternalValue' => 'KasperTYPO',
83 'expectedValueAfterSave' => 'KasperTYPO',
84 'comment' => '',
85 ],
86 [
87 'label' => 'input_4 eval=alpha',
88 'inputValue' => 'Non-latin characters: ŠĐŽĆČ',
89 'expectedValue' => 'Nonlatincharacters',
90 'expectedInternalValue' => 'Nonlatincharacters',
91 'expectedValueAfterSave' => 'Nonlatincharacters',
92 'comment' => '',
93 ],
94 [
95 'label' => 'input_5 eval=alphanum',
96 'inputValue' => 'Kasper = TYPO3',
97 'expectedValue' => 'KasperTYPO3',
98 'expectedInternalValue' => 'KasperTYPO3',
99 'expectedValueAfterSave' => 'KasperTYPO3',
100 'comment' => '',
101 ],
102 [
103 'label' => 'input_10 eval=is_in, is_in=abc123',
104 'inputValue' => 'abcd1234',
105 'expectedValue' => 'abc123',
106 'expectedInternalValue' => 'abc123',
107 'expectedValueAfterSave' => 'abc123',
108 'comment' => '',
109 ],
110 [
111 'label' => 'input_10 eval=is_in, is_in=abc123',
112 'inputValue' => 'Kasper TYPO3',
113 'expectedValue' => 'a3',
114 'expectedInternalValue' => 'a3',
115 'expectedValueAfterSave' => 'a3',
116 'comment' => '',
117 ],
118 [
119 'label' => 'input_11 eval=lower',
120 'inputValue' => 'Kasper TYPO3!',
121 'expectedValue' => 'kasper typo3!',
122 'expectedInternalValue' => 'kasper typo3!',
123 'expectedValueAfterSave' => 'kasper typo3!',
124 'comment' => '',
125 ],
126 [
127 'label' => 'input_13 eval=nospace',
128 'inputValue' => ' Kasper TYPO3! ',
129 'expectedValue' => 'KasperTYPO3!',
130 'expectedInternalValue' => 'KasperTYPO3!',
131 'expectedValueAfterSave' => 'KasperTYPO3!',
132 'comment' => '',
133 ],
134 [
135 'label' => 'input_16 eval=password',
136 'inputValue' => 'Kasper',
137 'expectedValue' => '********',
138 'expectedInternalValue' => 'Kasper',
139 'expectedValueAfterSave' => 'Kasper',
140 'comment' => '',
141 ],
142 [
143 'label' => 'input_19 eval=trim',
144 'inputValue' => ' Kasper ',
145 'expectedValue' => 'Kasper',
146 'expectedInternalValue' => 'Kasper',
147 'expectedValueAfterSave' => 'Kasper',
148 'comment' => '',
149 ],
150 [
151 'label' => 'input_19 eval=trim',
152 'inputValue' => ' Kasper TYPO3 ',
153 'expectedValue' => 'Kasper TYPO3',
154 'expectedInternalValue' => 'Kasper TYPO3',
155 'expectedValueAfterSave' => 'Kasper TYPO3',
156 'comment' => '',
157 ],
158 [
159 'label' => 'input_23 eval=upper',
160 'inputValue' => 'Kasper TYPO3!',
161 'expectedValue' => 'KASPER TYPO3!',
162 'expectedInternalValue' => 'KASPER TYPO3!',
163 'expectedValueAfterSave' => 'KASPER TYPO3!',
164 'comment' => '',
165 ],
166 [
167 'label' => 'input_24 eval=year',
168 'inputValue' => '2016',
169 'expectedValue' => '2016',
170 'expectedInternalValue' => '2016',
171 'expectedValueAfterSave' => '2016',
172 'comment' => '',
173 ],
174 [
175 'label' => 'input_24 eval=year',
176 'inputValue' => '12',
177 'expectedValue' => '12',
178 'expectedInternalValue' => '12',
179 'expectedValueAfterSave' => '12',
180 'comment' => '',
181 ],
182 [
183 'label' => 'input_24 eval=year',
184 'inputValue' => 'Kasper',
185 'expectedValue' => date('Y'),
186 'expectedInternalValue' => date('Y'),
187 'expectedValueAfterSave' => date('Y'),
188 'comment' => 'Invalid character is converted to current year',
189 ]
190 ];
191 }
192
193 /**
194 * @dataProvider simpleInputFieldsDataProvider
195 * @param BackendTester $I
196 * @param Example $testData
197 */
198 public function simpleInputFields(BackendTester $I, Example $testData)
199 {
200 $this->runInputFieldTest($I, $testData);
201 }
202
203 /**
204 * Test various type=input fields having eval
205 */
206 protected function simpleEvalInputFieldsDataProvider()
207 {
208 return [
209 [
210 'label' => 'input_8 eval=double2',
211 'inputValue' => '12.335',
212 'expectedValue' => '12.34',
213 'expectedInternalValue' => '12.34',
214 'expectedValueAfterSave' => '12.34',
215 'comment' => '',
216 ],
217 [
218 'label' => 'input_8 eval=double2',
219 'inputValue' => '12,335', // comma as delimiter
220 'expectedValue' => '12.34',
221 'expectedInternalValue' => '12.34',
222 'expectedValueAfterSave' => '12.34',
223 'comment' => '',
224 ],
225 [
226 'label' => 'input_8 eval=double2',
227 'inputValue' => '1.1', // dot as delimiter
228 'expectedValue' => '1.10',
229 'expectedInternalValue' => '1.10',
230 'expectedValueAfterSave' => '1.10',
231 'comment' => '',
232 ],
233 [
234 'label' => 'input_8 eval=double2',
235 'inputValue' => 'TYPO3', // word having a number at end
236 'expectedValue' => '3.00',
237 'expectedInternalValue' => '3.00',
238 'expectedValueAfterSave' => '3.00',
239 'comment' => '',
240 ],
241 [
242 'label' => 'input_8 eval=double2',
243 'inputValue' => '3TYPO', // word having a number in front
244 'expectedValue' => '3.00',
245 'expectedInternalValue' => '3.00',
246 'expectedValueAfterSave' => '3.00',
247 'comment' => '',
248 ],
249 [
250 'label' => 'input_9 eval=int',
251 'inputValue' => '12.335',
252 'expectedValue' => '12',
253 'expectedInternalValue' => '12',
254 'expectedValueAfterSave' => '12',
255 'comment' => '',
256 ],
257 [
258 'label' => 'input_9 eval=int',
259 'inputValue' => '12,9',
260 'expectedValue' => '129',
261 'expectedInternalValue' => '129',
262 'expectedValueAfterSave' => '129',
263 'comment' => '',
264 ],
265 [
266 // this one probably broke with the type="number" patch
267 'label' => 'input_9 eval=int',
268 'inputValue' => 'TYPO3',
269 'expectedValue' => '0',
270 'expectedInternalValue' => '0',
271 'expectedValueAfterSave' => '0',
272 'comment' => '',
273 ],
274 [
275 'label' => 'input_9 eval=int',
276 'inputValue' => '3TYPO',
277 'expectedValue' => '3',
278 'expectedInternalValue' => '3',
279 'expectedValueAfterSave' => '3',
280 'comment' => '',
281 ],
282 [
283 'label' => 'input_15 eval=num',
284 'inputValue' => '12.335',
285 'expectedValue' => '12335',
286 'expectedInternalValue' => '12335',
287 'expectedValueAfterSave' => '12335',
288 'comment' => '',
289 ],
290 [
291 'label' => 'input_15 eval=num',
292 'inputValue' => '12,9',
293 'expectedValue' => '129',
294 'expectedInternalValue' => '129',
295 'expectedValueAfterSave' => '129',
296 'comment' => '',
297 ],
298 [
299 'label' => 'input_15 eval=num',
300 'inputValue' => 'TYPO3',
301 'expectedValue' => '3',
302 'expectedInternalValue' => '3',
303 'expectedValueAfterSave' => '3',
304 'comment' => '',
305 ],
306 [
307 'label' => 'input_15 eval=num',
308 'inputValue' => '3TYPO',
309 'expectedValue' => '3',
310 'expectedInternalValue' => '3',
311 'expectedValueAfterSave' => '3',
312 'comment' => '',
313 ],
314 ];
315 }
316
317 /**
318 * @dataProvider simpleEvalInputFieldsDataProvider
319 * @param BackendTester $I
320 * @param Example $testData
321 */
322 public function simpleEvalInputFields(BackendTester $I, Example $testData)
323 {
324 $this->runInputFieldTest($I, $testData);
325 }
326
327 /**
328 * type=input range and md5 field tests
329 */
330 protected function simpleRangeAndMd5FieldsDataProvider()
331 {
332 return [
333 [
334 // this one probably broke with the type="number" patch
335 'label' => 'input_25 eval=int, default=0, range lower=-2, range upper=2',
336 'inputValue' => 'Kasper TYPO3',
337 'expectedValue' => '0',
338 'expectedInternalValue' => '0',
339 'expectedValueAfterSave' => '0',
340 'comment' => '',
341 ],
342 [
343 'label' => 'input_25 eval=int, default=0, range lower=-2, range upper=2',
344 'inputValue' => '2',
345 'expectedValue' => '2',
346 'expectedInternalValue' => '2',
347 'expectedValueAfterSave' => '2',
348 'comment' => '',
349 ],
350 [
351 'label' => 'input_25 eval=int, default=0, range lower=-2, range upper=2',
352 'inputValue' => '-1',
353 'expectedValue' => '-1',
354 'expectedInternalValue' => '-1',
355 'expectedValueAfterSave' => '-1',
356 'comment' => '',
357 ],
358 [
359 'label' => 'input_12 eval=md5',
360 'inputValue' => 'Kasper TYPO3!',
361 'expectedValue' => '748469dd64911af8df8f9a3dcb2c9378',
362 'expectedInternalValue' => '748469dd64911af8df8f9a3dcb2c9378',
363 'expectedValueAfterSave' => '748469dd64911af8df8f9a3dcb2c9378',
364 'comment' => '',
365 ],
366 [
367 'label' => 'input_12 eval=md5',
368 'inputValue' => ' Kasper TYPO3! ',
369 'expectedValue' => '792a085606250c47d6ebb8c98804d5b0',
370 'expectedInternalValue' => '792a085606250c47d6ebb8c98804d5b0',
371 'expectedValueAfterSave' => '792a085606250c47d6ebb8c98804d5b0',
372 'comment' => 'Check whitespaces are not trimmed.',
373 ],
374 ];
375 }
376
377 /**
378 * @dataProvider simpleRangeAndMd5FieldsDataProvider
379 * @param BackendTester $I
380 * @param Example $testData
381 */
382 public function simpleRangeAndMd5Fields(BackendTester $I, Example $testData)
383 {
384 $this->runInputFieldTest($I, $testData);
385 }
386 }