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