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