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