‪TYPO3CMS  10.4
TcaFlexProcessTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪TcaFlexProcessTest extends UnitTestCase
33 {
37  protected ‪$backendUserProphecy;
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
43  $this->backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
44  ‪$GLOBALS['BE_USER'] = $this->backendUserProphecy->reveal();
45  ‪$GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
46 
47  // Some tests call FormDataCompiler for sub elements. Those tests have functional test characteristics.
48  // This is ok for the time being, but this settings takes care only parts of the compiler are called
49  // to have less dependencies.
50  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [];
51  }
52 
57  {
58  $input = [
59  'tableName' => 'aTable',
60  'effectivePid' => 1,
61  'databaseRow' => [],
62  'processedTca' => [
63  'columns' => [
64  'aField' => [
65  'config' => [
66  'type' => 'flex',
67  'ds' => [],
68  ],
69  ],
70  ],
71  ],
72  ];
73 
74  $this->expectException(\RuntimeException::class);
75  $this->expectExceptionCode(1480765571);
76  (new ‪TcaFlexProcess())->addData($input);
77  }
78 
83  {
84  $input = [
85  'tableName' => 'aTable',
86  'effectivePid' => 1,
87  'databaseRow' => [
88  'aField' => [
89  'data' => [],
90  ],
91  'pointerField' => 'aFlex',
92  ],
93  'processedTca' => [
94  'columns' => [
95  'aField' => [
96  'config' => [
97  'type' => 'flex',
98  'ds_pointerField' => 'pointerField',
99  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
100  'ds' => [
101  'sheets' => [
102  'aSheet' => [
103  'ROOT' => [
104  'type' => 'array',
105  'el' => [
106  'aFlexField' => [
107  'label' => 'aFlexFieldLabel',
108  'config' => [
109  'type' => 'input',
110  ],
111  ]
112  ],
113  ],
114  ],
115  ],
116  ],
117  ],
118  ],
119  ],
120  ],
121  'pageTsConfig' => [
122  'TCEFORM.' => [
123  'aTable.' => [
124  'aField.' => [
125  'aFlex.' => [
126  'aSheet.' => [
127  'disabled' => 1,
128  ],
129  ],
130  ],
131  ],
132  ],
133  ],
134  ];
135 
136  $expected = $input;
137  $expected['processedTca']['columns']['aField']['config']['ds'] = [
138  'sheets' => [],
139  ];
140 
141  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
142  }
143 
148  {
149  $input = [
150  'tableName' => 'aTable',
151  'effectivePid' => 1,
152  'selectTreeCompileItems' => false,
153  'databaseRow' => [
154  'uid' => 5,
155  'aField' => [
156  'data' => [],
157  ],
158  'pointerField' => 'aFlex',
159  ],
160  'processedTca' => [
161  'columns' => [
162  'aField' => [
163  'config' => [
164  'type' => 'flex',
165  'ds_pointerField' => 'pointerField',
166  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
167  'ds' => [
168  'sheets' => [
169  'aSheet' => [
170  'ROOT' => [
171  'type' => 'array',
172  'el' => [
173  'aFlexField' => [
174  'label' => 'aFlexFieldLabel',
175  'config' => [
176  'type' => 'input',
177  ],
178  ]
179  ],
180  ],
181  ],
182  ],
183  ],
184  ],
185  ],
186  ],
187  ],
188  'pageTsConfig' => [
189  'TCEFORM.' => [
190  'aTable.' => [
191  'aField.' => [
192  'aFlex.' => [
193  'aSheet.' => [
194  'sheetTitle' => 'aTitle',
195  ],
196  ],
197  ],
198  ],
199  ],
200  ],
201  ];
202 
203  $expected = $input;
204  $expected['processedTca']['columns']['aField']['config']['ds'] = [
205  'sheets' => [
206  'aSheet' => [
207  'ROOT' => [
208  'type' => 'array',
209  'el' => [
210  'aFlexField' => [
211  'label' => 'aFlexFieldLabel',
212  'config' => [
213  'type' => 'input',
214  ],
215  ],
216  ],
217  'sheetTitle' => 'aTitle',
218  ],
219  ],
220  ],
221  ];
222 
223  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
224  }
225 
230  {
231  $input = [
232  'tableName' => 'aTable',
233  'effectivePid' => 1,
234  'selectTreeCompileItems' => false,
235  'databaseRow' => [
236  'uid' => 5,
237  'aField' => [
238  'data' => [],
239  ],
240  'pointerField' => 'aFlex',
241  ],
242  'processedTca' => [
243  'columns' => [
244  'aField' => [
245  'config' => [
246  'type' => 'flex',
247  'ds_pointerField' => 'pointerField',
248  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
249  'ds' => [
250  'sheets' => [
251  'aSheet' => [
252  'ROOT' => [
253  'type' => 'array',
254  'el' => [
255  'aFlexField' => [
256  'label' => 'aFlexFieldLabel',
257  'config' => [
258  'type' => 'input',
259  ],
260  ]
261  ],
262  ],
263  ],
264  ],
265  ],
266  ],
267  ],
268  ],
269  ],
270  'pageTsConfig' => [
271  'TCEFORM.' => [
272  'aTable.' => [
273  'aField.' => [
274  'aFlex.' => [
275  'aSheet.' => [
276  'sheetDescription' => 'aDescription',
277  ],
278  ],
279  ],
280  ],
281  ],
282  ],
283  ];
284 
285  $expected = $input;
286  $expected['processedTca']['columns']['aField']['config']['ds'] = [
287  'sheets' => [
288  'aSheet' => [
289  'ROOT' => [
290  'type' => 'array',
291  'el' => [
292  'aFlexField' => [
293  'label' => 'aFlexFieldLabel',
294  'config' => [
295  'type' => 'input',
296  ],
297  ],
298  ],
299  'sheetDescription' => 'aDescription',
300  ],
301  ],
302  ],
303  ];
304 
305  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
306  }
307 
312  {
313  $input = [
314  'tableName' => 'aTable',
315  'effectivePid' => 1,
316  'selectTreeCompileItems' => false,
317  'databaseRow' => [
318  'uid' => 5,
319  'aField' => [
320  'data' => [],
321  ],
322  'pointerField' => 'aFlex',
323  ],
324  'processedTca' => [
325  'columns' => [
326  'aField' => [
327  'config' => [
328  'type' => 'flex',
329  'ds_pointerField' => 'pointerField',
330  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
331  'ds' => [
332  'sheets' => [
333  'aSheet' => [
334  'ROOT' => [
335  'type' => 'array',
336  'el' => [
337  'aFlexField' => [
338  'label' => 'aFlexFieldLabel',
339  'config' => [
340  'type' => 'input',
341  ],
342  ]
343  ],
344  ],
345  ],
346  ],
347  ],
348  ],
349  ],
350  ],
351  ],
352  'pageTsConfig' => [
353  'TCEFORM.' => [
354  'aTable.' => [
355  'aField.' => [
356  'aFlex.' => [
357  'aSheet.' => [
358  'sheetDescription' => 'sheetShortDescr',
359  ],
360  ],
361  ],
362  ],
363  ],
364  ],
365  ];
366 
367  $expected = $input;
368  $expected['processedTca']['columns']['aField']['config']['ds'] = [
369  'sheets' => [
370  'aSheet' => [
371  'ROOT' => [
372  'type' => 'array',
373  'el' => [
374  'aFlexField' => [
375  'label' => 'aFlexFieldLabel',
376  'config' => [
377  'type' => 'input',
378  ],
379  ],
380  ],
381  'sheetDescription' => 'sheetShortDescr',
382  ],
383  ],
384  ],
385  ];
386 
387  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
388  }
389 
394  {
395  $input = [
396  'tableName' => 'aTable',
397  'effectivePid' => 1,
398  'selectTreeCompileItems' => false,
399  'databaseRow' => [
400  'uid' => 5,
401  'aField' => [
402  'data' => [],
403  ],
404  'pointerField' => 'aFlex',
405  ],
406  'processedTca' => [
407  'columns' => [
408  'aField' => [
409  'config' => [
410  'type' => 'flex',
411  'ds_pointerField' => 'pointerField',
412  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
413  'ds' => [
414  'sheets' => [
415  'sDEF' => [
416  'ROOT' => [
417  'type' => 'array',
418  'el' => [
419  'aFlexField' => [
420  'label' => 'aFlexFieldLabel',
421  'config' => [
422  'type' => 'input',
423  ],
424  ]
425  ],
426  ],
427  ],
428  ],
429  ],
430  ],
431  ],
432  ],
433  ],
434  'pageTsConfig' => [
435  'TCEFORM.' => [
436  'aTable.' => [
437  'aField.' => [
438  'aFlex.' => [
439  'sDEF.' => [
440  'sheetDescription' => 'sheetShortDescr',
441  ],
442  ],
443  ],
444  ],
445  ],
446  ],
447  ];
448 
449  $expected = $input;
450  $expected['processedTca']['columns']['aField']['config']['ds'] = [
451  'sheets' => [
452  'sDEF' => [
453  'ROOT' => [
454  'type' => 'array',
455  'el' => [
456  'aFlexField' => [
457  'label' => 'aFlexFieldLabel',
458  'config' => [
459  'type' => 'input',
460  ],
461  ],
462  ],
463  'sheetDescription' => 'sheetShortDescr',
464  ],
465  ],
466  ],
467  ];
468 
469  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
470  }
471 
476  {
477  $input = [
478  'tableName' => 'aTable',
479  'effectivePid' => 1,
480  'selectTreeCompileItems' => false,
481  'databaseRow' => [
482  'uid' => 5,
483  'aField' => [
484  'data' => [],
485  ],
486  'pointerField' => 'aFlex',
487  ],
488  'processedTca' => [
489  'columns' => [
490  'aField' => [
491  'config' => [
492  'type' => 'flex',
493  'ds_pointerField' => 'pointerField',
494  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
495  'ds' => [
496  'sheets' => [
497  'sDEF' => [
498  'ROOT' => [
499  'type' => 'array',
500  'el' => [
501  'aFlexField' => [
502  'label' => 'aFlexFieldLabel',
503  'exclude' => '1',
504  'config' => [
505  'type' => 'input',
506  ],
507  ]
508  ],
509  ],
510  ],
511  ],
512  ],
513  ],
514  ],
515  ],
516  ],
517  'pageTsConfig' => [],
518  ];
519 
520  $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(false);
521  ‪$GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
522 
523  $expected = $input;
524  $expected['processedTca']['columns']['aField']['config']['ds'] = [
525  'sheets' => [
526  'sDEF' => [
527  'ROOT' => [
528  'type' => 'array',
529  'el' => [],
530  ],
531  ],
532  ],
533  ];
534 
535  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
536  }
537 
542  {
543  $input = [
544  'tableName' => 'aTable',
545  'effectivePid' => 1,
546  'selectTreeCompileItems' => false,
547  'databaseRow' => [
548  'uid' => 5,
549  'aField' => [
550  'data' => [],
551  ],
552  'pointerField' => 'aFlex',
553  ],
554  'processedTca' => [
555  'columns' => [
556  'aField' => [
557  'config' => [
558  'type' => 'flex',
559  'ds_pointerField' => 'pointerField',
560  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
561  'ds' => [
562  'sheets' => [
563  'sDEF' => [
564  'ROOT' => [
565  'type' => 'array',
566  'el' => [
567  'aFlexField' => [
568  'label' => 'aFlexFieldLabel',
569  'exclude' => '1',
570  'config' => [
571  'type' => 'input',
572  ],
573  ]
574  ],
575  ],
576  ],
577  ],
578  ],
579  ],
580  ],
581  ],
582  ],
583  'pageTsConfig' => [],
584  ];
585 
586  $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(false);
587  ‪$GLOBALS['BE_USER']->groupData['non_exclude_fields'] = 'aTable:aField;aFlex;sDEF;aFlexField';
588 
589  $expected = $input;
590  $expected['processedTca']['columns']['aField']['config']['ds'] = [
591  'sheets' => [
592  'sDEF' => [
593  'ROOT' => [
594  'type' => 'array',
595  'el' => [
596  'aFlexField' => [
597  'label' => 'aFlexFieldLabel',
598  'config' => [
599  'type' => 'input',
600  ],
601  'exclude' => '1',
602  ],
603  ],
604  ],
605  ],
606  ],
607  ];
608 
609  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
610  }
611 
616  {
617  $input = [
618  'tableName' => 'aTable',
619  'effectivePid' => 1,
620  'selectTreeCompileItems' => false,
621  'databaseRow' => [
622  'uid' => 5,
623  'aField' => [
624  'data' => [],
625  ],
626  'pointerField' => 'aFlex',
627  ],
628  'processedTca' => [
629  'columns' => [
630  'aField' => [
631  'config' => [
632  'type' => 'flex',
633  'ds_pointerField' => 'pointerField',
634  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
635  'ds' => [
636  'sheets' => [
637  'sDEF' => [
638  'ROOT' => [
639  'type' => 'array',
640  'el' => [
641  'aFlexField' => [
642  'label' => 'aFlexFieldLabel',
643  'exclude' => '1',
644  'config' => [
645  'type' => 'input',
646  ],
647  ]
648  ],
649  ],
650  ],
651  ],
652  ],
653  ],
654  ],
655  ],
656  ],
657  'pageTsConfig' => [],
658  ];
659 
660  $this->backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(true);
661  ‪$GLOBALS['BE_USER']->groupData['non_exclude_fields'] = '';
662 
663  $expected = $input;
664  $expected['processedTca']['columns']['aField']['config']['ds'] = [
665  'sheets' => [
666  'sDEF' => [
667  'ROOT' => [
668  'type' => 'array',
669  'el' => [
670  'aFlexField' => [
671  'label' => 'aFlexFieldLabel',
672  'config' => [
673  'type' => 'input',
674  ],
675  'exclude' => '1',
676  ],
677  ],
678  ],
679  ],
680  ],
681  ];
682 
683  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
684  }
685 
690  {
691  $input = [
692  'tableName' => 'aTable',
693  'selectTreeCompileItems' => false,
694  'effectivePid' => 1,
695  'databaseRow' => [
696  'uid' => 5,
697  'aField' => [
698  'data' => [],
699  ],
700  'pointerField' => 'aFlex',
701  ],
702  'processedTca' => [
703  'columns' => [
704  'aField' => [
705  'config' => [
706  'type' => 'flex',
707  'ds_pointerField' => 'pointerField',
708  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
709  'ds' => [
710  'sheets' => [
711  'sDEF' => [
712  'ROOT' => [
713  'type' => 'array',
714  'el' => [
715  'aFlexField' => [
716  'label' => 'aFlexFieldLabel',
717  'config' => [
718  'type' => 'input',
719  ],
720  ]
721  ],
722  ],
723  ],
724  ],
725  ],
726  ],
727  ],
728  ],
729  ],
730  'pageTsConfig' => [
731  'TCEFORM.' => [
732  'aTable.' => [
733  'aField.' => [
734  'aFlex.' => [
735  'sDEF.' => [
736  'aFlexField.' => [
737  'disabled' => 1,
738  ],
739  ],
740  ],
741  ],
742  ],
743  ],
744  ],
745  ];
746 
747  $expected = $input;
748  $expected['processedTca']['columns']['aField']['config']['ds'] = [
749  'sheets' => [
750  'sDEF' => [
751  'ROOT' => [
752  'type' => 'array',
753  'el' => [],
754  ],
755  ],
756  ],
757  ];
758 
759  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
760  }
761 
766  {
767  $input = [
768  'tableName' => 'aTable',
769  'selectTreeCompileItems' => false,
770  'effectivePid' => 1,
771  'databaseRow' => [
772  'uid' => 5,
773  'aField' => [
774  'data' => [],
775  ],
776  'pointerField' => 'aFlex',
777  ],
778  'processedTca' => [
779  'columns' => [
780  'aField' => [
781  'config' => [
782  'type' => 'flex',
783  'ds_pointerField' => 'pointerField',
784  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
785  'ds' => [
786  'sheets' => [
787  'sDEF' => [
788  'ROOT' => [
789  'type' => 'array',
790  'el' => [
791  'aFlexField' => [
792  'label' => 'aFlexFieldLabel',
793  'config' => [
794  'type' => 'radio',
795  'items' => [
796  0 => [
797  0 => 'aLabel',
798  1 => 'aValue',
799  ],
800  ],
801  ],
802  ],
803  ],
804  ],
805  ],
806  ],
807  ],
808  ],
809  ],
810  ],
811  ],
812  'pageTsConfig' => [
813  'TCEFORM.' => [
814  'aTable.' => [
815  'aField.' => [
816  'aFlex.' => [
817  'sDEF.' => [
818  'aFlexField.' => [
819  'altLabels.' => [
820  '0' => 'labelOverride',
821  ],
822  ],
823  ],
824  ],
825  ],
826  ],
827  ],
828  ],
829  ];
830 
831  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
832  TcaRadioItems::class => [],
833  ];
834 
836  $languageService = $this->prophesize(LanguageService::class);
837  ‪$GLOBALS['LANG'] = $languageService->reveal();
838  $languageService->sL(Argument::cetera())->willReturnArgument(0);
839 
840  $this->backendUserProphecy->isAdmin()->willReturn(true);
841  $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(true);
842 
843  $expected = $input;
844  $expected['processedTca']['columns']['aField']['config']['ds'] = [
845  'sheets' => [
846  'sDEF' => [
847  'ROOT' => [
848  'type' => 'array',
849  'el' => [
850  'aFlexField' => [
851  'label' => 'aFlexFieldLabel',
852  'config' => [
853  'type' => 'radio',
854  'items' => [
855  0 => [
856  0 => 'labelOverride',
857  1 => 'aValue',
858  ],
859  ],
860  ],
861  ],
862  ],
863  ],
864  ],
865  ],
866  ];
867 
868  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
869  }
870 
875  {
876  $input = [
877  'tableName' => 'aTable',
878  'effectivePid' => 1,
879  'selectTreeCompileItems' => false,
880  'databaseRow' => [
881  'uid' => 5,
882  'aField' => [
883  'data' => [],
884  ],
885  'pointerField' => 'aFlex',
886  ],
887  'processedTca' => [
888  'columns' => [
889  'aField' => [
890  'config' => [
891  'type' => 'flex',
892  'ds_pointerField' => 'pointerField',
893  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
894  'ds' => [
895  'sheets' => [
896  'sDEF' => [
897  'ROOT' => [
898  'type' => 'array',
899  'el' => [
900  'aFlexField' => [
901  'label' => 'aFlexFieldLabel',
902  'config' => [
903  'type' => 'input',
904  'default' => 'defaultValue',
905  ],
906  ],
907  ],
908  ],
909  ],
910  ],
911  ],
912  ],
913  ],
914  ],
915  ],
916  'pageTsConfig' => [],
917  ];
918 
919  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
920  DatabaseRowDefaultValues::class => [],
921  ];
922 
924  $languageService = $this->prophesize(LanguageService::class);
925  ‪$GLOBALS['LANG'] = $languageService->reveal();
926  $languageService->sL(Argument::cetera())->willReturnArgument(0);
927 
928  $this->backendUserProphecy->isAdmin()->willReturn(true);
929  $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(true);
930 
931  $expected = $input;
932  $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['aFlexField']['vDEF'] = 'defaultValue';
933 
934  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
935  }
936 
941  {
942  $input = [
943  'tableName' => 'aTable',
944  'effectivePid' => 1,
945  'databaseRow' => [
946  'aField' => [
947  'data' => [],
948  'meta' => [],
949  ],
950  ],
951  'processedTca' => [
952  'columns' => [
953  'aField' => [
954  'config' => [
955  'type' => 'flex',
956  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
957  'ds' => [
958  'sheets' => [
959  'sDEF' => [
960  'ROOT' => [
961  'type' => 'array',
962  'el' => [
963  'aFlexField' => [
964  'type' => 'array',
965  ],
966  ],
967  ],
968  ],
969  ],
970  ],
971  ],
972  ],
973  ],
974  ],
975  'pageTsConfig' => [],
976  ];
977 
978  $this->backendUserProphecy->isAdmin()->willReturn(true);
979  $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(true);
980 
981  $this->expectException(\UnexpectedValueException::class);
982  $this->expectExceptionCode(1440685208);
983 
984  (new TcaFlexProcess())->addData($input);
985  }
986 
991  {
992  $input = [
993  'tableName' => 'aTable',
994  'effectivePid' => 1,
995  'databaseRow' => [
996  'aField' => [
997  'data' => [],
998  'meta' => [],
999  ],
1000  ],
1001  'processedTca' => [
1002  'columns' => [
1003  'aField' => [
1004  'config' => [
1005  'type' => 'flex',
1006  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1007  'ds' => [
1008  'sheets' => [
1009  'sDEF' => [
1010  'ROOT' => [
1011  'type' => 'array',
1012  'el' => [
1013  'aFlexField' => [
1014  'section' => '1',
1015  ],
1016  ],
1017  ],
1018  ],
1019  ],
1020  ],
1021  ],
1022  ],
1023  ],
1024  ],
1025  'pageTsConfig' => [],
1026  ];
1027 
1028  $this->backendUserProphecy->isAdmin()->willReturn(true);
1029  $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(true);
1030 
1031  $this->expectException(\UnexpectedValueException::class);
1032  $this->expectExceptionCode(1440685208);
1033 
1034  (new TcaFlexProcess())->addData($input);
1035  }
1036 
1041  {
1042  $input = [
1043  'tableName' => 'aTable',
1044  'effectivePid' => 1,
1045  'selectTreeCompileItems' => false,
1046  'databaseRow' => [
1047  'uid' => 5,
1048  'aField' => [
1049  'data' => [
1050  'sDEF' => [
1051  'lDEF' => [
1052  'section_1' => [
1053  'el' => [
1054  '1' => [
1055  'container_1' => [
1056  // It should set the default value for aFlexField here
1057  'el' => [
1058  ],
1059  ],
1060  ],
1061  '2' => [
1062  'container_1' => [
1063  'el' => [
1064  'aFlexField' => [
1065  // It should keep this value
1066  'vDEF' => 'dbValue',
1067  ],
1068  ],
1069  ],
1070  ],
1071  ],
1072  ],
1073  ],
1074  ],
1075  ],
1076  'meta' => [],
1077  ],
1078  ],
1079  'processedTca' => [
1080  'columns' => [
1081  'aField' => [
1082  'config' => [
1083  'type' => 'flex',
1084  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1085  'ds' => [
1086  'sheets' => [
1087  'sDEF' => [
1088  'ROOT' => [
1089  'type' => 'array',
1090  'el' => [
1091  'section_1' => [
1092  'section' => '1',
1093  'type' => 'array',
1094  'el' => [
1095  'container_1' => [
1096  'type' => 'array',
1097  'el' => [
1098  'aFlexField' => [
1099  'label' => 'aFlexFieldLabel',
1100  'config' => [
1101  'type' => 'input',
1102  'default' => 'defaultValue',
1103  ],
1104  ],
1105  ],
1106  ],
1107  ],
1108  ],
1109  ],
1110  ],
1111  ],
1112  ],
1113  ],
1114  ],
1115  ],
1116  ],
1117  ],
1118  'pageTsConfig' => [],
1119  ];
1120 
1121  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
1122  DatabaseRowDefaultValues::class => [],
1123  ];
1124 
1126  $languageService = $this->prophesize(LanguageService::class);
1127  ‪$GLOBALS['LANG'] = $languageService->reveal();
1128  $languageService->sL(Argument::cetera())->willReturnArgument(0);
1129 
1130  $this->backendUserProphecy->isAdmin()->willReturn(true);
1131  $this->backendUserProphecy->checkLanguageAccess(Argument::cetera())->willReturn(true);
1132 
1133  $expected = $input;
1134 
1135  // A default value for existing container field aFlexField should have been set
1136  $expected['databaseRow']['aField']['data']['sDEF']['lDEF']['section_1']['el']['1']['container_1']['el']['aFlexField']['vDEF'] = 'defaultValue';
1137 
1138  // Data structure of given containers is copied over to "children" referencing the existing container name
1139  $expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sDEF']['ROOT']['el']['section_1']['children']['1']
1140  = $expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sDEF']['ROOT']['el']['section_1']['el']['container_1'];
1141  $expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sDEF']['ROOT']['el']['section_1']['children']['2']
1142  = $expected['processedTca']['columns']['aField']['config']['ds']['sheets']['sDEF']['ROOT']['el']['section_1']['el']['container_1'];
1143 
1144  self::assertEquals($expected, (new TcaFlexProcess())->addData($input));
1145  }
1146 
1151  {
1152  $input = [
1153  'tableName' => 'aTable',
1154  'effectivePid' => 1,
1155  'databaseRow' => [
1156  'aField' => [
1157  'data' => [],
1158  ],
1159  'pointerField' => 'aFlex',
1160  ],
1161  'processedTca' => [
1162  'columns' => [
1163  'aField' => [
1164  'config' => [
1165  'type' => 'flex',
1166  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1167  'ds' => [
1168  'sheets' => [
1169  'sDEF' => [
1170  'ROOT' => [
1171  'type' => 'array',
1172  'el' => [
1173  'section_1' => [
1174  'section' => '1',
1175  'type' => 'array',
1176  'el' => [
1177  'container_1' => [
1178  'type' => 'array',
1179  'el' => [
1180  'aFlexField' => [
1181  'label' => 'aFlexFieldLabel',
1182  'config' => [
1183  'type' => 'inline',
1184  ],
1185  ],
1186  ],
1187  ],
1188  ],
1189  ],
1190  ],
1191  ],
1192  ],
1193  ],
1194  ],
1195  ],
1196  ],
1197  ],
1198  ],
1199  'pageTsConfig' => [],
1200  ];
1201 
1202  $this->expectException(\UnexpectedValueException::class);
1203  $this->expectExceptionCode(1458745468);
1204 
1205  (new TcaFlexProcess())->addData($input);
1206  }
1207 
1212  {
1213  $input = [
1214  'tableName' => 'aTable',
1215  'effectivePid' => 1,
1216  'databaseRow' => [
1217  'aField' => [
1218  'data' => [],
1219  ],
1220  'pointerField' => 'aFlex',
1221  ],
1222  'processedTca' => [
1223  'columns' => [
1224  'aField' => [
1225  'config' => [
1226  'type' => 'flex',
1227  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1228  'ds' => [
1229  'sheets' => [
1230  'sDEF' => [
1231  'ROOT' => [
1232  'type' => 'array',
1233  'el' => [
1234  'section_1' => [
1235  'section' => '1',
1236  'type' => 'array',
1237  'el' => [
1238  'container_1' => [
1239  'type' => 'array',
1240  'el' => [
1241  'section_nested' => [
1242  'section' => '1',
1243  'type' => 'array',
1244  'el' => [
1245  ],
1246  ],
1247  ],
1248  ],
1249  ],
1250  ],
1251  ],
1252  ],
1253  ],
1254  ],
1255  ],
1256  ],
1257  ],
1258  ],
1259  ],
1260  'pageTsConfig' => [],
1261  ];
1262 
1263  $this->expectException(\UnexpectedValueException::class);
1264  $this->expectExceptionCode(1458745712);
1265 
1266  (new TcaFlexProcess())->addData($input);
1267  }
1268 
1273  {
1274  $input = [
1275  'tableName' => 'aTable',
1276  'effectivePid' => 1,
1277  'databaseRow' => [
1278  'aField' => [
1279  'data' => [],
1280  ],
1281  'pointerField' => 'aFlex',
1282  ],
1283  'processedTca' => [
1284  'columns' => [
1285  'aField' => [
1286  'config' => [
1287  'type' => 'flex',
1288  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1289  'ds' => [
1290  'sheets' => [
1291  'sDEF' => [
1292  'ROOT' => [
1293  'type' => 'array',
1294  'el' => [
1295  'section_1' => [
1296  'section' => '1',
1297  'type' => 'array',
1298  'el' => [
1299  'container_1' => [
1300  'type' => 'array',
1301  'el' => [
1302  'section_nested' => [
1303  'config' => [
1304  'type' => 'select',
1305  'MM' => '',
1306  ],
1307  ],
1308  ],
1309  ],
1310  ],
1311  ],
1312  ],
1313  ],
1314  ],
1315  ],
1316  ],
1317  ],
1318  ],
1319  ],
1320  ],
1321  'pageTsConfig' => [],
1322  ];
1323 
1324  $this->expectException(\UnexpectedValueException::class);
1325  $this->expectExceptionCode(1481647089);
1326 
1327  (new TcaFlexProcess())->addData($input);
1328  }
1329 
1334  {
1335  $input = [
1336  'tableName' => 'aTable',
1337  'effectivePid' => 1,
1338  'databaseRow' => [
1339  'aField' => [
1340  'data' => [],
1341  ],
1342  'pointerField' => 'aFlex',
1343  ],
1344  'processedTca' => [
1345  'columns' => [
1346  'aField' => [
1347  'config' => [
1348  'type' => 'flex',
1349  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1350  'ds' => [
1351  'sheets' => [
1352  'sDEF' => [
1353  'ROOT' => [
1354  'type' => 'array',
1355  'el' => [
1356  'section_1' => [
1357  'section' => '1',
1358  'type' => 'array',
1359  'el' => [
1360  'container_1' => [
1361  'type' => 'array',
1362  'el' => [
1363  'section_nested' => [
1364  'config' => [
1365  'type' => 'group',
1366  'MM' => '',
1367  ],
1368  ],
1369  ],
1370  ],
1371  ],
1372  ],
1373  ],
1374  ],
1375  ],
1376  ],
1377  ],
1378  ],
1379  ],
1380  ],
1381  ],
1382  'pageTsConfig' => [],
1383  ];
1384 
1385  $this->expectException(\UnexpectedValueException::class);
1386  $this->expectExceptionCode(1481647089);
1387 
1388  (new TcaFlexProcess())->addData($input);
1389  }
1390 
1395  {
1396  $input = [
1397  'tableName' => 'aTable',
1398  'selectTreeCompileItems' => false,
1399  'effectivePid' => 1,
1400  'databaseRow' => [
1401  'uid' => 5,
1402  'aField' => [
1403  'data' => [],
1404  ],
1405  'pointerField' => 'aFlex',
1406  ],
1407  'processedTca' => [
1408  'columns' => [
1409  'aField' => [
1410  'config' => [
1411  'type' => 'flex',
1412  'ds_pointerField' => 'pointerField',
1413  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1414  'ds' => [
1415  'sheets' => [
1416  'sDEF' => [
1417  'ROOT' => [
1418  'type' => 'array',
1419  'el' => [
1420  'aFlexField' => [
1421  'label' => 'aFlexFieldLabel',
1422  'config' => [
1423  'type' => 'input',
1424  ],
1425  ],
1426  ],
1427  ],
1428  ],
1429  ],
1430  ],
1431  ],
1432  ],
1433  ],
1434  ],
1435  'pageTsConfig' => [],
1436  ];
1437 
1439  $dummyGroup = $this->prophesize(FlexFormSegment::class);
1440  GeneralUtility::addInstance(FlexFormSegment::class, $dummyGroup->reveal());
1441 
1442  // Check array given to flex group contains databaseRow as flexParentDatabaseRow and check compile is called
1443  $dummyGroup->compile(Argument::that(function ($result) use ($input) {
1444  if ($result['flexParentDatabaseRow'] === $input['databaseRow']) {
1445  return true;
1446  }
1447  return false;
1448  }))->shouldBeCalled()->willReturnArgument(0);
1449 
1450  (new TcaFlexProcess())->addData($input);
1451  }
1452 
1457  {
1458  $input = [
1459  'tableName' => 'aTable',
1460  'selectTreeCompileItems' => false,
1461  'effectivePid' => 1,
1462  'databaseRow' => [
1463  'uid' => 5,
1464  'aField' => [
1465  'data' => [],
1466  ],
1467  'pointerField' => 'aFlex',
1468  ],
1469  'processedTca' => [
1470  'columns' => [
1471  'aField' => [
1472  'config' => [
1473  'type' => 'flex',
1474  'ds_pointerField' => 'pointerField',
1475  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTable","fieldName":"aField","dataStructureKey":"aFlex"}',
1476  'ds' => [
1477  'sheets' => [
1478  'sDEF' => [
1479  'ROOT' => [
1480  'type' => 'array',
1481  'el' => [
1482  'aFlexField' => [
1483  'label' => 'aFlexFieldLabel',
1484  'config' => [
1485  'type' => 'input',
1486  ],
1487  ],
1488  ],
1489  ],
1490  ],
1491  ],
1492  ],
1493  ],
1494  ],
1495  ],
1496  ],
1497  'pageTsConfig' => [],
1498  ];
1499 
1501  $dummyGroupExisting = $this->prophesize(FlexFormSegment::class);
1502  GeneralUtility::addInstance(FlexFormSegment::class, $dummyGroupExisting->reveal());
1503  // Check array given to flex group contains databaseRow as flexParentDatabaseRow and check compile is called
1504  $dummyGroupExisting->compile(Argument::that(function ($result) use ($input) {
1505  if ($result['flexParentDatabaseRow'] === $input['databaseRow']) {
1506  return true;
1507  }
1508  return false;
1509  }))->shouldBeCalled()->willReturnArgument(0);
1510 
1511  (new TcaFlexProcess())->addData($input);
1512  }
1513 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataKeepsExcludeFieldInDataStructureWithUserAccess
‪addDataKeepsExcludeFieldInDataStructureWithUserAccess()
Definition: TcaFlexProcessTest.php:540
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues
Definition: DatabaseRowDefaultValues.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsValuesAndStructureForSectionContainerElements
‪addDataSetsValuesAndStructureForSectionContainerElements()
Definition: TcaFlexProcessTest.php:1039
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsSheetShortDescriptionForSingleSheetFromPageTsConfig
‪addDataSetsSheetShortDescriptionForSingleSheetFromPageTsConfig()
Definition: TcaFlexProcessTest.php:392
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexProcess
Definition: TcaFlexProcess.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionWithMissingDataStructureIdentifier
‪addDataThrowsExceptionWithMissingDataStructureIdentifier()
Definition: TcaFlexProcessTest.php:55
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForDataStructureTypeArrayWithoutSection
‪addDataThrowsExceptionForDataStructureTypeArrayWithoutSection()
Definition: TcaFlexProcessTest.php:939
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataKeepsExcludeFieldInDataStructureForAdminUser
‪addDataKeepsExcludeFieldInDataStructureForAdminUser()
Definition: TcaFlexProcessTest.php:614
‪TYPO3\CMS\Backend\Form\FormDataGroup\FlexFormSegment
Definition: FlexFormSegment.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsSheetShortDescriptionFromPageTsConfig
‪addDataSetsSheetShortDescriptionFromPageTsConfig()
Definition: TcaFlexProcessTest.php:310
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForSelectElementsInSectionContainers
‪addDataThrowsExceptionForSelectElementsInSectionContainers()
Definition: TcaFlexProcessTest.php:1271
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\setUp
‪setUp()
Definition: TcaFlexProcessTest.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataCallsFlexFormSegmentGroupForFieldAndAddsFlexParentDatabaseRow
‪addDataCallsFlexFormSegmentGroupForFieldAndAddsFlexParentDatabaseRow()
Definition: TcaFlexProcessTest.php:1393
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsDefaultValueFromFlexTcaForField
‪addDataSetsDefaultValueFromFlexTcaForField()
Definition: TcaFlexProcessTest.php:873
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsSheetTitleFromPageTsConfig
‪addDataSetsSheetTitleFromPageTsConfig()
Definition: TcaFlexProcessTest.php:146
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataRemovesSheetIfDisabledByPageTsConfig
‪addDataRemovesSheetIfDisabledByPageTsConfig()
Definition: TcaFlexProcessTest.php:81
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataSetsSheetDescriptionFromPageTsConfig
‪addDataSetsSheetDescriptionFromPageTsConfig()
Definition: TcaFlexProcessTest.php:228
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForInlineElementsNestedInSectionContainers
‪addDataThrowsExceptionForInlineElementsNestedInSectionContainers()
Definition: TcaFlexProcessTest.php:1149
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest
Definition: TcaFlexProcessTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForNestedSectionContainers
‪addDataThrowsExceptionForNestedSectionContainers()
Definition: TcaFlexProcessTest.php:1210
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForDataStructureSectionWithoutTypeArray
‪addDataThrowsExceptionForDataStructureSectionWithoutTypeArray()
Definition: TcaFlexProcessTest.php:989
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataRemovesPageTsDisabledFieldFromDataStructure
‪addDataRemovesPageTsDisabledFieldFromDataStructure()
Definition: TcaFlexProcessTest.php:688
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataRemovesExcludeFieldFromDataStructure
‪addDataRemovesExcludeFieldFromDataStructure()
Definition: TcaFlexProcessTest.php:474
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataHandlesPageTsConfigSettingsOfSingleFlexField
‪addDataHandlesPageTsConfigSettingsOfSingleFlexField()
Definition: TcaFlexProcessTest.php:764
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataThrowsExceptionForGroupElementsInSectionContainers
‪addDataThrowsExceptionForGroupElementsInSectionContainers()
Definition: TcaFlexProcessTest.php:1332
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\$backendUserProphecy
‪BackendUserAuthentication ObjectProphecy $backendUserProphecy
Definition: TcaFlexProcessTest.php:36
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems
Definition: TcaRadioItems.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexProcessTest\addDataCallsFlexFormSegmentGroupForDummyContainerAndAddsFlexParentDatabaseRow
‪addDataCallsFlexFormSegmentGroupForDummyContainerAndAddsFlexParentDatabaseRow()
Definition: TcaFlexProcessTest.php:1455