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