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