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