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