78be831d4d1661234c2ad2156d0e316c6ba3bd45
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaFlexTest.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\Cache\CacheManager;
21 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
22 use TYPO3\CMS\Core\Tests\UnitTestCase;
23 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlex;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Lang\LanguageService;
26
27 /**
28 * Test case
29 */
30 class TcaFlexTest extends UnitTestCase {
31
32 /**
33 * @var TcaFlex
34 */
35 protected $subject;
36
37 /**
38 * @var BackendUserAuthentication|ObjectProphecy
39 */
40 protected $backendUserProphecy;
41
42 /**
43 * @var array A backup of registered singleton instances
44 */
45 protected $singletonInstances = array();
46
47 public function setUp() {
48 $this->singletonInstances = GeneralUtility::getSingletonInstances();
49
50 // Suppress cache foo in xml helpers of GeneralUtility
51 /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */
52 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
53 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
54 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
55 $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
56
57 /** @var BackendUserAuthentication|ObjectProphecy backendUserProphecy */
58 $this->backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
59 $GLOBALS['BE_USER'] = $this->backendUserProphecy->reveal();
60 $GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
61
62 // Some tests call FormDataCompiler for sub elements. Those tests have functional test characteristics.
63 // This is ok for the time being, but this settings takes care only parts of the compiler are called
64 // to have less dependencies.
65 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [];
66
67 $this->subject = new TcaFlex();
68 }
69
70 protected function tearDown() {
71 GeneralUtility::purgeInstances();
72 GeneralUtility::resetSingletonInstances($this->singletonInstances);
73 parent::tearDown();
74 }
75
76 /**
77 * @test
78 */
79 public function addDataThrowsExceptionIfBothSheetsAndRootDefined() {
80 $input = [
81 'systemLanguageRows' => [],
82 'databaseRow' => [
83 'aField' => [
84 'data' => [],
85 'meta' => [],
86 ],
87 ],
88 'processedTca' => [
89 'columns' => [
90 'aField' => [
91 'config' => [
92 'type' => 'flex',
93 'ds' => [
94 'default' => '
95 <T3DataStructure>
96 <ROOT></ROOT>
97 <sheets></sheets>
98 </T3DataStructure>
99 ',
100 ],
101 ],
102 ],
103 ],
104 ],
105 ];
106
107 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1440676540);
108
109 $this->subject->addData($input);
110 }
111
112 /**
113 * @test
114 */
115 public function addDataSetsParsedDataStructureArray() {
116 $input = [
117 'systemLanguageRows' => [],
118 'databaseRow' => [
119 'aField' => [
120 'data' => [],
121 'meta' => [],
122 ],
123 ],
124 'processedTca' => [
125 'columns' => [
126 'aField' => [
127 'config' => [
128 'type' => 'flex',
129 'ds' => [
130 'default' => '
131 <T3DataStructure>
132 <ROOT>
133 <type>array</type>
134 <el>
135 <aFlexField>
136 <TCEforms>
137 <label>aFlexFieldLabel</label>
138 <config>
139 <type>input</type>
140 </config>
141 </TCEforms>
142 </aFlexField>
143 </el>
144 </ROOT>
145 </T3DataStructure>
146 ',
147 ],
148 ],
149 ],
150 ],
151 ],
152 ];
153
154 $expected = $input;
155 $expected['processedTca']['columns']['aField']['config']['ds'] = [
156 'sheets' => [
157 'sDEF' => [
158 'ROOT' => [
159 'type' => 'array',
160 'el' => [
161 'aFlexField' => [
162 'label' => 'aFlexFieldLabel',
163 'config' => [
164 'type' => 'input',
165 ],
166 ],
167 ],
168 ],
169 ],
170 ],
171 'meta' => [
172 'availableLanguageCodes' => [],
173 'langDisable' => FALSE,
174 'langChildren' => FALSE,
175 'languagesOnSheetLevel' => [],
176 'languagesOnElement' => [
177 0 => 'DEF',
178 ],
179 ],
180 ];
181
182 $this->assertEquals($expected, $this->subject->addData($input));
183 }
184
185 /**
186 * @test
187 */
188 public function addDataSetsParsedDataStructureArrayWithSheets() {
189 $input = [
190 'systemLanguageRows' => [],
191 'databaseRow' => [
192 'aField' => [
193 'data' => [],
194 'meta' => [],
195 ],
196 ],
197 'processedTca' => [
198 'columns' => [
199 'aField' => [
200 'config' => [
201 'type' => 'flex',
202 'ds' => [
203 'default' => '
204 <T3DataStructure>
205 <sheets>
206 <sDEF>
207 <ROOT>
208 <TCEforms>
209 <sheetTitle>aTitle</sheetTitle>
210 </TCEforms>
211 <type>array</type>
212 <el>
213 <aFlexField>
214 <TCEforms>
215 <label>aFlexFieldLabel</label>
216 <config>
217 <type>input</type>
218 </config>
219 </TCEforms>
220 </aFlexField>
221 </el>
222 </ROOT>
223 </sDEF>
224 </sheets>
225 </T3DataStructure>
226 ',
227 ],
228 ],
229 ],
230 ],
231 ],
232 ];
233
234 $expected = $input;
235 $expected['processedTca']['columns']['aField']['config']['ds'] = [
236 'sheets' => [
237 'sDEF' => [
238 'ROOT' => [
239 'type' => 'array',
240 'el' => [
241 'aFlexField' => [
242 'label' => 'aFlexFieldLabel',
243 'config' => [
244 'type' => 'input',
245 ],
246 ],
247 ],
248 'TCEforms' => [
249 'sheetTitle' => 'aTitle',
250 ],
251 ],
252 ],
253 ],
254 'meta' => [
255 'availableLanguageCodes' => [],
256 'langDisable' => FALSE,
257 'langChildren' => FALSE,
258 'languagesOnSheetLevel' => [],
259 'languagesOnElement' => [
260 0 => 'DEF',
261 ],
262 ],
263 ];
264
265 $this->assertEquals($expected, $this->subject->addData($input));
266 }
267
268 /**
269 * @test
270 */
271 public function addDataThrowsExceptionIfDataStructureCanNotBeParsed() {
272 $input = [
273 'systemLanguageRows' => [],
274 'databaseRow' => [],
275 'processedTca' => [
276 'columns' => [
277 'aField' => [
278 'config' => [
279 'type' => 'flex',
280 'ds' => ''
281 ],
282 ],
283 ],
284 ],
285 ];
286
287 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1440506893);
288
289 $this->subject->addData($input);
290 }
291
292 /**
293 * @test
294 */
295 public function addDataInitializesDatabaseRowValueIfNoDataStringIsGiven() {
296 $input = [
297 'databaseRow' => [],
298 'systemLanguageRows' => [],
299 'processedTca' => [
300 'columns' => [
301 'aField' => [
302 'config' => [
303 'type' => 'flex',
304 'ds' => [
305 'default' => '
306 <T3DataStructure>
307 <ROOT></ROOT>
308 </T3DataStructure>
309 ',
310 ],
311 ],
312 ],
313 ],
314 ],
315 ];
316
317 $expected = $input;
318 $expected['processedTca']['columns']['aField']['config']['ds'] = [
319 'ROOT' => '',
320 'meta' => [
321 'availableLanguageCodes' => [],
322 'langDisable' => FALSE,
323 'langChildren' => FALSE,
324 'languagesOnSheetLevel' => [],
325 'languagesOnElement' => [
326 0 => 'DEF',
327 ]
328 ],
329 ];
330 $expected['databaseRow']['aField'] = [
331 'data' => [],
332 'meta' => []
333 ];
334
335 $this->assertEquals($expected, $this->subject->addData($input));
336 }
337
338 /**
339 * @test
340 */
341 public function addDataOverwritesDataStructureLangDisableIfSetViaPageTsConfig() {
342 $input = [
343 'tableName' => 'aTable',
344 'databaseRow' => [
345 'aField' => [
346 'data' => [],
347 'meta' => [],
348 ],
349 'pointerField' => 'aFlex',
350 ],
351 'systemLanguageRows' => [],
352 'processedTca' => [
353 'columns' => [
354 'aField' => [
355 'config' => [
356 'type' => 'flex',
357 'ds_pointerField' => 'pointerField',
358 'ds' => [
359 'aFlex' => '
360 <T3DataStructure>
361 <ROOT></ROOT>
362 </T3DataStructure>
363 ',
364 ],
365 ],
366 ],
367 ],
368 ],
369 'pageTsConfigMerged' => [
370 'TCEFORM.' => [
371 'aTable.' => [
372 'aField.' => [
373 'aFlex.' => [
374 'langDisable' => 1,
375 ],
376 ],
377 ],
378 ],
379 ],
380 ];
381
382 $expected = $input;
383 $expected['processedTca']['columns']['aField']['config']['ds'] = [
384 'ROOT' => '',
385 'meta' => [
386 'availableLanguageCodes' => [],
387 'langDisable' => TRUE,
388 'langChildren' => FALSE,
389 'languagesOnSheetLevel' => [],
390 'languagesOnElement' => [
391 0 => 'DEF',
392 ]
393 ],
394 ];
395
396 $this->assertEquals($expected, $this->subject->addData($input));
397 }
398
399 /**
400 * @test
401 */
402 public function addDataOverwritesDataStructureLangChildrenIfSetViaPageTsConfig() {
403 $input = [
404 'tableName' => 'aTable',
405 'databaseRow' => [
406 'aField' => [
407 'data' => [],
408 'meta' => [],
409 ],
410 'pointerField' => 'aFlex',
411 ],
412 'systemLanguageRows' => [],
413 'processedTca' => [
414 'columns' => [
415 'aField' => [
416 'config' => [
417 'type' => 'flex',
418 'ds_pointerField' => 'pointerField',
419 'ds' => [
420 'aFlex' => '
421 <T3DataStructure>
422 <ROOT></ROOT>
423 </T3DataStructure>
424 ',
425 ],
426 ],
427 ],
428 ],
429 ],
430 'pageTsConfigMerged' => [
431 'TCEFORM.' => [
432 'aTable.' => [
433 'aField.' => [
434 'aFlex.' => [
435 'langChildren' => FALSE,
436 ],
437 ],
438 ],
439 ],
440 ],
441 ];
442
443 $expected = $input;
444 $expected['processedTca']['columns']['aField']['config']['ds'] = [
445 'ROOT' => '',
446 'meta' => [
447 'availableLanguageCodes' => [],
448 'langDisable' => FALSE,
449 'langChildren' => FALSE,
450 'languagesOnSheetLevel' => [],
451 'languagesOnElement' => [
452 0 => 'DEF',
453 ]
454 ],
455 ];
456
457 $this->assertEquals($expected, $this->subject->addData($input));
458 }
459
460 /**
461 * @test
462 */
463 public function addDataRemovesSheetIfDisabledByPageTsConfig() {
464 $input = [
465 'tableName' => 'aTable',
466 'databaseRow' => [
467 'aField' => [
468 'data' => [],
469 'meta' => [],
470 ],
471 'pointerField' => 'aFlex',
472 ],
473 'systemLanguageRows' => [],
474 'processedTca' => [
475 'columns' => [
476 'aField' => [
477 'config' => [
478 'type' => 'flex',
479 'ds_pointerField' => 'pointerField',
480 'ds' => [
481 'aFlex' => '
482 <T3DataStructure>
483 <sheets>
484 <aSheet>
485 <ROOT>
486 <type>array</type>
487 <el>
488 <aFlexField>
489 <TCEforms>
490 <label>aFlexFieldLabel</label>
491 <config>
492 <type>input</type>
493 </config>
494 </TCEforms>
495 </aFlexField>
496 </el>
497 </ROOT>
498 </aSheet>
499 </sheets>
500 </T3DataStructure>
501 ',
502 ],
503 ],
504 ],
505 ],
506 ],
507 'pageTsConfigMerged' => [
508 'TCEFORM.' => [
509 'aTable.' => [
510 'aField.' => [
511 'aFlex.' => [
512 'aSheet.' => [
513 'disabled' => 1,
514 ],
515 ],
516 ],
517 ],
518 ],
519 ],
520 ];
521
522 $expected = $input;
523 $expected['processedTca']['columns']['aField']['config']['ds'] = [
524 'meta' => [
525 'availableLanguageCodes' => [],
526 'langDisable' => FALSE,
527 'langChildren' => FALSE,
528 'languagesOnSheetLevel' => [],
529 'languagesOnElement' => [
530 0 => 'DEF',
531 ]
532 ],
533 'sheets' => [],
534 ];
535
536 $this->assertEquals($expected, $this->subject->addData($input));
537 }
538
539 /**
540 * @test
541 */
542 public function addDataRemovesSingleSheetIfDisabledByPageTsConfig() {
543 $input = [
544 'tableName' => 'aTable',
545 'databaseRow' => [
546 'aField' => [
547 'data' => [],
548 'meta' => [],
549 ],
550 'pointerField' => 'aFlex',
551 ],
552 'systemLanguageRows' => [],
553 'processedTca' => [
554 'columns' => [
555 'aField' => [
556 'config' => [
557 'type' => 'flex',
558 'ds_pointerField' => 'pointerField',
559 'ds' => [
560 'aFlex' => '
561 <T3DataStructure>
562 <ROOT>
563 <type>array</type>
564 <el>
565 <aFlexField>
566 <TCEforms>
567 <label>aFlexFieldLabel</label>
568 <config>
569 <type>input</type>
570 </config>
571 </TCEforms>
572 </aFlexField>
573 </el>
574 </ROOT>
575 </T3DataStructure>
576 ',
577 ],
578 ],
579 ],
580 ],
581 ],
582 'pageTsConfigMerged' => [
583 'TCEFORM.' => [
584 'aTable.' => [
585 'aField.' => [
586 'aFlex.' => [
587 'sDEF.' => [
588 'disabled' => 1,
589 ],
590 ],
591 ],
592 ],
593 ],
594 ],
595 ];
596
597 $expected = $input;
598 $expected['processedTca']['columns']['aField']['config']['ds'] = [
599 'meta' => [
600 'availableLanguageCodes' => [],
601 'langDisable' => FALSE,
602 'langChildren' => FALSE,
603 'languagesOnSheetLevel' => [],
604 'languagesOnElement' => [
605 0 => 'DEF',
606 ]
607 ],
608 'sheets' => [],
609 ];
610
611 $this->assertEquals($expected, $this->subject->addData($input));
612 }
613
614 /**
615 * @test
616 */
617 public function addDataSetsSheetTitleFromPageTsConfig() {
618 $input = [
619 'tableName' => 'aTable',
620 'databaseRow' => [
621 'aField' => [
622 'data' => [],
623 'meta' => [],
624 ],
625 'pointerField' => 'aFlex',
626 ],
627 'systemLanguageRows' => [],
628 'processedTca' => [
629 'columns' => [
630 'aField' => [
631 'config' => [
632 'type' => 'flex',
633 'ds_pointerField' => 'pointerField',
634 'ds' => [
635 'aFlex' => '
636 <T3DataStructure>
637 <sheets>
638 <aSheet>
639 <ROOT>
640 <type>array</type>
641 <el>
642 <aFlexField>
643 <TCEforms>
644 <label>aFlexFieldLabel</label>
645 <config>
646 <type>input</type>
647 </config>
648 </TCEforms>
649 </aFlexField>
650 </el>
651 </ROOT>
652 </aSheet>
653 </sheets>
654 </T3DataStructure>
655 ',
656 ],
657 ],
658 ],
659 ],
660 ],
661 'pageTsConfigMerged' => [
662 'TCEFORM.' => [
663 'aTable.' => [
664 'aField.' => [
665 'aFlex.' => [
666 'aSheet.' => [
667 'sheetTitle' => 'aTitle',
668 ],
669 ],
670 ],
671 ],
672 ],
673 ],
674 ];
675
676 $expected = $input;
677 $expected['processedTca']['columns']['aField']['config']['ds'] = [
678 'meta' => [
679 'availableLanguageCodes' => [],
680 'langDisable' => FALSE,
681 'langChildren' => FALSE,
682 'languagesOnSheetLevel' => [],
683 'languagesOnElement' => [
684 0 => 'DEF',
685 ]
686 ],
687 'sheets' => [
688 'aSheet' => [
689 'ROOT' => [
690 'type' => 'array',
691 'el' => [
692 'aFlexField' => [
693 'label' => 'aFlexFieldLabel',
694 'config' => [
695 'type' => 'input',
696 ],
697 ],
698 ],
699 'TCEforms' => [
700 'sheetTitle' => 'aTitle',
701 ],
702 ],
703 ],
704 ],
705 ];
706
707 $this->assertEquals($expected, $this->subject->addData($input));
708 }
709
710 /**
711 * @test
712 */
713 public function addDataSetsSheetDescriptionFromPageTsConfig() {
714 $input = [
715 'tableName' => 'aTable',
716 'databaseRow' => [
717 'aField' => [
718 'data' => [],
719 'meta' => [],
720 ],
721 'pointerField' => 'aFlex',
722 ],
723 'systemLanguageRows' => [],
724 'processedTca' => [
725 'columns' => [
726 'aField' => [
727 'config' => [
728 'type' => 'flex',
729 'ds_pointerField' => 'pointerField',
730 'ds' => [
731 'aFlex' => '
732 <T3DataStructure>
733 <sheets>
734 <aSheet>
735 <ROOT>
736 <type>array</type>
737 <el>
738 <aFlexField>
739 <TCEforms>
740 <label>aFlexFieldLabel</label>
741 <config>
742 <type>input</type>
743 </config>
744 </TCEforms>
745 </aFlexField>
746 </el>
747 </ROOT>
748 </aSheet>
749 </sheets>
750 </T3DataStructure>
751 ',
752 ],
753 ],
754 ],
755 ],
756 ],
757 'pageTsConfigMerged' => [
758 'TCEFORM.' => [
759 'aTable.' => [
760 'aField.' => [
761 'aFlex.' => [
762 'aSheet.' => [
763 'sheetDescription' => 'aDescription',
764 ],
765 ],
766 ],
767 ],
768 ],
769 ],
770 ];
771
772 $expected = $input;
773 $expected['processedTca']['columns']['aField']['config']['ds'] = [
774 'meta' => [
775 'availableLanguageCodes' => [],
776 'langDisable' => FALSE,
777 'langChildren' => FALSE,
778 'languagesOnSheetLevel' => [],
779 'languagesOnElement' => [
780 0 => 'DEF',
781 ]
782 ],
783 'sheets' => [
784 'aSheet' => [
785 'ROOT' => [
786 'type' => 'array',
787 'el' => [
788 'aFlexField' => [
789 'label' => 'aFlexFieldLabel',
790 'config' => [
791 'type' => 'input',
792 ],
793 ],
794 ],
795 'TCEforms' => [
796 'sheetDescription' => 'aDescription',
797 ],
798 ],
799 ],
800 ],
801 ];
802
803 $this->assertEquals($expected, $this->subject->addData($input));
804 }
805
806 /**
807 * @test
808 */
809 public function addDataSetsSheetShortDescriptionFromPageTsConfig() {
810 $input = [
811 'tableName' => 'aTable',
812 'databaseRow' => [
813 'aField' => [
814 'data' => [],
815 'meta' => [],
816 ],
817 'pointerField' => 'aFlex',
818 ],
819 'systemLanguageRows' => [],
820 'processedTca' => [
821 'columns' => [
822 'aField' => [
823 'config' => [
824 'type' => 'flex',
825 'ds_pointerField' => 'pointerField',
826 'ds' => [
827 'aFlex' => '
828 <T3DataStructure>
829 <sheets>
830 <aSheet>
831 <ROOT>
832 <type>array</type>
833 <el>
834 <aFlexField>
835 <TCEforms>
836 <label>aFlexFieldLabel</label>
837 <config>
838 <type>input</type>
839 </config>
840 </TCEforms>
841 </aFlexField>
842 </el>
843 </ROOT>
844 </aSheet>
845 </sheets>
846 </T3DataStructure>
847 ',
848 ],
849 ],
850 ],
851 ],
852 ],
853 'pageTsConfigMerged' => [
854 'TCEFORM.' => [
855 'aTable.' => [
856 'aField.' => [
857 'aFlex.' => [
858 'aSheet.' => [
859 'sheetDescription' => 'sheetShortDescr',
860 ],
861 ],
862 ],
863 ],
864 ],
865 ],
866 ];
867
868 $expected = $input;
869 $expected['processedTca']['columns']['aField']['config']['ds'] = [
870 'meta' => [
871 'availableLanguageCodes' => [],
872 'langDisable' => FALSE,
873 'langChildren' => FALSE,
874 'languagesOnSheetLevel' => [],
875 'languagesOnElement' => [
876 0 => 'DEF',
877 ]
878 ],
879 'sheets' => [
880 'aSheet' => [
881 'ROOT' => [
882 'type' => 'array',
883 'el' => [
884 'aFlexField' => [
885 'label' => 'aFlexFieldLabel',
886 'config' => [
887 'type' => 'input',
888 ],
889 ],
890 ],
891 'TCEforms' => [
892 'sheetDescription' => 'sheetShortDescr',
893 ],
894 ],
895 ],
896 ],
897 ];
898
899 $this->assertEquals($expected, $this->subject->addData($input));
900 }
901
902 /**
903 * @test
904 */
905 public function addDataSetsSheetShortDescriptionForSingleSheetFromPageTsConfig() {
906 $input = [
907 'tableName' => 'aTable',
908 'databaseRow' => [
909 'aField' => [
910 'data' => [],
911 'meta' => [],
912 ],
913 'pointerField' => 'aFlex',
914 ],
915 'systemLanguageRows' => [],
916 'processedTca' => [
917 'columns' => [
918 'aField' => [
919 'config' => [
920 'type' => 'flex',
921 'ds_pointerField' => 'pointerField',
922 'ds' => [
923 'aFlex' => '
924 <T3DataStructure>
925 <ROOT>
926 <type>array</type>
927 <el>
928 <aFlexField>
929 <TCEforms>
930 <label>aFlexFieldLabel</label>
931 <config>
932 <type>input</type>
933 </config>
934 </TCEforms>
935 </aFlexField>
936 </el>
937 </ROOT>
938 </T3DataStructure>
939 ',
940 ],
941 ],
942 ],
943 ],
944 ],
945 'pageTsConfigMerged' => [
946 'TCEFORM.' => [
947 'aTable.' => [
948 'aField.' => [
949 'aFlex.' => [
950 'sDEF.' => [
951 'sheetDescription' => 'sheetShortDescr',
952 ],
953 ],
954 ],
955 ],
956 ],
957 ],
958 ];
959
960 $expected = $input;
961 $expected['processedTca']['columns']['aField']['config']['ds'] = [
962 'meta' => [
963 'availableLanguageCodes' => [],
964 'langDisable' => FALSE,
965 'langChildren' => FALSE,
966 'languagesOnSheetLevel' => [],
967 'languagesOnElement' => [
968 0 => 'DEF',
969 ]
970 ],
971 'sheets' => [
972 'sDEF' => [
973 'ROOT' => [
974 'type' => 'array',
975 'el' => [
976 'aFlexField' => [
977 'label' => 'aFlexFieldLabel',
978 'config' => [
979 'type' => 'input',
980 ],
981 ],
982 ],
983 'TCEforms' => [
984 'sheetDescription' => 'sheetShortDescr',
985 ],
986 ],
987 ],
988 ],
989 ];
990
991 $this->assertEquals($expected, $this->subject->addData($input));
992 }
993
994 /**
995 * @test
996 */
997 public function addDataRemovesExcludeFieldFromDataStructure() {
998 $input = [
999 'tableName' => 'aTable',
1000 'databaseRow' => [
1001 'aField' => [
1002 'data' => [],
1003 'meta' => [],
1004 ],
1005 'pointerField' => 'aFlex',
1006 ],
1007 'systemLanguageRows' => [],
1008 'processedTca' => [
1009 'columns' => [
1010 'aField' => [
1011 'config' => [
1012 'type' => 'flex',
1013 'ds_pointerField' => 'pointerField',
1014 'ds' => [
1015 'aFlex' => '
1016 <T3DataStructure>
1017 <ROOT>
1018 <type>array</type>
1019 <el>
1020 <aFlexField>
1021 <TCEforms>
1022 <label>aFlexFieldLabel</label>
1023 <exclude>1</exclude>
1024 <config>
1025 <type>input</type>
1026 </config>
1027 </TCEforms>
1028 </aFlexField>
1029 </el>
1030 </ROOT>
1031 </T3DataStructure>
1032 ',
1033 ],
1034 ],
1035 ],
1036 ],
1037 ],
1038 'pageTsConfigMerged' => [],
1039 ];
1040
1041 $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(FALSE);
1042 $GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
1043
1044 $expected = $input;
1045 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1046 'meta' => [
1047 'availableLanguageCodes' => [],
1048 'langDisable' => FALSE,
1049 'langChildren' => FALSE,
1050 'languagesOnSheetLevel' => [],
1051 'languagesOnElement' => [
1052 0 => 'DEF',
1053 ]
1054 ],
1055 'sheets' => [
1056 'sDEF' => [
1057 'ROOT' => [
1058 'type' => 'array',
1059 'el' => [],
1060 ],
1061 ],
1062 ],
1063 ];
1064
1065 $this->assertEquals($expected, $this->subject->addData($input));
1066 }
1067
1068 /**
1069 * @test
1070 */
1071 public function addDataKeepsExcludeFieldInDataStructureWithUserAccess() {
1072 $input = [
1073 'tableName' => 'aTable',
1074 'databaseRow' => [
1075 'aField' => [
1076 'data' => [],
1077 'meta' => [],
1078 ],
1079 'pointerField' => 'aFlex',
1080 ],
1081 'systemLanguageRows' => [],
1082 'processedTca' => [
1083 'columns' => [
1084 'aField' => [
1085 'config' => [
1086 'type' => 'flex',
1087 'ds_pointerField' => 'pointerField',
1088 'ds' => [
1089 'aFlex' => '
1090 <T3DataStructure>
1091 <ROOT>
1092 <type>array</type>
1093 <el>
1094 <aFlexField>
1095 <TCEforms>
1096 <label>aFlexFieldLabel</label>
1097 <exclude>1</exclude>
1098 <config>
1099 <type>input</type>
1100 </config>
1101 </TCEforms>
1102 </aFlexField>
1103 </el>
1104 </ROOT>
1105 </T3DataStructure>
1106 ',
1107 ],
1108 ],
1109 ],
1110 ],
1111 ],
1112 'pageTsConfigMerged' => [],
1113 ];
1114
1115 $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(FALSE);
1116 $GLOBALS['BE_USER']->groupData['non_exclude_fields'] = 'aTable:aField;aFlex;sDEF;aFlexField';
1117
1118 $expected = $input;
1119 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1120 'meta' => [
1121 'availableLanguageCodes' => [],
1122 'langDisable' => FALSE,
1123 'langChildren' => FALSE,
1124 'languagesOnSheetLevel' => [],
1125 'languagesOnElement' => [
1126 0 => 'DEF',
1127 ]
1128 ],
1129 'sheets' => [
1130 'sDEF' => [
1131 'ROOT' => [
1132 'type' => 'array',
1133 'el' => [
1134 'aFlexField' => [
1135 'label' => 'aFlexFieldLabel',
1136 'config' => [
1137 'type' => 'input',
1138 ],
1139 'exclude' => '1',
1140 ],
1141 ],
1142 ],
1143 ],
1144 ],
1145 ];
1146
1147 $this->assertEquals($expected, $this->subject->addData($input));
1148 }
1149
1150 /**
1151 * @test
1152 */
1153 public function addDataKeepsExcludeFieldInDataStructureForAdminUser() {
1154 $input = [
1155 'tableName' => 'aTable',
1156 'databaseRow' => [
1157 'aField' => [
1158 'data' => [],
1159 'meta' => [],
1160 ],
1161 'pointerField' => 'aFlex',
1162 ],
1163 'systemLanguageRows' => [],
1164 'processedTca' => [
1165 'columns' => [
1166 'aField' => [
1167 'config' => [
1168 'type' => 'flex',
1169 'ds_pointerField' => 'pointerField',
1170 'ds' => [
1171 'aFlex' => '
1172 <T3DataStructure>
1173 <ROOT>
1174 <type>array</type>
1175 <el>
1176 <aFlexField>
1177 <TCEforms>
1178 <label>aFlexFieldLabel</label>
1179 <exclude>1</exclude>
1180 <config>
1181 <type>input</type>
1182 </config>
1183 </TCEforms>
1184 </aFlexField>
1185 </el>
1186 </ROOT>
1187 </T3DataStructure>
1188 ',
1189 ],
1190 ],
1191 ],
1192 ],
1193 ],
1194 'pageTsConfigMerged' => [],
1195 ];
1196
1197 $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(TRUE);
1198 $GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
1199
1200 $expected = $input;
1201 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1202 'meta' => [
1203 'availableLanguageCodes' => [],
1204 'langDisable' => FALSE,
1205 'langChildren' => FALSE,
1206 'languagesOnSheetLevel' => [],
1207 'languagesOnElement' => [
1208 0 => 'DEF',
1209 ]
1210 ],
1211 'sheets' => [
1212 'sDEF' => [
1213 'ROOT' => [
1214 'type' => 'array',
1215 'el' => [
1216 'aFlexField' => [
1217 'label' => 'aFlexFieldLabel',
1218 'config' => [
1219 'type' => 'input',
1220 ],
1221 'exclude' => '1',
1222 ],
1223 ],
1224 ],
1225 ],
1226 ],
1227 ];
1228
1229 $this->assertEquals($expected, $this->subject->addData($input));
1230 }
1231
1232 /**
1233 * @test
1234 */
1235 public function addDataRemovesPageTsDisabledFieldFromDataStructure() {
1236 $input = [
1237 'tableName' => 'aTable',
1238 'databaseRow' => [
1239 'aField' => [
1240 'data' => [],
1241 'meta' => [],
1242 ],
1243 'pointerField' => 'aFlex',
1244 ],
1245 'systemLanguageRows' => [],
1246 'processedTca' => [
1247 'columns' => [
1248 'aField' => [
1249 'config' => [
1250 'type' => 'flex',
1251 'ds_pointerField' => 'pointerField',
1252 'ds' => [
1253 'aFlex' => '
1254 <T3DataStructure>
1255 <ROOT>
1256 <type>array</type>
1257 <el>
1258 <aFlexField>
1259 <TCEforms>
1260 <label>aFlexFieldLabel</label>
1261 <config>
1262 <type>input</type>
1263 </config>
1264 </TCEforms>
1265 </aFlexField>
1266 </el>
1267 </ROOT>
1268 </T3DataStructure>
1269 ',
1270 ],
1271 ],
1272 ],
1273 ],
1274 ],
1275 'pageTsConfigMerged' => [
1276 'TCEFORM.' => [
1277 'aTable.' => [
1278 'aField.' => [
1279 'aFlex.' => [
1280 'sDEF.' => [
1281 'aFlexField.' => [
1282 'disabled' => 1,
1283 ],
1284 ],
1285 ],
1286 ],
1287 ],
1288 ],
1289 ],
1290 ];
1291
1292 $expected = $input;
1293 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1294 'meta' => [
1295 'availableLanguageCodes' => [],
1296 'langDisable' => FALSE,
1297 'langChildren' => FALSE,
1298 'languagesOnSheetLevel' => [],
1299 'languagesOnElement' => [
1300 0 => 'DEF',
1301 ]
1302 ],
1303 'sheets' => [
1304 'sDEF' => [
1305 'ROOT' => [
1306 'type' => 'array',
1307 'el' => [],
1308 ],
1309 ],
1310 ],
1311 ];
1312
1313 $this->assertEquals($expected, $this->subject->addData($input));
1314 }
1315
1316 /**
1317 * @test
1318 */
1319 public function addDataCleansLanguageDisabledDataValues() {
1320 $input = [
1321 'tableName' => 'aTable',
1322 'databaseRow' => [
1323 'aField' => [
1324 'data' => [
1325 'sDEF' => [
1326 'lDEF' => [
1327 'input_1' => [
1328 'vDEF' => 'input1 text',
1329 'vDEF.vDEFbase' => 'base',
1330 '_TRANSFORM_vDEF.vDEFbase' => 'transform',
1331 'vRemoveMe' => 'removeMe',
1332 'vRemoveMe.vDEFbase' => 'removeMe',
1333 '_TRANSFORM_vRemoveMe.vDEFbase' => 'removeMe',
1334 ],
1335 'section_1' => [
1336 'el' => [
1337 '1' => [
1338 'container_1' => [
1339 'el' => [
1340 'input_2' => [
1341 'vDEF' => 'input2 text',
1342 'vRemoveMe' => 'removeMe',
1343 ]
1344 ],
1345 ],
1346 ],
1347 ],
1348 ],
1349 'invalid1' => 'keepMe',
1350 'invalid2' => [
1351 'el' => [
1352 '1' => [
1353 'keepMe',
1354 ],
1355 ],
1356 ],
1357 'invalid3' => [
1358 'el' => [
1359 '1' => [
1360 'container_2' => 'keepMe',
1361 ],
1362 ],
1363 ],
1364 'invalid4' => [
1365 'el' => [
1366 '1' => [
1367 'container_2' => [
1368 'el' => 'keepMe',
1369 ],
1370 ],
1371 ],
1372 ],
1373 'invalid5' => [
1374 'el' => [
1375 '1' => [
1376 'container_2' => [
1377 'el' => [
1378 'field' => 'keepMe',
1379 ],
1380 ],
1381 ],
1382 ],
1383 ],
1384 ],
1385 'lRemoveMe' => [],
1386 ],
1387 ],
1388 'meta' => [],
1389 ],
1390 'pointerField' => 'aFlex',
1391 ],
1392 'systemLanguageRows' => [
1393 0 => [
1394 'uid' => 0,
1395 'title' => 'aLanguageTitle',
1396 'iso' => 'DEF',
1397 ],
1398 ],
1399 'processedTca' => [
1400 'columns' => [
1401 'aField' => [
1402 'config' => [
1403 'type' => 'flex',
1404 'ds_pointerField' => 'pointerField',
1405 'ds' => [
1406 'aFlex' => '
1407 <T3DataStructure>
1408 <ROOT></ROOT>
1409 <meta>
1410 <langDisable>1</langDisable>
1411 </meta>
1412 </T3DataStructure>
1413 ',
1414 ],
1415 ],
1416 ],
1417 ],
1418 ],
1419 ];
1420
1421 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1422 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1423
1424 $expected = $input;
1425 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1426 'ROOT' => '',
1427 'meta' => [
1428 'availableLanguageCodes' => [
1429 0 => 'DEF',
1430 ],
1431 'langDisable' => TRUE,
1432 'langChildren' => FALSE,
1433 'languagesOnSheetLevel' => [
1434 0 => 'DEF',
1435 ],
1436 'languagesOnElement' => [
1437 0 => 'DEF',
1438 ]
1439 ],
1440 ];
1441
1442 unset($expected['databaseRow']['aField']['data']['sDEF']['lRemoveMe']);
1443 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['input_1']['vRemoveMe']);
1444 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['input_1']['vRemoveMe.vDEFbase']);
1445 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['input_1']['_TRANSFORM_vRemoveMe.vDEFbase']);
1446 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['input_2']['vRemoveMe']);
1447
1448 $this->assertEquals($expected, $this->subject->addData($input));
1449 }
1450
1451 /**
1452 * @test
1453 */
1454 public function addDataRemovesDataValuesIfUserHasNoAccess() {
1455 $input = [
1456 'tableName' => 'aTable',
1457 'databaseRow' => [
1458 'aField' => [
1459 'data' => [
1460 'sDEF' => [
1461 'lDEF' => [
1462 'input_1' => [
1463 'vDEF' => 'input1 text',
1464 ],
1465 'section_1' => [
1466 'el' => [
1467 '1' => [
1468 'container_1' => [
1469 'el' => [
1470 'input_2' => [
1471 'vDEF' => 'input2 text',
1472 'vNoAccess' => 'removeMe',
1473 ]
1474 ],
1475 ],
1476 ],
1477 ],
1478 ],
1479 ],
1480 'lNoAccess' => [],
1481 ],
1482 ],
1483 'meta' => [],
1484 ],
1485 'pointerField' => 'aFlex',
1486 ],
1487 'systemLanguageRows' => [
1488 0 => [
1489 'uid' => 0,
1490 'iso' => 'DEF',
1491 ],
1492 1 => [
1493 'uid' => 1,
1494 'iso' => 'NoAccess',
1495 ],
1496 ],
1497 'processedTca' => [
1498 'columns' => [
1499 'aField' => [
1500 'config' => [
1501 'type' => 'flex',
1502 'ds_pointerField' => 'pointerField',
1503 'ds' => [
1504 'aFlex' => '
1505 <T3DataStructure>
1506 <ROOT></ROOT>
1507 <meta>
1508 <langDisable>0</langDisable>
1509 </meta>
1510 </T3DataStructure>
1511 ',
1512 ],
1513 ],
1514 ],
1515 ],
1516 ],
1517 ];
1518
1519 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1520 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1521 $this->backendUserProphecy->checkLanguageAccess('1')->shouldBeCalled()->willReturn(FALSE);
1522
1523 $expected = $input;
1524 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1525 'ROOT' => '',
1526 'meta' => [
1527 'availableLanguageCodes' => [
1528 0 => 'DEF',
1529 ],
1530 'langDisable' => FALSE,
1531 'langChildren' => FALSE,
1532 'languagesOnSheetLevel' => [
1533 0 => 'DEF',
1534 ],
1535 'languagesOnElement' => [
1536 0 => 'DEF',
1537 ]
1538 ],
1539 ];
1540
1541 unset($expected['databaseRow']['aField']['data']['sDEF']['lNoAccess']);
1542 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['input_2']['vNoAccess']);
1543
1544 $this->assertEquals($expected, $this->subject->addData($input));
1545 }
1546
1547 /**
1548 * @test
1549 */
1550 public function addDataAddsNewLanguageDataValues() {
1551 $input = [
1552 'tableName' => 'aTable',
1553 'databaseRow' => [
1554 'aField' => [
1555 'data' => [
1556 'sDEF' => [
1557 'lDEF' => [
1558 'input_1' => [
1559 'vDEF' => 'input1 text',
1560 ],
1561 ],
1562 ],
1563 ],
1564 'meta' => [],
1565 ],
1566 'pointerField' => 'aFlex',
1567 ],
1568 'systemLanguageRows' => [
1569 0 => [
1570 'uid' => 0,
1571 'iso' => 'DEF',
1572 ],
1573 1 => [
1574 'uid' => 1,
1575 'iso' => 'EN',
1576 ],
1577 ],
1578 'processedTca' => [
1579 'columns' => [
1580 'aField' => [
1581 'config' => [
1582 'type' => 'flex',
1583 'ds_pointerField' => 'pointerField',
1584 'ds' => [
1585 'aFlex' => '
1586 <T3DataStructure>
1587 <ROOT></ROOT>
1588 <meta>
1589 <langDisable>0</langDisable>
1590 </meta>
1591 </T3DataStructure>
1592 ',
1593 ],
1594 ],
1595 ],
1596 ],
1597 ],
1598 ];
1599
1600 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1601 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1602 $this->backendUserProphecy->checkLanguageAccess('1')->shouldBeCalled()->willReturn(TRUE);
1603
1604 $expected = $input;
1605 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1606 'ROOT' => '',
1607 'meta' => [
1608 'availableLanguageCodes' => [
1609 0 => 'DEF',
1610 1 => 'EN',
1611 ],
1612 'langDisable' => FALSE,
1613 'langChildren' => FALSE,
1614 'languagesOnSheetLevel' => [
1615 0 => 'DEF',
1616 1 => 'EN',
1617 ],
1618 'languagesOnElement' => [
1619 0 => 'DEF',
1620 ]
1621 ],
1622 ];
1623
1624 $expected['databaseRow']['aField']['data']['sDEF']['lEN'] = [];
1625
1626 $this->assertEquals($expected, $this->subject->addData($input));
1627 }
1628
1629 /**
1630 * @test
1631 */
1632 public function addDataRemovesDataValuesIfPageOverlayCheckIsEnabled() {
1633 $input = [
1634 'tableName' => 'aTable',
1635 'databaseRow' => [
1636 'aField' => [
1637 'data' => [
1638 'sDEF' => [
1639 'lDEF' => [],
1640 'lEN' => [],
1641 'lNoOverlay' => [],
1642 ],
1643 ],
1644 'meta' => [],
1645 ],
1646 'pointerField' => 'aFlex',
1647 ],
1648 'systemLanguageRows' => [
1649 0 => [
1650 'uid' => 0,
1651 'iso' => 'DEF',
1652 ],
1653 1 => [
1654 'uid' => 1,
1655 'iso' => 'EN',
1656 ],
1657 2 => [
1658 'uid' => 2,
1659 'iso' => 'NoOverlay',
1660 ],
1661 ],
1662 'userTsConfig' => [
1663 'options.' => [
1664 'checkPageLanguageOverlay' => '1',
1665 ],
1666 ],
1667 'pageLanguageOverlayRows' => [
1668 0 => [
1669 'uid' => 1,
1670 'sys_language_uid' => 1,
1671 ],
1672 ],
1673 'processedTca' => [
1674 'columns' => [
1675 'aField' => [
1676 'config' => [
1677 'type' => 'flex',
1678 'ds_pointerField' => 'pointerField',
1679 'ds' => [
1680 'aFlex' => '
1681 <T3DataStructure>
1682 <ROOT></ROOT>
1683 <meta>
1684 <langDisable>0</langDisable>
1685 </meta>
1686 </T3DataStructure>
1687 ',
1688 ],
1689 ],
1690 ],
1691 ],
1692 ],
1693 ];
1694
1695 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1696 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1697 $this->backendUserProphecy->checkLanguageAccess('1')->shouldBeCalled()->willReturn(TRUE);
1698 $this->backendUserProphecy->checkLanguageAccess('2')->shouldBeCalled()->willReturn(TRUE);
1699
1700 $expected = $input;
1701 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1702 'ROOT' => '',
1703 'meta' => [
1704 'availableLanguageCodes' => [
1705 0 => 'DEF',
1706 1 => 'EN',
1707 ],
1708 'langDisable' => FALSE,
1709 'langChildren' => FALSE,
1710 'languagesOnSheetLevel' => [
1711 0 => 'DEF',
1712 1 => 'EN',
1713 ],
1714 'languagesOnElement' => [
1715 0 => 'DEF',
1716 ]
1717 ],
1718 ];
1719
1720 unset($expected['databaseRow']['aField']['data']['sDEF']['lNoOverlay']);
1721
1722 $this->assertEquals($expected, $this->subject->addData($input));
1723 }
1724
1725 /**
1726 * @test
1727 */
1728 public function addDataRemovesLanguageDataValuesIfUserHasNoAccessWithLangChildren() {
1729 $input = [
1730 'tableName' => 'aTable',
1731 'databaseRow' => [
1732 'aField' => [
1733 'data' => [
1734 'sDEF' => [
1735 'lDEF' => [
1736 'input_1' => [
1737 'vDEF' => 'input1 text',
1738 'vNoAccess' => 'removeMe',
1739 ],
1740 'section_1' => [
1741 'el' => [
1742 '1' => [
1743 'container_1' => [
1744 'el' => [
1745 'input_2' => [
1746 'vDEF' => 'input2 text',
1747 'vNoAccess' => 'removeMe',
1748 ]
1749 ],
1750 ],
1751 ],
1752 ],
1753 ],
1754 ],
1755 'lNoAccess' => [],
1756 ],
1757 ],
1758 'meta' => [],
1759 ],
1760 'pointerField' => 'aFlex',
1761 ],
1762 'systemLanguageRows' => [
1763 0 => [
1764 'uid' => 0,
1765 'iso' => 'DEF',
1766 ],
1767 1 => [
1768 'uid' => 1,
1769 'iso' => 'NoAccess',
1770 ],
1771 ],
1772 'processedTca' => [
1773 'columns' => [
1774 'aField' => [
1775 'config' => [
1776 'type' => 'flex',
1777 'ds_pointerField' => 'pointerField',
1778 'ds' => [
1779 'aFlex' => '
1780 <T3DataStructure>
1781 <ROOT></ROOT>
1782 <meta>
1783 <langDisable>0</langDisable>
1784 <langChildren>1</langChildren>
1785 </meta>
1786 </T3DataStructure>
1787 ',
1788 ],
1789 ],
1790 ],
1791 ],
1792 ],
1793 ];
1794
1795 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1796 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1797 $this->backendUserProphecy->checkLanguageAccess('1')->shouldBeCalled()->willReturn(FALSE);
1798
1799 $expected = $input;
1800 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1801 'ROOT' => '',
1802 'meta' => [
1803 'availableLanguageCodes' => [
1804 0 => 'DEF',
1805 ],
1806 'langDisable' => FALSE,
1807 'langChildren' => TRUE,
1808 'languagesOnSheetLevel' => [
1809 0 => 'DEF',
1810 ],
1811 'languagesOnElement' => [
1812 0 => 'DEF',
1813 ]
1814 ],
1815 ];
1816
1817 unset($expected['databaseRow']['aField']['data']['sDEF']['lNoAccess']);
1818 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['input_1']['vNoAccess']);
1819 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['input_2']['vNoAccess']);
1820
1821 $this->assertEquals($expected, $this->subject->addData($input));
1822 }
1823
1824 /**
1825 * @test
1826 */
1827 public function addDataRemovesDataValuesIfPageOverlayCheckIsEnabledWithLangChildren() {
1828 $input = [
1829 'tableName' => 'aTable',
1830 'databaseRow' => [
1831 'aField' => [
1832 'data' => [
1833 'sDEF' => [
1834 'lDEF' => [
1835 'input_1' => [
1836 'vDEF' => 'input1 text',
1837 'vEN' => 'input1 en text',
1838 'vNoOverlay' => 'removeMe',
1839 ],
1840 ],
1841 ],
1842 ],
1843 'meta' => [],
1844 ],
1845 'pointerField' => 'aFlex',
1846 ],
1847 'systemLanguageRows' => [
1848 0 => [
1849 'uid' => 0,
1850 'iso' => 'DEF',
1851 ],
1852 1 => [
1853 'uid' => 1,
1854 'iso' => 'EN',
1855 ],
1856 2 => [
1857 'uid' => 2,
1858 'iso' => 'NoOverlay',
1859 ],
1860 ],
1861 'userTsConfig' => [
1862 'options.' => [
1863 'checkPageLanguageOverlay' => '1',
1864 ],
1865 ],
1866 'pageLanguageOverlayRows' => [
1867 0 => [
1868 'uid' => 1,
1869 'sys_language_uid' => 1,
1870 ],
1871 ],
1872 'processedTca' => [
1873 'columns' => [
1874 'aField' => [
1875 'config' => [
1876 'type' => 'flex',
1877 'ds_pointerField' => 'pointerField',
1878 'ds' => [
1879 'aFlex' => '
1880 <T3DataStructure>
1881 <ROOT></ROOT>
1882 <meta>
1883 <langDisable>0</langDisable>
1884 <langChildren>1</langChildren>
1885 </meta>
1886 </T3DataStructure>
1887 ',
1888 ],
1889 ],
1890 ],
1891 ],
1892 ],
1893 ];
1894
1895 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
1896 $this->backendUserProphecy->checkLanguageAccess('0')->shouldBeCalled()->willReturn(TRUE);
1897 $this->backendUserProphecy->checkLanguageAccess('1')->shouldBeCalled()->willReturn(TRUE);
1898 $this->backendUserProphecy->checkLanguageAccess('2')->shouldBeCalled()->willReturn(TRUE);
1899
1900 $expected = $input;
1901 $expected['processedTca']['columns']['aField']['config']['ds'] = [
1902 'ROOT' => '',
1903 'meta' => [
1904 'availableLanguageCodes' => [
1905 0 => 'DEF',
1906 1 => 'EN',
1907 ],
1908 'langDisable' => FALSE,
1909 'langChildren' => TRUE,
1910 'languagesOnSheetLevel' => [
1911 0 => 'DEF',
1912 ],
1913 'languagesOnElement' => [
1914 0 => 'DEF',
1915 1 => 'EN',
1916 ]
1917 ],
1918 ];
1919
1920 unset($expected['databaseRow']['aField']['data']['sDEF']['lDEF']['input_1']['vNoOverlay']);
1921
1922 $this->assertEquals($expected, $this->subject->addData($input));
1923 }
1924
1925 /**
1926 * @test
1927 */
1928 public function addDataHandlesPageTsConfigSettingsOfSingleFlexField() {
1929 $input = [
1930 'tableName' => 'aTable',
1931 'databaseRow' => [
1932 'aField' => [
1933 'data' => [],
1934 'meta' => [],
1935 ],
1936 'pointerField' => 'aFlex',
1937 ],
1938 'systemLanguageRows' => [
1939 0 => [
1940 'uid' => 0,
1941 'iso' => 'DEF',
1942 ],
1943 ],
1944 'processedTca' => [
1945 'columns' => [
1946 'aField' => [
1947 'config' => [
1948 'type' => 'flex',
1949 'ds_pointerField' => 'pointerField',
1950 'ds' => [
1951 'aFlex' => '
1952 <T3DataStructure>
1953 <ROOT>
1954 <type>array</type>
1955 <el>
1956 <aFlexField>
1957 <TCEforms>
1958 <label>aFlexFieldLabel</label>
1959 <config>
1960 <type>radio</type>
1961 <items>
1962 <numIndex index="0">
1963 <numIndex index="0">aLabel</numIndex>
1964 <numIndex index="1">aValue</numIndex>
1965 </numIndex>
1966 </items>
1967 </config>
1968 </TCEforms>
1969 </aFlexField>
1970 </el>
1971 </ROOT>
1972 </T3DataStructure>
1973 ',
1974 ],
1975 ],
1976 ],
1977 ],
1978 ],
1979 'pageTsConfigMerged' => [
1980 'TCEFORM.' => [
1981 'aTable.' => [
1982 'aField.' => [
1983 'aFlex.' => [
1984 'sDEF.' => [
1985 'aFlexField.' => [
1986 'altLabels.' => [
1987 '0' => 'labelOverride',
1988 ],
1989 ],
1990 ],
1991 ],
1992 ],
1993 ],
1994 ],
1995 ],
1996 ];
1997
1998 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
1999 \TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems::class => [],
2000 ];
2001
2002 /** @var LanguageService|ObjectProphecy $languageService */
2003 $languageService = $this->prophesize(LanguageService::class);
2004 $GLOBALS['LANG'] = $languageService->reveal();
2005 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2006
2007 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2008 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2009
2010 $expected = $input;
2011 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2012 'meta' => [
2013 'availableLanguageCodes' => [
2014 0 => 'DEF',
2015 ],
2016 'langDisable' => FALSE,
2017 'langChildren' => FALSE,
2018 'languagesOnSheetLevel' => [
2019 0 => 'DEF',
2020 ],
2021 'languagesOnElement' => [
2022 0 => 'DEF',
2023 ]
2024 ],
2025 'sheets' => [
2026 'sDEF' => [
2027 'ROOT' => [
2028 'type' => 'array',
2029 'el' => [
2030 'aFlexField' => [
2031 'label' => 'aFlexFieldLabel',
2032 'config' => [
2033 'type' => 'radio',
2034 'items' => [
2035 0 => [
2036 0 => 'labelOverride',
2037 1 => 'aValue',
2038 ],
2039 ],
2040 ],
2041 ],
2042 ],
2043 ],
2044 ],
2045 ],
2046 ];
2047
2048 $this->assertEquals($expected, $this->subject->addData($input));
2049 }
2050
2051 /**
2052 * @test
2053 */
2054 public function addDataSetsDefaultValueFromFlexTcaForField() {
2055 $input = [
2056 'tableName' => 'aTable',
2057 'databaseRow' => [
2058 'aField' => [
2059 'data' => [],
2060 'meta' => [],
2061 ],
2062 'pointerField' => 'aFlex',
2063 ],
2064 'systemLanguageRows' => [
2065 0 => [
2066 'uid' => 0,
2067 'iso' => 'DEF',
2068 ],
2069 ],
2070 'processedTca' => [
2071 'columns' => [
2072 'aField' => [
2073 'config' => [
2074 'type' => 'flex',
2075 'ds_pointerField' => 'pointerField',
2076 'ds' => [
2077 'aFlex' => '
2078 <T3DataStructure>
2079 <ROOT>
2080 <type>array</type>
2081 <el>
2082 <aFlexField>
2083 <TCEforms>
2084 <label>aFlexFieldLabel</label>
2085 <config>
2086 <type>input</type>
2087 <default>defaultValue</default>
2088 </config>
2089 </TCEforms>
2090 </aFlexField>
2091 </el>
2092 </ROOT>
2093 </T3DataStructure>
2094 ',
2095 ],
2096 ],
2097 ],
2098 ],
2099 ],
2100 'pageTsConfigMerged' => [],
2101 ];
2102
2103 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2104 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2105 ];
2106
2107 /** @var LanguageService|ObjectProphecy $languageService */
2108 $languageService = $this->prophesize(LanguageService::class);
2109 $GLOBALS['LANG'] = $languageService->reveal();
2110 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2111
2112 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2113 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2114
2115 $expected = $input;
2116 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2117 'meta' => [
2118 'availableLanguageCodes' => [
2119 0 => 'DEF',
2120 ],
2121 'langDisable' => FALSE,
2122 'langChildren' => FALSE,
2123 'languagesOnSheetLevel' => [
2124 0 => 'DEF',
2125 ],
2126 'languagesOnElement' => [
2127 0 => 'DEF',
2128 ]
2129 ],
2130 'sheets' => [
2131 'sDEF' => [
2132 'ROOT' => [
2133 'type' => 'array',
2134 'el' => [
2135 'aFlexField' => [
2136 'label' => 'aFlexFieldLabel',
2137 'config' => [
2138 'type' => 'input',
2139 'default' => 'defaultValue',
2140 ],
2141 ],
2142 ],
2143 ],
2144 ],
2145 ],
2146 ];
2147
2148 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vDEF'] = 'defaultValue';
2149
2150 $this->assertEquals($expected, $this->subject->addData($input));
2151 }
2152
2153 /**
2154 * @test
2155 */
2156 public function addDataSetsDefaultValueFromFlexTcaForFieldInLocalizedSheet() {
2157 $input = [
2158 'tableName' => 'aTable',
2159 'databaseRow' => [
2160 'aField' => [
2161 'data' => [],
2162 'meta' => [],
2163 ],
2164 ],
2165 'systemLanguageRows' => [
2166 0 => [
2167 'uid' => 0,
2168 'iso' => 'DEF',
2169 ],
2170 1 => [
2171 'uid' => 1,
2172 'iso' => 'EN',
2173 ],
2174 ],
2175 'processedTca' => [
2176 'columns' => [
2177 'aField' => [
2178 'config' => [
2179 'type' => 'flex',
2180 'ds' => [
2181 'default' => '
2182 <T3DataStructure>
2183 <ROOT>
2184 <type>array</type>
2185 <el>
2186 <aFlexField>
2187 <TCEforms>
2188 <label>aFlexFieldLabel</label>
2189 <config>
2190 <type>input</type>
2191 <default>defaultValue</default>
2192 </config>
2193 </TCEforms>
2194 </aFlexField>
2195 </el>
2196 </ROOT>
2197 </T3DataStructure>
2198 ',
2199 ],
2200 ],
2201 ],
2202 ],
2203 ],
2204 'pageTsConfigMerged' => [],
2205 ];
2206
2207 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2208 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2209 ];
2210
2211 /** @var LanguageService|ObjectProphecy $languageService */
2212 $languageService = $this->prophesize(LanguageService::class);
2213 $GLOBALS['LANG'] = $languageService->reveal();
2214 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2215
2216 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2217 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2218
2219 $expected = $input;
2220 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2221 'meta' => [
2222 'availableLanguageCodes' => [
2223 0 => 'DEF',
2224 1 => 'EN',
2225 ],
2226 'langDisable' => FALSE,
2227 'langChildren' => FALSE,
2228 'languagesOnSheetLevel' => [
2229 0 => 'DEF',
2230 1 => 'EN',
2231 ],
2232 'languagesOnElement' => [
2233 0 => 'DEF'
2234 ]
2235 ],
2236 'sheets' => [
2237 'sDEF' => [
2238 'ROOT' => [
2239 'type' => 'array',
2240 'el' => [
2241 'aFlexField' => [
2242 'label' => 'aFlexFieldLabel',
2243 'config' => [
2244 'type' => 'input',
2245 'default' => 'defaultValue',
2246 ],
2247 ],
2248 ],
2249 ],
2250 ],
2251 ],
2252 ];
2253
2254 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vDEF'] = 'defaultValue';
2255 $expected['databaseRow']['aField']['data']['sDEF']['lEN']['aFlexField']['vDEF'] = 'defaultValue';
2256
2257 $this->assertEquals($expected, $this->subject->addData($input));
2258 }
2259
2260 /**
2261 * @test
2262 */
2263 public function addDataSetsDefaultValueFromFlexTcaForFieldInLocalizedSheetWithLangChildren() {
2264 $input = [
2265 'tableName' => 'aTable',
2266 'databaseRow' => [
2267 'aField' => [
2268 'data' => [],
2269 'meta' => [],
2270 ],
2271 ],
2272 'systemLanguageRows' => [
2273 0 => [
2274 'uid' => 0,
2275 'iso' => 'DEF',
2276 ],
2277 1 => [
2278 'uid' => 1,
2279 'iso' => 'EN',
2280 ],
2281 ],
2282 'processedTca' => [
2283 'columns' => [
2284 'aField' => [
2285 'config' => [
2286 'type' => 'flex',
2287 'ds' => [
2288 'default' => '
2289 <T3DataStructure>
2290 <meta>
2291 <langChildren>1</langChildren>
2292 </meta>
2293 <ROOT>
2294 <type>array</type>
2295 <el>
2296 <aFlexField>
2297 <TCEforms>
2298 <label>aFlexFieldLabel</label>
2299 <config>
2300 <type>input</type>
2301 <default>defaultValue</default>
2302 </config>
2303 </TCEforms>
2304 </aFlexField>
2305 </el>
2306 </ROOT>
2307 </T3DataStructure>
2308 ',
2309 ],
2310 ],
2311 ],
2312 ],
2313 ],
2314 'pageTsConfigMerged' => [],
2315 ];
2316
2317 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2318 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2319 ];
2320
2321 /** @var LanguageService|ObjectProphecy $languageService */
2322 $languageService = $this->prophesize(LanguageService::class);
2323 $GLOBALS['LANG'] = $languageService->reveal();
2324 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2325
2326 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2327 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2328
2329 $expected = $input;
2330 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2331 'meta' => [
2332 'availableLanguageCodes' => [
2333 0 => 'DEF',
2334 1 => 'EN',
2335 ],
2336 'langDisable' => FALSE,
2337 'langChildren' => TRUE,
2338 'languagesOnSheetLevel' => [
2339 0 => 'DEF',
2340 ],
2341 'languagesOnElement' => [
2342 0 => 'DEF',
2343 1 => 'EN'
2344 ]
2345 ],
2346 'sheets' => [
2347 'sDEF' => [
2348 'ROOT' => [
2349 'type' => 'array',
2350 'el' => [
2351 'aFlexField' => [
2352 'label' => 'aFlexFieldLabel',
2353 'config' => [
2354 'type' => 'input',
2355 'default' => 'defaultValue',
2356 ],
2357 ],
2358 ],
2359 ],
2360 ],
2361 ],
2362 ];
2363
2364 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vDEF'] = 'defaultValue';
2365 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vEN'] = 'defaultValue';
2366
2367 $this->assertEquals($expected, $this->subject->addData($input));
2368 }
2369
2370 /**
2371 * @test
2372 */
2373 public function addDataThrowsExceptionForDataStructureTypeArrayWithoutSection() {
2374 $input = [
2375 'tableName' => 'aTable',
2376 'databaseRow' => [
2377 'aField' => [
2378 'data' => [],
2379 'meta' => [],
2380 ],
2381 ],
2382 'systemLanguageRows' => [
2383 0 => [
2384 'uid' => 0,
2385 'iso' => 'DEF',
2386 ],
2387 ],
2388 'processedTca' => [
2389 'columns' => [
2390 'aField' => [
2391 'config' => [
2392 'type' => 'flex',
2393 'ds' => [
2394 'default' => '
2395 <T3DataStructure>
2396 <ROOT>
2397 <type>array</type>
2398 <el>
2399 <aFlexField>
2400 <type>array</type>
2401 <TCEforms></TCEforms>
2402 </aFlexField>
2403 </el>
2404 </ROOT>
2405 </T3DataStructure>
2406 ',
2407 ],
2408 ],
2409 ],
2410 ],
2411 ],
2412 'pageTsConfigMerged' => [],
2413 ];
2414
2415 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2416 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2417
2418 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1440685208);
2419
2420 $this->subject->addData($input);
2421 }
2422
2423 /**
2424 * @test
2425 */
2426 public function addDataThrowsExceptionForDataStructureSectionWithoutTypeArray() {
2427 $input = [
2428 'tableName' => 'aTable',
2429 'databaseRow' => [
2430 'aField' => [
2431 'data' => [],
2432 'meta' => [],
2433 ],
2434 ],
2435 'systemLanguageRows' => [
2436 0 => [
2437 'uid' => 0,
2438 'iso' => 'DEF',
2439 ],
2440 ],
2441 'processedTca' => [
2442 'columns' => [
2443 'aField' => [
2444 'config' => [
2445 'type' => 'flex',
2446 'ds' => [
2447 'default' => '
2448 <T3DataStructure>
2449 <ROOT>
2450 <type>array</type>
2451 <el>
2452 <aFlexField>
2453 <section>1</section>
2454 <TCEforms></TCEforms>
2455 </aFlexField>
2456 </el>
2457 </ROOT>
2458 </T3DataStructure>
2459 ',
2460 ],
2461 ],
2462 ],
2463 ],
2464 ],
2465 'pageTsConfigMerged' => [],
2466 ];
2467
2468 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2469 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2470
2471 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1440685208);
2472
2473 $this->subject->addData($input);
2474 }
2475
2476 /**
2477 * @test
2478 */
2479 public function addDataSetsValuesAndStructureForSectionContainerElementsNoLangChildren() {
2480 $input = [
2481 'tableName' => 'aTable',
2482 'databaseRow' => [
2483 'aField' => [
2484 'data' => [
2485 'sDEF' => [
2486 'lDEF' => [
2487 'section_1' => [
2488 'el' => [
2489 '1' => [
2490 'container_1' => [
2491 // It should set the default value for aFlexField here
2492 'el' => [
2493 ],
2494 ],
2495 ],
2496 '2' => [
2497 'container_1' => [
2498 'el' => [
2499 'aFlexField' => [
2500 // It should keep this value
2501 'vDEF' => 'dbValue',
2502 ],
2503 ],
2504 ],
2505 ],
2506 ],
2507 ],
2508 ],
2509 'lEN' => [
2510 'section_1' => [
2511 'el' => [
2512 '1' => [
2513 'container_1' => [
2514 // It should add the default value for aFlexField here
2515 ],
2516 ],
2517 ],
2518 ],
2519 ],
2520 ],
2521 ],
2522 'meta' => [],
2523 ],
2524 ],
2525 'systemLanguageRows' => [
2526 0 => [
2527 'uid' => 0,
2528 'iso' => 'DEF',
2529 ],
2530 1 => [
2531 'uid' => 1,
2532 'iso' => 'EN',
2533 ],
2534 ],
2535 'processedTca' => [
2536 'columns' => [
2537 'aField' => [
2538 'config' => [
2539 'type' => 'flex',
2540 'ds' => [
2541 'default' => '
2542 <T3DataStructure>
2543 <ROOT>
2544 <type>array</type>
2545 <el>
2546 <section_1>
2547 <type>array</type>
2548 <section>1</section>
2549 <el>
2550 <container_1>
2551 <type>array</type>
2552 <el>
2553 <aFlexField>
2554 <TCEforms>
2555 <label>aFlexFieldLabel</label>
2556 <config>
2557 <type>input</type>
2558 <default>defaultValue</default>
2559 </config>
2560 </TCEforms>
2561 </aFlexField>
2562 </el>
2563 </container_1>
2564 </el>
2565 </section_1>
2566 </el>
2567 </ROOT>
2568 </T3DataStructure>
2569 ',
2570 ],
2571 ],
2572 ],
2573 ],
2574 ],
2575 'pageTsConfigMerged' => [],
2576 ];
2577
2578 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2579 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2580 ];
2581
2582 /** @var LanguageService|ObjectProphecy $languageService */
2583 $languageService = $this->prophesize(LanguageService::class);
2584 $GLOBALS['LANG'] = $languageService->reveal();
2585 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2586
2587 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2588 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2589
2590 $expected = $input;
2591 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2592 'meta' => [
2593 'availableLanguageCodes' => [
2594 0 => 'DEF',
2595 1 => 'EN',
2596 ],
2597 'langDisable' => FALSE,
2598 'langChildren' => FALSE,
2599 'languagesOnSheetLevel' => [
2600 0 => 'DEF',
2601 1 => 'EN',
2602 ],
2603 'languagesOnElement' => [
2604 0 => 'DEF',
2605 ]
2606 ],
2607 'sheets' => [
2608 'sDEF' => [
2609 'ROOT' => [
2610 'type' => 'array',
2611 'el' => [
2612 'section_1' => [
2613 'type' => 'array',
2614 'section' => '1',
2615 'el' => [
2616 'container_1' => [
2617 'type' => 'array',
2618 'el' => [
2619 'aFlexField' => [
2620 'label' => 'aFlexFieldLabel',
2621 'config' => [
2622 'type' => 'input',
2623 'default' => 'defaultValue',
2624 ],
2625 ],
2626 ],
2627 ],
2628 ],
2629 ],
2630 ],
2631 ],
2632 ],
2633 ],
2634 ];
2635
2636 // A default value for existing container field aFlexField should have been set
2637 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2638 // Also for the other defined language
2639 $expected['databaseRow']['aField']['data']['sDEF']['lEN']['section_1']['el']['1']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2640
2641 // Dummy row values for container_1 on lDEF sheet
2642 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['templateRows']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2643 // Dummy row values for container_1 on lDEF sheet
2644 $expected['databaseRow']['aField']['data']['sDEF']['lEN']['section_1']['templateRows']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2645
2646 $this->assertEquals($expected, $this->subject->addData($input));
2647 }
2648
2649 /**
2650 * @test
2651 */
2652 public function addDataSetsValuesAndStructureForSectionContainerElementsWithLangChildren() {
2653 $input = [
2654 'tableName' => 'aTable',
2655 'databaseRow' => [
2656 'aField' => [
2657 'data' => [
2658 'sDEF' => [
2659 'lDEF' => [
2660 'section_1' => [
2661 'el' => [
2662 '1' => [
2663 'container_1' => [
2664 // It should set a default for both vDEF and vEN
2665 'el' => [
2666 ],
2667 ],
2668 ],
2669 '2' => [
2670 'container_1' => [
2671 'el' => [
2672 'aFlexField' => [
2673 // It should keep this value
2674 'vDEF' => 'dbValue',
2675 // It should set a default for vEN
2676 ],
2677 ],
2678 ],
2679 ],
2680 ],
2681 ],
2682 ],
2683 ],
2684 ],
2685 'meta' => [],
2686 ],
2687 ],
2688 'systemLanguageRows' => [
2689 0 => [
2690 'uid' => 0,
2691 'iso' => 'DEF',
2692 ],
2693 1 => [
2694 'uid' => 1,
2695 'iso' => 'EN',
2696 ],
2697 ],
2698 'processedTca' => [
2699 'columns' => [
2700 'aField' => [
2701 'config' => [
2702 'type' => 'flex',
2703 'ds' => [
2704 'default' => '
2705 <T3DataStructure>
2706 <meta>
2707 <langChildren>1</langChildren>
2708 </meta>
2709 <ROOT>
2710 <type>array</type>
2711 <el>
2712 <section_1>
2713 <type>array</type>
2714 <section>1</section>
2715 <el>
2716 <container_1>
2717 <type>array</type>
2718 <el>
2719 <aFlexField>
2720 <TCEforms>
2721 <label>aFlexFieldLabel</label>
2722 <config>
2723 <type>input</type>
2724 <default>defaultValue</default>
2725 </config>
2726 </TCEforms>
2727 </aFlexField>
2728 </el>
2729 </container_1>
2730 </el>
2731 </section_1>
2732 </el>
2733 </ROOT>
2734 </T3DataStructure>
2735 ',
2736 ],
2737 ],
2738 ],
2739 ],
2740 ],
2741 'pageTsConfigMerged' => [],
2742 ];
2743
2744 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2745 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2746 ];
2747
2748 /** @var LanguageService|ObjectProphecy $languageService */
2749 $languageService = $this->prophesize(LanguageService::class);
2750 $GLOBALS['LANG'] = $languageService->reveal();
2751 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2752
2753 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2754 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2755
2756 $expected = $input;
2757 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2758 'meta' => [
2759 'availableLanguageCodes' => [
2760 0 => 'DEF',
2761 1 => 'EN',
2762 ],
2763 'langDisable' => FALSE,
2764 'langChildren' => TRUE,
2765 'languagesOnSheetLevel' => [
2766 0 => 'DEF',
2767 ],
2768 'languagesOnElement' => [
2769 0 => 'DEF',
2770 1 => 'EN',
2771 ]
2772 ],
2773 'sheets' => [
2774 'sDEF' => [
2775 'ROOT' => [
2776 'type' => 'array',
2777 'el' => [
2778 'section_1' => [
2779 'type' => 'array',
2780 'section' => '1',
2781 'el' => [
2782 'container_1' => [
2783 'type' => 'array',
2784 'el' => [
2785 'aFlexField' => [
2786 'label' => 'aFlexFieldLabel',
2787 'config' => [
2788 'type' => 'input',
2789 'default' => 'defaultValue',
2790 ],
2791 ],
2792 ],
2793 ],
2794 ],
2795 ],
2796 ],
2797 ],
2798 ],
2799 ],
2800 ];
2801
2802 // A default value for existing container field aFlexField should have been set
2803 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2804 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['aFlexField']['vEN'] = 'defaultValue';
2805 // Also for the other defined language
2806 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['2']['container_1']['el']['aFlexField']['vEN'] = 'defaultValue';
2807
2808 // There should be a templateRow for container_1 with defaultValue set for both languages
2809 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['templateRows']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
2810 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['templateRows']['container_1']['el']['aFlexField']['vEN'] = 'defaultValue';
2811
2812 $this->assertEquals($expected, $this->subject->addData($input));
2813 }
2814
2815 /**
2816 * @test
2817 */
2818 public function addDataMigratesFlexformTca() {
2819 $input = [
2820 'tableName' => 'aTable',
2821 'databaseRow' => [
2822 'aField' => [
2823 'data' => [],
2824 'meta' => [],
2825 ],
2826 'pointerField' => 'aFlex',
2827 ],
2828 'systemLanguageRows' => [
2829 0 => [
2830 'uid' => 0,
2831 'iso' => 'DEF',
2832 ],
2833 ],
2834 'processedTca' => [
2835 'columns' => [
2836 'aField' => [
2837 'config' => [
2838 'type' => 'flex',
2839 'ds_pointerField' => 'pointerField',
2840 'ds' => [
2841 'aFlex' => '
2842 <T3DataStructure>
2843 <ROOT>
2844 <type>array</type>
2845 <el>
2846 <aFlexField>
2847 <TCEforms>
2848 <label>aFlexFieldLabel</label>
2849 <config>
2850 <type>text</type>
2851 <default>defaultValue</default>
2852 <wizards type="array">
2853 <t3editor type="array">
2854 <type>userFunc</type>
2855 <userFunc>TYPO3\CMS\T3editor\FormWizard->main</userFunc>
2856 <title>t3editor</title>
2857 <icon>EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif</icon>
2858 <module type="array">
2859 <name>wizard_table</name>
2860 </module>
2861 <params type="array">
2862 <format>html</format>
2863 </params>
2864 </t3editor>
2865 </wizards>
2866 </config>
2867 </TCEforms>
2868 </aFlexField>
2869 </el>
2870 </ROOT>
2871 </T3DataStructure>
2872 ',
2873 ],
2874 ],
2875 ],
2876 ],
2877 ],
2878 'pageTsConfigMerged' => [],
2879 ];
2880
2881 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
2882 \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues::class => [],
2883 ];
2884
2885 /** @var LanguageService|ObjectProphecy $languageService */
2886 $languageService = $this->prophesize(LanguageService::class);
2887 $GLOBALS['LANG'] = $languageService->reveal();
2888 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2889
2890 $this->backendUserProphecy->isAdmin()->willReturn(TRUE);
2891 $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(TRUE);
2892
2893 $expected = $input;
2894 $expected['processedTca']['columns']['aField']['config']['ds'] = [
2895 'meta' => [
2896 'availableLanguageCodes' => [
2897 0 => 'DEF',
2898 ],
2899 'langDisable' => FALSE,
2900 'langChildren' => FALSE,
2901 'languagesOnSheetLevel' => [
2902 0 => 'DEF',
2903 ],
2904 'languagesOnElement' => [
2905 0 => 'DEF',
2906 ],
2907 ],
2908 'sheets' => [
2909 'sDEF' => [
2910 'ROOT' => [
2911 'type' => 'array',
2912 'el' => [
2913 'aFlexField' => [
2914 'label' => 'aFlexFieldLabel',
2915 'config' => [
2916 'type' => 'text',
2917 'default' => 'defaultValue',
2918 'renderType' => 't3editor',
2919 'format' => 'html',
2920 ],
2921 ],
2922 ],
2923 ],
2924 ],
2925 ],
2926 ];
2927
2928 $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vDEF'] = 'defaultValue';
2929
2930 $this->assertEquals($expected, $this->subject->addData($input));
2931 }
2932
2933 /**
2934 * @test
2935 */
2936 public function addDataMigratesFlexformTcaInContainer() {
2937 $input = [
2938 'tableName' => 'aTable',
2939 'databaseRow' => [
2940 'aField' => [
2941 'data' => [],
2942 'meta' => [],
2943 ],
2944 'pointerField' => 'aFlex',
2945 ],
2946 'systemLanguageRows' => [
2947 0 => [
2948 'uid' => 0,
2949 'iso' => 'DEF',
2950 ],
2951 ],
2952 'processedTca' => [
2953 'columns' => [
2954 'aField' => [
2955 'config' => [
2956 'type' => 'flex',
2957 'ds_pointerField' => 'pointerField',
2958 'ds' => [
2959 'aFlex'