[BUGFIX] Notice free FormEngine testing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaRecordTitleTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaRecordTitle;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class TcaRecordTitleTest extends UnitTestCase
27 {
28 /**
29 * @var string
30 */
31 protected $timeZone;
32
33 public function setUp()
34 {
35 $this->timeZone = date_default_timezone_get();
36 date_default_timezone_set('UTC');
37 }
38
39 protected function tearDown()
40 {
41 date_default_timezone_set($this->timeZone);
42 parent::tearDown();
43 }
44
45 /**
46 * @test
47 */
48 public function addDataThrowsExceptionWithMissingLabel()
49 {
50 $input = [
51 'tableName' => 'aTable',
52 'databaseRew' => [],
53 'processedTca' => [
54 'ctrl' => [],
55 ],
56 ];
57 $this->expectException(\UnexpectedValueException::class);
58 $this->expectExceptionCode(1443706103);
59 (new TcaRecordTitle)->addData($input);
60 }
61
62 /**
63 * @test
64 */
65 public function addDataReturnsRecordTitleForLabelUserFunction()
66 {
67 $input = [
68 'tableName' => 'aTable',
69 'databaseRow' => [],
70 'isInlineChild' => false,
71 'processedTca' => [
72 'ctrl' => [
73 'label' => 'uid',
74 'label_userFunc' => function (&$parameters) {
75 $parameters['title'] = 'Test';
76 }
77 ],
78 'columns' => [],
79 ],
80 ];
81
82 $expected = $input;
83 $expected['recordTitle'] = 'Test';
84
85 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
86 }
87
88 /**
89 * @test
90 */
91 public function addDataReturnsRecordTitleForFormattedLabelUserFunction()
92 {
93 $input = [
94 'tableName' => 'aTable',
95 'databaseRow' => [
96 'uid' => 5,
97 ],
98 'isInlineChild' => true,
99 'isOnSymmetricSide' => false,
100 'inlineParentConfig' => [
101 'foreign_label' => 'aField',
102 ],
103 'processedTca' => [
104 'ctrl' => [
105 'label' => 'uid',
106 'formattedLabel_userFunc' => function (&$parameters) {
107 $parameters['title'] = 'Test';
108 }
109 ],
110 'columns' => [],
111 ],
112 ];
113
114 $expected = $input;
115 $expected['recordTitle'] = 'Test';
116
117 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
118 }
119
120 /**
121 * @test
122 */
123 public function addDataReturnsRecordTitleForInlineChildWithForeignLabel()
124 {
125 $input = [
126 'tableName' => 'aTable',
127 'databaseRow' => [
128 'aField' => 'aValue',
129 ],
130 'processedTca' => [
131 'ctrl' => [
132 'label' => 'foo',
133 'label_userFunc' => function (&$parameters) {
134 $parameters['title'] = 'Value that MUST NOT be used, otherwise the code is broken.';
135 }
136 ],
137 'columns' => [
138 'aField' => [
139 'config' => [
140 'type' => 'input',
141 ],
142 ],
143 ],
144 ],
145 'isInlineChild' => true,
146 'isOnSymmetricSide' => false,
147 'inlineParentConfig' => [
148 'foreign_label' => 'aField',
149 ],
150 ];
151 $expected = $input;
152 $expected['recordTitle'] = 'aValue';
153 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
154 }
155
156 /**
157 * @test
158 */
159 public function addDataOverridesRecordTitleWithFormattedLabelUserFuncForInlineChildWithForeignLabel()
160 {
161 $input = [
162 'tableName' => 'aTable',
163 'databaseRow' => [
164 'uid' => 5,
165 'aField' => 'aValue',
166 ],
167 'processedTca' => [
168 'ctrl' => [
169 'label' => 'foo',
170 'formattedLabel_userFunc' => function (&$parameters) {
171 $parameters['title'] = 'aFormattedLabel';
172 },
173 ],
174 'columns' => [
175 'aField' => [
176 'config' => [
177 'type' => 'input',
178 ],
179 ],
180 ],
181 ],
182 'isInlineChild' => true,
183 'isOnSymmetricSide' => false,
184 'inlineParentConfig' => [
185 'foreign_label' => 'aField',
186 ],
187 ];
188 $expected = $input;
189 $expected['recordTitle'] = 'aFormattedLabel';
190 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
191 }
192
193 /**
194 * @test
195 */
196 public function addDataReturnsRecordTitleForInlineChildWithSymmetricLabel()
197 {
198 $input = [
199 'tableName' => 'aTable',
200 'databaseRow' => [
201 'aField' => 'aValue',
202 ],
203 'processedTca' => [
204 'ctrl' => [
205 'label' => 'foo',
206 ],
207 'columns' => [
208 'aField' => [
209 'config' => [
210 'type' => 'input',
211 ],
212 ],
213 ],
214 ],
215 'isInlineChild' => true,
216 'inlineParentConfig' => [
217 'symmetric_label' => 'aField',
218 ],
219 'isOnSymmetricSide' => true,
220 ];
221 $expected = $input;
222 $expected['recordTitle'] = 'aValue';
223 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
224 }
225
226 /**
227 * @test
228 */
229 public function addDataReturnsRecordTitleForUid()
230 {
231 $input = [
232 'tableName' => 'aTable',
233 'isInlineChild' => false,
234 'databaseRow' => [
235 'uid' => 'NEW56017ee37d10e587251374',
236 ],
237 'processedTca' => [
238 'ctrl' => [
239 'label' => 'uid'
240 ],
241 'columns' => [],
242 ]
243 ];
244
245 /** @var LanguageService|ObjectProphecy $languageService */
246 $languageService = $this->prophesize(LanguageService::class);
247 $GLOBALS['LANG'] = $languageService->reveal();
248 $languageService->sL(Argument::cetera())->willReturnArgument(0);
249
250 $expected = $input;
251 $expected['recordTitle'] = 'NEW56017ee37d10e587251374';
252 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
253 }
254
255 /**
256 * Data provider for addDataReturnsRecordTitleForInputType
257 * Each data set is an array with the following elements:
258 * - TCA field ['config'] section
259 * - Database value for field
260 * - expected title to be generated
261 *
262 * @returns array
263 */
264 public function addDataReturnsRecordTitleForInputTypeDataProvider()
265 {
266 return [
267 'new record' => [
268 [
269 'type' => 'input',
270 ],
271 '',
272 '',
273 ],
274 'plain text input' => [
275 [
276 'type' => 'input',
277 ],
278 'aValue',
279 'aValue',
280 ],
281 'date input' => [
282 [
283 'type' => 'input',
284 'eval' => 'date'
285 ],
286 '978307261',
287 '01-01-01 (-7 days)',
288 ],
289 'date input (dbType: date)' => [
290 [
291 'type' => 'input',
292 'eval' => 'date',
293 'dbType' => 'date'
294 ],
295 '2001-01-01',
296 '01-01-01 (-7 days)',
297 ],
298 'date input (disableAgeDisplay: TRUE)' => [
299 [
300 'type' => 'input',
301 'eval' => 'date',
302 'disableAgeDisplay' => true
303 ],
304 '978307261',
305 '01-01-01',
306 ],
307 'time input' => [
308 [
309 'type' => 'input',
310 'eval' => 'time',
311 ],
312 '44100',
313 '12:15',
314 ],
315 'time input (dbType: time)' => [
316 [
317 'type' => 'input',
318 'eval' => 'time',
319 'dbType' => 'time'
320 ],
321 '23:59:00',
322 '23:59',
323 ],
324 'timesec input' => [
325 [
326 'type' => 'input',
327 'eval' => 'timesec',
328 ],
329 '44130',
330 '12:15:30',
331 ],
332 'timesec input (dbType: time)' => [
333 [
334 'type' => 'input',
335 'eval' => 'timesec',
336 'dbType' => 'time'
337 ],
338 '23:59:59',
339 '23:59:59',
340 ],
341 'datetime input' => [
342 [
343 'type' => 'input',
344 'eval' => 'datetime',
345 'dbType' => 'date'
346 ],
347 '978307261',
348 '01-01-01 00:01',
349 ],
350 'datetime input (dbType: datetime)' => [
351 [
352 'type' => 'input',
353 'eval' => 'datetime',
354 'dbType' => 'datetime'
355 ],
356 '2014-12-31 23:59:59',
357 '31-12-14 23:59',
358 ],
359 ];
360 }
361
362 /**
363 * @test
364 * @dataProvider addDataReturnsRecordTitleForInputTypeDataProvider
365 *
366 * @param array $fieldConfig
367 * @param string $fieldValue
368 * @param string $expectedTitle
369 */
370 public function addDataReturnsRecordTitleForInputType($fieldConfig, $fieldValue, $expectedTitle)
371 {
372 $input = [
373 'tableName' => 'aTable',
374 'isInlineChild' => false,
375 'databaseRow' => [
376 'uid' => '1',
377 'aField' => $fieldValue,
378 ],
379 'processedTca' => [
380 'ctrl' => [
381 'label' => 'aField'
382 ],
383 'columns' => [
384 'aField' => [
385 'config' => $fieldConfig,
386 ]
387 ],
388 ]
389 ];
390
391 /** @var LanguageService|ObjectProphecy $languageService */
392 $languageService = $this->prophesize(LanguageService::class);
393 $GLOBALS['LANG'] = $languageService->reveal();
394 $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
395 ->willReturn(' min| hrs| days| yrs| min| hour| day| year');
396 $languageService->sL(Argument::cetera())->willReturnArgument(0);
397 $GLOBALS['EXEC_TIME'] = 978912061;
398
399 $expected = $input;
400 $expected['recordTitle'] = $expectedTitle;
401 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
402 }
403
404 /**
405 * @test
406 */
407 public function addDataReturnsRecordTitleWithAlternativeLabel()
408 {
409 $input = [
410 'tableName' => 'aTable',
411 'isInlineChild' => false,
412 'databaseRow' => [
413 'uid' => '1',
414 'aField' => '',
415 'anotherField' => 'anotherValue',
416 ],
417 'processedTca' => [
418 'ctrl' => [
419 'label' => 'aField',
420 'label_alt' => 'anotherField',
421 ],
422 'columns' => [
423 'aField' => [
424 'config' => [
425 'type' => 'input'
426 ]
427 ],
428 'anotherField' => [
429 'config' => [
430 'type' => 'input'
431 ]
432 ]
433 ],
434 ]
435 ];
436
437 $expected = $input;
438 $expected['recordTitle'] = 'anotherValue';
439 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
440 }
441
442 /**
443 * @test
444 */
445 public function addDataReturnsRecordTitleWithMultipleAlternativeLabels()
446 {
447 $input = [
448 'tableName' => 'aTable',
449 'isInlineChild' => false,
450 'databaseRow' => [
451 'uid' => '1',
452 'aField' => '',
453 'anotherField' => '',
454 'additionalField' => 'additionalValue'
455 ],
456 'processedTca' => [
457 'ctrl' => [
458 'label' => 'aField',
459 'label_alt' => 'anotherField,additionalField',
460 ],
461 'columns' => [
462 'aField' => [
463 'config' => [
464 'type' => 'input'
465 ]
466 ],
467 'anotherField' => [
468 'config' => [
469 'type' => 'input'
470 ]
471 ],
472 'additionalField' => [
473 'config' => [
474 'type' => 'input'
475 ]
476 ],
477 ],
478 ]
479 ];
480
481 $expected = $input;
482 $expected['recordTitle'] = 'additionalValue';
483 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
484 }
485
486 /**
487 * @test
488 */
489 public function addDataReturnsRecordTitleWithForcedAlternativeLabel()
490 {
491 $input = [
492 'tableName' => 'aTable',
493 'isInlineChild' => false,
494 'databaseRow' => [
495 'uid' => '1',
496 'aField' => 'aField',
497 'anotherField' => 'anotherField'
498 ],
499 'processedTca' => [
500 'ctrl' => [
501 'label' => 'aField',
502 'label_alt' => 'anotherField',
503 'label_alt_force' => true,
504 ],
505 'columns' => [
506 'aField' => [
507 'config' => [
508 'type' => 'input'
509 ]
510 ],
511 'anotherField' => [
512 'config' => [
513 'type' => 'input'
514 ]
515 ],
516 ],
517 ]
518 ];
519
520 $expected = $input;
521 $expected['recordTitle'] = 'aField, anotherField';
522 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
523 }
524
525 /**
526 * @test
527 */
528 public function addDataReturnsRecordTitleWithMultipleForcedAlternativeLabels()
529 {
530 $input = [
531 'tableName' => 'aTable',
532 'isInlineChild' => false,
533 'databaseRow' => [
534 'uid' => '1',
535 'aField' => 'aField',
536 'anotherField' => 'anotherField',
537 'additionalField' => 'additionalValue'
538 ],
539 'processedTca' => [
540 'ctrl' => [
541 'label' => 'aField',
542 'label_alt' => 'anotherField,additionalField',
543 'label_alt_force' => true,
544 ],
545 'columns' => [
546 'aField' => [
547 'config' => [
548 'type' => 'input'
549 ]
550 ],
551 'anotherField' => [
552 'config' => [
553 'type' => 'input'
554 ]
555 ],
556 'additionalField' => [
557 'config' => [
558 'type' => 'input'
559 ]
560 ],
561 ],
562 ]
563 ];
564
565 $expected = $input;
566 $expected['recordTitle'] = 'aField, anotherField, additionalValue';
567 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
568 }
569
570 /**
571 * @test
572 */
573 public function addDataReturnsRecordTitleIgnoresEmptyAlternativeLabels()
574 {
575 $input = [
576 'tableName' => 'aTable',
577 'isInlineChild' => false,
578 'databaseRow' => [
579 'uid' => '1',
580 'aField' => 'aField',
581 'anotherField' => '',
582 'additionalField' => 'additionalValue'
583 ],
584 'processedTca' => [
585 'ctrl' => [
586 'label' => 'aField',
587 'label_alt' => 'anotherField,additionalField',
588 'label_alt_force' => true,
589 ],
590 'columns' => [
591 'aField' => [
592 'config' => [
593 'type' => 'input'
594 ]
595 ],
596 'anotherField' => [
597 'config' => [
598 'type' => 'input'
599 ]
600 ],
601 'additionalField' => [
602 'config' => [
603 'type' => 'input'
604 ]
605 ],
606 ],
607 ]
608 ];
609
610 $expected = $input;
611 $expected['recordTitle'] = 'aField, additionalValue';
612 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
613 }
614
615 /**
616 * @test
617 */
618 public function addDataReturnsRecordTitleForRadioType()
619 {
620 $input = [
621 'tableName' => 'aTable',
622 'isInlineChild' => false,
623 'databaseRow' => [
624 'uid' => '1',
625 'aField' => '2',
626 ],
627 'processedTca' => [
628 'ctrl' => [
629 'label' => 'aField'
630 ],
631 'columns' => [
632 'aField' => [
633 'config' => [
634 'type' => 'radio',
635 'items' => [
636 ['foo', 1],
637 ['bar', 2],
638 ['baz', 3],
639 ]
640 ]
641 ]
642 ],
643 ]
644 ];
645
646 $expected = $input;
647 $expected['recordTitle'] = 'bar';
648 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
649 }
650
651 /**
652 * @test
653 */
654 public function addDataReturnsRecordTitleForInlineType()
655 {
656 $input = [
657 'tableName' => 'aTable',
658 'isInlineChild' => false,
659 'databaseRow' => [
660 'uid' => '1',
661 'aField' => '2',
662 ],
663 'processedTca' => [
664 'ctrl' => [
665 'label' => 'aField'
666 ],
667 'columns' => [
668 'aField' => [
669 'config' => [
670 'type' => 'inline'
671 ],
672 'children' => [
673 [
674 'recordTitle' => 'foo',
675 'vanillaUid' => 2
676 ]
677 ]
678 ]
679 ],
680 ]
681 ];
682
683 $expected = $input;
684 $expected['recordTitle'] = 'foo';
685 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
686 }
687
688 /**
689 * Data provider for addDataReturnsRecordTitleForGroupType
690 * Each data set is an array with the following elements:
691 * - TCA field configuration (merged with base config)
692 * - Database value for field
693 * - expected title to be generated
694 *
695 * @returns array
696 */
697 public function addDataReturnsRecordTitleForGroupTypeDataProvider()
698 {
699 return [
700 'new record' => [
701 [
702 'internal_type' => 'db',
703 ],
704 [],
705 ''
706 ],
707 'internal_type: file' => [
708 [
709 'internal_type' => 'file',
710 ],
711 [
712 [
713 'uidOrPath' => 'somePath/aFile.jpg',
714 ],
715 [
716 'uidOrPath' => 'someOtherPath/anotherFile.png',
717 ],
718 ],
719 'somePath/aFile.jpg, someOtherPath/anotherFile.png',
720 ],
721 'internal_type: db, single table, single record' => [
722 [
723 'internal_type' => 'db',
724 'allowed' => 'aTable'
725 ],
726 [
727 [
728 'title' => 'aValue',
729 ],
730 ],
731 'aValue',
732 ],
733 'internal_type: db, single table, multiple records' => [
734 [
735 'internal_type' => 'db',
736 'allowed' => 'aTable'
737 ],
738 [
739 [
740 'title' => 'aValue',
741 ],
742 [
743 'title' => 'anotherValue',
744 ],
745 ],
746 'aValue, anotherValue',
747 ],
748 'internal_type: db, multiple tables, single record' => [
749 [
750 'internal_type' => 'db',
751 'allowed' => 'aTable,anotherTable'
752 ],
753 [
754 [
755 'uid' => 1,
756 'table' => 'anotherTable',
757 'title' => 'anotherValue',
758 ],
759 ],
760 'anotherValue',
761 ],
762 'internal_type: db, multiple tables, multiple records' => [
763 [
764 'internal_type' => 'db',
765 'allowed' => 'aTable,anotherTable'
766 ],
767 [
768 [
769 'uid' => 1,
770 'table' => 'aTable',
771 'title' => 'aValue',
772 ],
773 [
774 'uid' => 2,
775 'table' => 'anotherTable',
776 'title' => 'anotherValue',
777 ],
778 ],
779 'aValue, anotherValue',
780 ],
781 ];
782 }
783
784 /**
785 * @test
786 * @dataProvider addDataReturnsRecordTitleForGroupTypeDataProvider
787 *
788 * @param array $fieldConfig
789 * @param string $fieldValue
790 * @param string $expectedTitle
791 */
792 public function addDataReturnsRecordTitleForGroupType($fieldConfig, $fieldValue, $expectedTitle)
793 {
794 $input = [
795 'tableName' => 'aTable',
796 'isInlineChild' => false,
797 'databaseRow' => [
798 'uid' => '1',
799 'aField' => $fieldValue,
800 ],
801 'processedTca' => [
802 'ctrl' => [
803 'label' => 'aField'
804 ],
805 'columns' => [
806 'aField' => [
807 'config' => array_merge(
808 [
809 'type' => 'group',
810 ],
811 $fieldConfig
812 ),
813 ]
814 ],
815 ]
816 ];
817
818 /** @var LanguageService|ObjectProphecy $languageService */
819 $languageService = $this->prophesize(LanguageService::class);
820 $GLOBALS['LANG'] = $languageService->reveal();
821 $languageService->sL(Argument::cetera())->willReturnArgument(0);
822
823 $expected = $input;
824 $expected['recordTitle'] = $expectedTitle;
825 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
826 }
827
828 /**
829 * @test
830 */
831 public function addDataReturnsRecordTitleForGroupTypeWithInternalTypeDb()
832 {
833 $input = [
834 'tableName' => 'aTable',
835 'isInlineChild' => false,
836 'databaseRow' => [
837 'uid' => '1',
838 'aField' => [
839 [
840 'uid' => 1,
841 'table' => 'aTable',
842 'title' => 'aValue',
843 ],
844 [
845 'uid' => 2,
846 'table' => 'anotherTable',
847 'title' => 'anotherValue',
848 ],
849 ],
850 ],
851 'processedTca' => [
852 'ctrl' => [
853 'label' => 'aField'
854 ],
855 'columns' => [
856 'aField' => [
857 'config' => [
858 'type' => 'group',
859 'internal_type' => 'db',
860 'allowed' => 'aTable,anotherTable',
861 ]
862 ]
863 ],
864 ]
865 ];
866
867 $expected = $input;
868 $expected['recordTitle'] = 'aValue, anotherValue';
869 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
870 }
871
872 /**
873 * @test
874 */
875 public function addDataReturnsRecordTitleForSingleCheckboxType()
876 {
877 $input = [
878 'tableName' => 'aTable',
879 'isInlineChild' => false,
880 'databaseRow' => [
881 'aField' => 1,
882 ],
883 'processedTca' => [
884 'ctrl' => [
885 'label' => 'aField'
886 ],
887 'columns' => [
888 'aField' => [
889 'config' => [
890 'type' => 'check',
891 ]
892 ]
893 ],
894 ]
895 ];
896
897 /** @var LanguageService|ObjectProphecy $languageService */
898 $languageService = $this->prophesize(LanguageService::class);
899 $GLOBALS['LANG'] = $languageService->reveal();
900 $languageService->sL(Argument::cetera())->willReturnArgument(0)->shouldBeCalled();
901
902 $expected = $input;
903 $expected['recordTitle'] = 'LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:yes';
904 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
905 }
906
907 /**
908 * @test
909 */
910 public function addDataReturnsRecordTitleForArrayCheckboxType()
911 {
912 $input = [
913 'tableName' => 'aTable',
914 'isInlineChild' => false,
915 'databaseRow' => [
916 'aField' => '5'
917 ],
918 'processedTca' => [
919 'ctrl' => [
920 'label' => 'aField'
921 ],
922 'columns' => [
923 'aField' => [
924 'config' => [
925 'type' => 'check',
926 'items' => [
927 ['foo', ''],
928 ['bar', ''],
929 ['baz', ''],
930 ]
931 ]
932 ]
933 ],
934 ]
935 ];
936
937 /** @var LanguageService|ObjectProphecy $languageService */
938 $languageService = $this->prophesize(LanguageService::class);
939 $GLOBALS['LANG'] = $languageService->reveal();
940 $languageService->sL(Argument::cetera())->willReturnArgument(0);
941
942 $expected = $input;
943 $expected['recordTitle'] = 'foo, baz';
944 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
945 }
946
947 /**
948 * @test
949 */
950 public function addDataReturnsEmptyRecordTitleForFlexType()
951 {
952 $input = [
953 'tableName' => 'aTable',
954 'isInlineChild' => false,
955 'databaseRow' => [
956 'aField' => [
957 'data' => [
958 'sDEF' => [
959 'lDEF' => [
960 'aFlexField' => [
961 'vDEF' => 'aFlexValue',
962 ]
963 ]
964 ]
965 ]
966 ]
967 ],
968 'processedTca' => [
969 'ctrl' => [
970 'label' => 'aField'
971 ],
972 'columns' => [
973 'aField' => [
974 'config' => [
975 'type' => 'flex',
976 'ds' => [
977 'sheets' => [
978 'sDEF' => [
979 'ROOT' => [
980 'type' => 'array',
981 'el' => [
982 'aFlexField' => [
983 'label' => 'Some input field',
984 'config' => [
985 'type' => 'input',
986 ],
987 ],
988 ],
989 ],
990 ],
991 ],
992 ]
993
994 ]
995 ]
996 ],
997 ]
998 ];
999
1000 $expected = $input;
1001 $expected['recordTitle'] = '';
1002 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
1003 }
1004
1005 /**
1006 * @test
1007 */
1008 public function addDataReturnsRecordTitleForSelectType()
1009 {
1010 $input = [
1011 'tableName' => 'aTable',
1012 'isInlineChild' => false,
1013 'databaseRow' => [
1014 'aField' => [
1015 '1',
1016 '2'
1017 ]
1018 ],
1019 'processedTca' => [
1020 'ctrl' => [
1021 'label' => 'aField'
1022 ],
1023 'columns' => [
1024 'aField' => [
1025 'config' => [
1026 'type' => 'select',
1027 'items' => [
1028 ['foo', 1, null, null],
1029 ['bar', 2, null, null],
1030 ['baz', 4, null, null],
1031 ]
1032 ]
1033 ]
1034 ],
1035 ]
1036 ];
1037
1038 $expected = $input;
1039 $expected['recordTitle'] = 'foo, bar';
1040 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
1041 }
1042
1043 /**
1044 * @test
1045 */
1046 public function addDataReturnsStrippedAndTrimmedValueForTextType()
1047 {
1048 $input = [
1049 'tableName' => 'aTable',
1050 'isInlineChild' => false,
1051 'databaseRow' => [
1052 'aField' => '<p> text </p>',
1053 ],
1054 'processedTca' => [
1055 'ctrl' => [
1056 'label' => 'aField',
1057 ],
1058 'columns' => [
1059 'aField' => [
1060 'config' => [
1061 'type' => 'text',
1062 ],
1063 ],
1064 ],
1065 ],
1066 ];
1067
1068 $expected = $input;
1069 $expected['recordTitle'] = 'text';
1070 $this->assertSame($expected, (new TcaRecordTitle)->addData($input));
1071 }
1072 }