bc585dcbd5c0e2aa2c875823681db9dd9e12cc55
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / Formhandler / ElementsBasicCest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Formhandler;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Step\Backend\Admin;
18 use TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Support\Helper\Formhandler;
19 use TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Support\Helper\FormHandlerElementTestDataObject;
20 use TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Support\Page\PageTree;
21
22 /**
23 * Tests for basic element fields
24 */
25 class ElementsBasicCest
26 {
27 /**
28 * Selector of the record container in the listview
29 *
30 * @var string
31 */
32 protected static $listViewRecordSelector = '#recordlist-tx_styleguide_elements_basic';
33
34 public function _before(Admin $I, PageTree $pageTree)
35 {
36 $I->useExistingSession();
37 // Ensure main content frame is fully loaded, otherwise there are load-race-conditions
38 $I->switchToIFrame('list_frame');
39 $I->waitForText('Web Content Management System');
40 $I->switchToIFrame();
41
42 $I->click('List');
43 $pageTree->openPath(['styleguide TCA demo', 'elements basic']);
44 $I->switchToIFrame('list_frame');
45 }
46
47 /**
48 * @param Admin $I
49 * @param Formhandler $formhandler
50 */
51 public function checkThatBrowserSideValidationsWorkAndSaveRecord(Admin $I, Formhandler $formhandler)
52 {
53 $this->waitForFormReady($I);
54
55 $fieldTests = [
56 'input_1' => [
57 new FormHandlerElementTestDataObject(
58 'This is a demo text with 2 numbers #!',
59 'This is a demo text with 2 numbers #!'
60 )
61 ],
62 'input_2, size=10' => [
63 new FormHandlerElementTestDataObject(
64 'This is a demo text with 2 numbers #!',
65 'This is a demo text with 2 numbers #!'
66 )
67 ],
68 'input_3 max=4' => [
69 new FormHandlerElementTestDataObject(
70 'Kasper',
71 'Kasp'
72 )
73 ],
74 'input_4 eval=alpha' => [
75 new FormHandlerElementTestDataObject(
76 'Kasper = TYPO3',
77 'KasperTYPO'
78 ),
79 new FormHandlerElementTestDataObject(
80 'Non-latin characters: ŠĐŽĆČ',
81 'Nonlatincharacters'
82 ),
83 ],
84 'input_5 eval=alphanum' => [
85 new FormHandlerElementTestDataObject(
86 'Kasper = TYPO3',
87 'KasperTYPO3'
88 ),
89
90 ],
91 'input_8 eval=double2' => [
92 new FormHandlerElementTestDataObject(
93 '12.335',
94 '12.34',
95 '12.34'
96 ),
97 new FormHandlerElementTestDataObject(
98 '12,335',
99 '12.34',
100 '12.34'
101 ),
102 new FormHandlerElementTestDataObject(
103 '1.1',
104 '1.10',
105 '1.10'
106 ),
107 new FormHandlerElementTestDataObject(
108 'TYPO3',
109 '3.00',
110 '3.00'
111 ),
112 new FormHandlerElementTestDataObject(
113 '3TYPO',
114 '3.00',
115 '3.00'
116 )
117 ],
118 'input_9 eval=int' => [
119 new FormHandlerElementTestDataObject(
120 '12.335',
121 '12',
122 '12'
123
124 ),
125 new FormHandlerElementTestDataObject(
126 '12,9',
127 '12',
128 '12'
129 ),
130 new FormHandlerElementTestDataObject(
131 'TYPO3',
132 '0',
133 '0'
134 ),
135 new FormHandlerElementTestDataObject(
136 '3TYPO',
137 '3',
138 '3'
139 )
140 ],
141 'input_10 eval=is_in, is_in=abc123' => [
142 new FormHandlerElementTestDataObject(
143 'abcd1234',
144 'abc123'
145 ),
146 new FormHandlerElementTestDataObject(
147 'Kasper TYPO3',
148 'a3'
149 )
150 ],
151 'input_11 eval=lower' => [
152 new FormHandlerElementTestDataObject(
153 'Kasper TYPO3!',
154 'kasper typo3!'
155 )
156 ],
157 'input_12 eval=md5' => [
158 new FormHandlerElementTestDataObject(
159 'Kasper TYPO3!',
160 '748469dd64911af8df8f9a3dcb2c9378',
161 '748469dd64911af8df8f9a3dcb2c9378'
162 ),
163 new FormHandlerElementTestDataObject(
164 ' Kasper TYPO3! ',
165 '792a085606250c47d6ebb8c98804d5b0',
166 '792a085606250c47d6ebb8c98804d5b0',
167 '792a085606250c47d6ebb8c98804d5b0',
168 false,
169 'Check that whitespaces are not trimmed.'
170 )
171 ],
172 'input_13 eval=nospace' => [
173 new FormHandlerElementTestDataObject(
174 ' Kasper TYPO3! ',
175 'KasperTYPO3!'
176 )
177 ],
178 'input_15 eval=num' => [
179 new FormHandlerElementTestDataObject(
180 '12.335',
181 '12335'
182 ),
183 new FormHandlerElementTestDataObject(
184 '12,9',
185 '129'
186 ),
187 new FormHandlerElementTestDataObject(
188 'TYPO3',
189 '3'
190 ),
191 new FormHandlerElementTestDataObject(
192 '3TYPO',
193 '3'
194 ),
195 ],
196 'input_16 eval=password' => [
197 new FormHandlerElementTestDataObject(
198 'Kasper',
199 '********',
200 'Kasper'
201 ),
202 ],
203 'input_19 eval=trim' => [
204 new FormHandlerElementTestDataObject(
205 ' Kasper ',
206 'Kasper'
207 ),
208 new FormHandlerElementTestDataObject(
209 ' Kasper TYPO3 ',
210 'Kasper TYPO3'
211 ),
212 ],
213 'input_23 eval=upper' => [
214 new FormHandlerElementTestDataObject(
215 'Kasper TYPO3!',
216 'KASPER TYPO3!'
217 )
218 ],
219 'input_25 eval=int, default=0, range lower=-2, range upper=2' => [
220 new FormHandlerElementTestDataObject(
221 'Kasper TYPO3',
222 '0',
223 '0'
224 ),
225 new FormHandlerElementTestDataObject(
226 '2',
227 '2',
228 '2'
229 ),
230 new FormHandlerElementTestDataObject(
231 '-1',
232 '-1',
233 '-1'
234 ),
235 new FormHandlerElementTestDataObject(
236 '-3',
237 '-3',
238 '-3',
239 '-3',
240 true,
241 'Expecting a modal with error on trying to save.'
242
243 ),
244 new FormHandlerElementTestDataObject(
245 '3',
246 '-3',
247 '-3',
248 '-3',
249 true,
250 'Expecting a modal with error on trying to save.'
251 )
252 ],
253 ];
254
255 foreach ($fieldTests as $fieldLabel => $testData) {
256 $formhandler->fillSeeSaveAndClearInputField(
257 $fieldLabel,
258 $testData
259 );
260 }
261 }
262
263 /**
264 * @param Admin $I
265 * @param Formhandler $formhandler
266 */
267 public function checkThatValidationWorks_evalYear(Admin $I, Formhandler $formhandler)
268 {
269 $this->waitForFormReady($I);
270
271 $testData = [
272 'input_24 eval=year' => [
273 new FormHandlerElementTestDataObject(
274 '2016',
275 '2016',
276 '2016'
277 ),
278 new FormHandlerElementTestDataObject(
279 '12',
280 '2012',
281 '2012'
282 ),
283 new FormHandlerElementTestDataObject(
284 'Kasper',
285 date('Y'),
286 date('Y'),
287 date('Y'),
288 false,
289 'Invalid character is converted to current year'
290 )
291 ]
292 ];
293
294 $this->runTests($formhandler, $testData);
295 }
296
297 /**
298 * @param \TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Step\Backend\Admin $I
299 * @param \TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Support\Helper\Formhandler $formhandler
300 * @skip
301 */
302 public function checkThatBrowserSideValidationWorks_EvalDate(Admin $I, Formhandler $formhandler)
303 {
304 $this->skip("Instable Test is skipped due to repeated failure");
305 //@todo fix this test
306
307 $this->waitForFormReady($I);
308 $fieldData = [
309 'input_6 eval=date' => [
310 new FormHandlerElementTestDataObject(
311 '29-01-2016',
312 '29-01-2016',
313 '2016-01-29T00:00:00Z',
314 '2016-01-29T00:00:00+00:00'
315 ),
316 new FormHandlerElementTestDataObject(
317 '13-13-2016',
318 '13-01-2017',
319 '2017-01-13T00:00:00Z',
320 '2017-01-13T00:00:00+00:00'
321 ),
322 new FormHandlerElementTestDataObject(
323 '29-02-2016',
324 '29-02-2016',
325 '2016-02-29T00:00:00Z',
326 '2016-02-29T00:00:00+00:00',
327 false,
328 'Check valid leap year input'
329 ),
330 new FormHandlerElementTestDataObject(
331 '29-02-2015',
332 '01-03-2015',
333 '2015-03-01T00:00:00Z',
334 '2015-03-01T00:00:00+00:00',
335 false,
336 'Check invalid leap year transformation'
337 )
338 ]
339 ];
340 $this->runTests($formhandler, $fieldData);
341 }
342
343 public function checkThatValidationWorks_EvalDate_TypeDate(Admin $I, Formhandler $formhandler)
344 {
345 $this->waitForFormReady($I);
346 $testData = [
347 'input_36 dbType=date eval=date' => [
348 new FormHandlerElementTestDataObject(
349 '29-01-2016',
350 '29-01-2016',
351 '2016-01-29T00:00:00Z',
352 '2016-01-29T00:00:00+00:00'
353 ),
354 new FormHandlerElementTestDataObject(
355 '13-13-2016',
356 '13-01-2017',
357 '2017-01-13T00:00:00Z',
358 '2017-01-13T00:00:00+00:00'
359 ),
360 new FormHandlerElementTestDataObject(
361 '29-02-2016',
362 '29-02-2016',
363 '2016-02-29T00:00:00Z',
364 '2016-02-29T00:00:00+00:00',
365 false,
366 'Check valid leap year input'
367 ),
368 new FormHandlerElementTestDataObject(
369 '29-02-2015',
370 '01-03-2015',
371 '2015-03-01T00:00:00Z',
372 '2015-03-01T00:00:00+00:00',
373 false,
374 'Check invalid leap year transformation'
375 ),
376 ]
377 ];
378 $this->runTests($formhandler, $testData);
379 }
380
381 public function checkThatValidationWorks_EvalDateTime(Admin $I, Formhandler $formhandler)
382 {
383 $this->waitForFormReady($I);
384 $testData = [
385 'input_7 eval=datetime' => [
386 new FormHandlerElementTestDataObject(
387 '05:23 29-01-2016',
388 '05:23 29-01-2016',
389 '2016-01-29T05:23:00Z',
390 '2016-01-29T05:23:00+00:00'
391 ),
392 new FormHandlerElementTestDataObject(
393 '05:23 13-13-2016',
394 '05:23 13-01-2017',
395 '2017-01-13T05:23:00Z',
396 '2017-01-13T05:23:00+00:00'
397 ),
398 new FormHandlerElementTestDataObject(
399 '05:23 29-02-2016',
400 '05:23 29-02-2016',
401 '2016-02-29T05:23:00Z',
402 '2016-02-29T05:23:00+00:00',
403 false,
404 'Check valid leap year input'
405 ),
406 new FormHandlerElementTestDataObject(
407 '05:23 29-02-2015',
408 '05:23 01-03-2015',
409 '2015-03-01T05:23:00Z',
410 '2015-03-01T05:23:00+00:00',
411 false,
412 'Check invalid leap year transformation'
413 )
414 ]
415 ];
416 $this->runTests($formhandler, $testData);
417 }
418
419 public function checkThatValidationWorks_EvalDateTime_DbTypeDateTime(Admin $I, Formhandler $formhandler)
420 {
421 $this->waitForFormReady($I);
422 $testData = [
423 'input_37 dbType=datetime eval=datetime' => [
424 new FormHandlerElementTestDataObject(
425 '05:23 29-01-2016',
426 '05:23 29-01-2016',
427 '2016-01-29T05:23:00Z',
428 '2016-01-29T05:23:00+00:00'
429 ),
430 new FormHandlerElementTestDataObject(
431 '05:23 13-13-2016',
432 '05:23 13-01-2017',
433 '2017-01-13T05:23:00Z',
434 '2017-01-13T05:23:00+00:00'
435 ),
436 new FormHandlerElementTestDataObject(
437 '05:23 29-02-2016',
438 '05:23 29-02-2016',
439 '2016-02-29T05:23:00Z',
440 '2016-02-29T05:23:00+00:00',
441 false,
442 'Check valid leap year input'
443 ),
444 new FormHandlerElementTestDataObject(
445 '05:23 29-02-2015',
446 '05:23 01-03-2015',
447 '2015-03-01T05:23:00Z',
448 '2015-03-01T05:23:00+00:00',
449 false,
450 'Check invalid leap year transformation'
451 ),
452 ],
453 ];
454 $this->runTests($formhandler, $testData);
455 }
456
457 public function checkThatValidationWorks_evalTime(Admin $I, Formhandler $formhandler)
458 {
459 $this->waitForFormReady($I);
460 $testData = [
461 'input_17 eval=time' => [
462 new FormHandlerElementTestDataObject(
463 '13:30',
464 '13:30',
465 '13:30',
466 (new \DateTime('13:30'))->getTimestamp()
467 ),
468 new FormHandlerElementTestDataObject(
469 '123',
470 '12:03',
471 '12:03',
472 (new \DateTime('12:03'))->getTimestamp()
473 ),
474 new FormHandlerElementTestDataObject(
475 '12345',
476 '12:34',
477 '12:34',
478 (new \DateTime('12:34'))->getTimestamp()
479 ),
480 new FormHandlerElementTestDataObject(
481 '12:04+5',
482 '12:09',
483 '12:09',
484 (new \DateTime('12:09'))->getTimestamp()
485 ),
486 new FormHandlerElementTestDataObject(
487 '12:09-3',
488 '12:06',
489 '12:06',
490 (new \DateTime('12:06'))->getTimestamp()
491 )
492 ],
493 ];
494 $this->runTests($formhandler, $testData);
495 }
496
497 public function checkThatValidationWorks_evalTimesec(Admin $I, Formhandler $formhandler)
498 {
499 $this->skip("Instable Test is skipped due to repeated failure");
500 //@todo fix this test
501
502 $this->waitForFormReady($I);
503 $testData = [
504 'input_18 eval=timesec' => [
505 new FormHandlerElementTestDataObject(
506 '13:30:00',
507 '13:30:00',
508 '13:30:00',
509 (new \DateTime('13:30:00'))->getTimestamp()
510 ),
511 new FormHandlerElementTestDataObject(
512 '12345',
513 '12:34:05',
514 '12:34:05',
515 (new \DateTime('12:34:05'))->getTimestamp()
516 ),
517 new FormHandlerElementTestDataObject(
518 '12:04:04+5',
519 '12:09:04',
520 '12:09:04',
521 (new \DateTime('12:09:04'))->getTimestamp()
522 )
523 ],
524 ];
525 $this->runTests($formhandler, $testData);
526 }
527
528 /**
529 * @param \TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Support\Helper\Formhandler $formhandler
530 * @param $fieldData
531 */
532 protected function runTests(Formhandler $formhandler, $fieldData)
533 {
534 foreach ($fieldData as $fieldLabel => $testData) {
535 $formhandler->fillSeeSaveAndClearInputField(
536 $fieldLabel,
537 $testData
538 );
539 }
540 }
541
542 /**
543 * @param \TYPO3\CMS\Components\TestingFramework\Core\Acceptance\Step\Backend\Admin $I
544 */
545 protected function waitForFormReady(Admin $I)
546 {
547 $editRecordLinkCssPath = self::$listViewRecordSelector . ' a[data-original-title="Edit record"]';
548 $I->waitForElement($editRecordLinkCssPath, 30);
549 $I->click($editRecordLinkCssPath);
550 $I->waitForText('Edit Form', 3, 'h1');
551 }
552
553 /**
554 * From Codeception/Scenario
555 */
556 protected function skip($message)
557 {
558 throw new \PHPUnit_Framework_SkippedTestError($message);
559 }
560 }