TYPO3 CMS  TYPO3_8-7
TcaInlineConfigurationTest.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 
18 
22 class TcaInlineConfigurationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $subject;
28 
29  protected function setUp()
30  {
31  $this->subject = new TcaInlineConfiguration();
32  }
33 
37  protected $defaultConfig = [
38  'type' => 'inline',
39  'foreign_table' => 'aForeignTableName',
40  'minitems' => 0,
41  'maxitems' => 99999,
42  'behaviour' => [
43  'localizationMode' => 'none',
44  ],
45  'appearance' => [
46  'levelLinksPosition' => 'top',
47  'showPossibleLocalizationRecords' => false,
48  'showRemovedLocalizationRecords' => false,
49  'enabledControls' => [
50  'info' => true,
51  'new' => true,
52  'dragdrop' => true,
53  'sort' => true,
54  'hide' => true,
55  'delete' => true,
56  'localize' => true,
57  ],
58  ],
59  ];
60 
65  {
66  $input = [
67  'databaseRow' => [],
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => [
72  'type' => 'inline',
73  ],
74  ],
75  ],
76  ],
77  ];
78  $this->expectException(\UnexpectedValueException::class);
79  $this->expectExceptionCode(1443793404);
80  $this->subject->addData($input);
81  }
82 
86  public function addDataSetsDefaults()
87  {
88  $input = [
89  'processedTca' => [
90  'columns' => [
91  'aField' => [
92  'config' => [
93  'type' => 'inline',
94  'foreign_table' => 'aForeignTableName',
95  ],
96  ],
97  ],
98  ],
99  ];
100  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
101  $this->assertEquals($expected, $this->subject->addData($input));
102  }
103 
107  public function addDataKeepsGivenMinitems()
108  {
109  $input = [
110  'processedTca' => [
111  'columns' => [
112  'aField' => [
113  'config' => [
114  'type' => 'inline',
115  'foreign_table' => 'aForeignTableName',
116  'minitems' => 23,
117  ],
118  ],
119  ],
120  ],
121  ];
122  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
123  $expected['processedTca']['columns']['aField']['config']['minitems'] = 23;
124  $this->assertEquals($expected, $this->subject->addData($input));
125  }
126 
131  {
132  $input = [
133  'processedTca' => [
134  'columns' => [
135  'aField' => [
136  'config' => [
137  'type' => 'inline',
138  'foreign_table' => 'aForeignTableName',
139  'minitems' => -23,
140  ],
141  ],
142  ],
143  ],
144  ];
145  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
146  $expected['processedTca']['columns']['aField']['config']['minitems'] = 0;
147  $this->assertEquals($expected, $this->subject->addData($input));
148  }
149 
153  public function addDataKeepsGivenMaxitems()
154  {
155  $input = [
156  'processedTca' => [
157  'columns' => [
158  'aField' => [
159  'config' => [
160  'type' => 'inline',
161  'foreign_table' => 'aForeignTableName',
162  'maxitems' => 23,
163  ],
164  ],
165  ],
166  ],
167  ];
168  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
169  $expected['processedTca']['columns']['aField']['config']['maxitems'] = 23;
170  $this->assertEquals($expected, $this->subject->addData($input));
171  }
172 
177  {
178  $input = [
179  'processedTca' => [
180  'columns' => [
181  'aField' => [
182  'config' => [
183  'type' => 'inline',
184  'foreign_table' => 'aForeignTableName',
185  'maxitems' => '-23',
186  ],
187  ],
188  ],
189  ],
190  ];
191  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
192  $expected['processedTca']['columns']['aField']['config']['maxitems'] = 1;
193  $this->assertEquals($expected, $this->subject->addData($input));
194  }
195 
200  {
201  $input = [
202  'defaultLanguageRow' => [],
203  'processedTca' => [
204  'columns' => [
205  'aField' => [
206  'config' => [
207  'type' => 'inline',
208  'foreign_table' => 'aForeignTableName',
209  'behaviour' => [
210  'localizationMode' => 'foo',
211  ]
212  ],
213  ],
214  ],
215  ],
216  ];
217  $this->expectException(\UnexpectedValueException::class);
218  $this->expectExceptionCode(1443829370);
219  $this->subject->addData($input);
220  }
221 
226  {
227  $input = [
228  'defaultLanguageRow' => [],
229  'processedTca' => [
230  'columns' => [
231  'aField' => [
232  'config' => [
233  'type' => 'inline',
234  'foreign_table' => 'aForeignTableName',
235  'behaviour' => [
236  'localizationMode' => 'select',
237  ]
238  ],
239  ],
240  ],
241  ],
242  ];
243  // not $globals definition for child here -> not localizable
244  $this->expectException(\UnexpectedValueException::class);
245  $this->expectExceptionCode(1443944274);
246  $this->subject->addData($input);
247  }
248 
253  {
254  $input = [
255  'defaultLanguageRow' => [],
256  'processedTca' => [
257  'columns' => [
258  'aField' => [
259  'config' => [
260  'type' => 'inline',
261  'foreign_table' => 'aForeignTableName',
262  'behaviour' => [
263  'localizationMode' => 'select',
264  ]
265  ],
266  ],
267  ],
268  ],
269  ];
270  $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
271  'languageField' => 'theLanguageField',
272  'transOrigPointerField' => 'theTransOrigPointerField',
273  ];
274  $expected = $input;
275  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
276  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
277  $this->assertEquals($expected, $this->subject->addData($input));
278  }
279 
284  {
285  $input = [
286  'defaultLanguageRow' => [],
287  'processedTca' => [
288  'columns' => [
289  'aField' => [
290  'config' => [
291  'type' => 'inline',
292  'foreign_table' => 'aForeignTableName',
293  'behaviour' => [
294  'localizationMode' => 'keep',
295  ]
296  ],
297  ],
298  ],
299  ],
300  ];
301  $expected = $input;
302  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
303  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'keep';
304  $this->assertEquals($expected, $this->subject->addData($input));
305  }
306 
311  {
312  $input = [
313  'defaultLanguageRow' => [],
314  'processedTca' => [
315  'columns' => [
316  'aField' => [
317  'config' => [
318  'type' => 'inline',
319  'foreign_table' => 'aForeignTableName',
320  ],
321  ],
322  ],
323  ],
324  ];
325  $expected = $input;
326  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
327  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'none';
328  $this->assertEquals($expected, $this->subject->addData($input));
329  }
330 
335  {
336  $input = [
337  'defaultLanguageRow' => [],
338  'processedTca' => [
339  'columns' => [
340  'aField' => [
341  'config' => [
342  'type' => 'inline',
343  'foreign_table' => 'aForeignTableName',
344  ],
345  ],
346  ],
347  ],
348  ];
349  $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
350  'languageField' => 'theLanguageField',
351  'transOrigPointerField' => 'theTransOrigPointerField',
352  ];
353  $expected = $input;
354  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
355  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
356  $this->assertEquals($expected, $this->subject->addData($input));
357  }
358 
363  {
364  $input = [
365  'processedTca' => [
366  'columns' => [
367  'aField' => [
368  'config' => [
369  'type' => 'inline',
370  'foreign_table' => 'aForeignTableName',
371  'appearance' => [
372  'levelLinksPosition' => 'both',
373  'enabledControls' => [
374  'dragdrop' => false,
375  ],
376  ],
377  ],
378  ],
379  ],
380  ],
381  ];
382  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
383  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
384  $expected['processedTca']['columns']['aField']['config']['appearance']['enabledControls']['dragdrop'] = false;
385  $this->assertEquals($expected, $this->subject->addData($input));
386  }
387 
392  {
393  $input = [
394  'processedTca' => [
395  'columns' => [
396  'aField' => [
397  'config' => [
398  'type' => 'inline',
399  'foreign_table' => 'aForeignTableName',
400  'foreign_selector' => 'aField',
401  'appearance' => [
402  'levelLinksPosition' => 'both',
403  ],
404  ],
405  ],
406  ],
407  ],
408  ];
409  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
410  'type' => 'select',
411  'foreign_table' => 'anotherForeignTableName',
412  ];
413  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
414  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
415  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
416  'fieldName' => 'aField',
417  'isSelector' => true,
418  'isUnique' => false,
419  'config' => [
420  'type' => 'select',
421  'foreign_table' => 'anotherForeignTableName',
422  ],
423  'foreignTable' => 'anotherForeignTableName',
424  ];
425  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'none';
426  $this->assertEquals($expected, $this->subject->addData($input));
427  }
428 
433  {
434  $input = [
435  'processedTca' => [
436  'columns' => [
437  'aField' => [
438  'config' => [
439  'type' => 'inline',
440  'foreign_table' => 'aForeignTableName',
441  'foreign_selector' => 'aField',
442  'appearance' => [
443  'useCombination' => true,
444  'levelLinksPosition' => 'both',
445  ],
446  ],
447  ],
448  ],
449  ],
450  ];
451  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
452  'type' => 'select',
453  'foreign_table' => 'anotherForeignTableName',
454  ];
455  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
456  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
457  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
458  'fieldName' => 'aField',
459  'isSelector' => true,
460  'isUnique' => false,
461  'config' => [
462  'type' => 'select',
463  'foreign_table' => 'anotherForeignTableName',
464  ],
465  'foreignTable' => 'anotherForeignTableName',
466  ];
467  $expected['processedTca']['columns']['aField']['config']['appearance']['useCombination'] = true;
468  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
469  $this->assertEquals($expected, $this->subject->addData($input));
470  }
471 
476  {
477  $input = [
478  'processedTca' => [
479  'columns' => [
480  'aField' => [
481  'config' => [
482  'type' => 'inline',
483  'foreign_table' => 'aForeignTableName',
484  'appearance' => [
485  'showPossibleLocalizationRecords' => '1',
486  ],
487  ],
488  ],
489  ],
490  ],
491  ];
492  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
493  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = true;
494  $this->assertEquals($expected, $this->subject->addData($input));
495  }
496 
501  {
502  $input = [
503  'processedTca' => [
504  'columns' => [
505  'aField' => [
506  'config' => [
507  'type' => 'inline',
508  'foreign_table' => 'aForeignTableName',
509  'appearance' => [
510  'showPossibleLocalizationRecords' => 0,
511  ],
512  ],
513  ],
514  ],
515  ],
516  ];
517  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
518  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = false;
519  $this->assertEquals($expected, $this->subject->addData($input));
520  }
521 
526  {
527  $input = [
528  'processedTca' => [
529  'columns' => [
530  'aField' => [
531  'config' => [
532  'type' => 'inline',
533  'foreign_table' => 'aForeignTableName',
534  'appearance' => [
535  'showRemovedLocalizationRecords' => 1,
536  ],
537  ],
538  ],
539  ],
540  ],
541  ];
542  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
543  $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = true;
544  $this->assertEquals($expected, $this->subject->addData($input));
545  }
546 
551  {
552  $input = [
553  'processedTca' => [
554  'columns' => [
555  'aField' => [
556  'config' => [
557  'type' => 'inline',
558  'foreign_table' => 'aForeignTableName',
559  'appearance' => [
560  'showRemovedLocalizationRecords' => '',
561  ],
562  ],
563  ],
564  ],
565  ],
566  ];
567  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
568  $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = false;
569  $this->assertEquals($expected, $this->subject->addData($input));
570  }
571 
576  {
577  $input = [
578  'processedTca' => [
579  'columns' => [
580  'aField' => [
581  'config' => [
582  'type' => 'inline',
583  'foreign_table' => 'aForeignTableName',
584  'foreign_selector' => 'aField',
585  'foreign_unique' => 'aDifferentField',
586  ],
587  ],
588  ],
589  ],
590  ];
591  $this->expectException(\UnexpectedValueException::class);
592  $this->expectExceptionCode(1444995464);
593  $this->subject->addData($input);
594  }
595 
600  {
601  $input = [
602  'processedTca' => [
603  'columns' => [
604  'aField' => [
605  'config' => [
606  'type' => 'inline',
607  'foreign_table' => 'aForeignTableName',
608  'foreign_selector' => 'aField',
609  ],
610  ],
611  ],
612  ],
613  ];
614  $this->expectException(\UnexpectedValueException::class);
615  $this->expectExceptionCode(1444996537);
616  $this->subject->addData($input);
617  }
618 
623  {
624  $input = [
625  'processedTca' => [
626  'columns' => [
627  'aField' => [
628  'config' => [
629  'type' => 'inline',
630  'foreign_table' => 'aForeignTableName',
631  'foreign_unique' => 'aField',
632  ],
633  ],
634  ],
635  ],
636  ];
637  $this->expectException(\UnexpectedValueException::class);
638  $this->expectExceptionCode(1444996537);
639  $this->subject->addData($input);
640  }
641 
646  {
647  $input = [
648  'processedTca' => [
649  'columns' => [
650  'aField' => [
651  'config' => [
652  'type' => 'inline',
653  'foreign_table' => 'aForeignTableName',
654  'foreign_unique' => 'aField',
655  ],
656  ],
657  ],
658  ],
659  ];
660  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
661  'type' => 'notSelectOrGroup',
662  ];
663  $this->expectException(\UnexpectedValueException::class);
664  $this->expectExceptionCode(1444996537);
665  $this->subject->addData($input);
666  }
667 
672  {
673  $input = [
674  'processedTca' => [
675  'columns' => [
676  'aField' => [
677  'config' => [
678  'type' => 'inline',
679  'foreign_table' => 'aForeignTableName',
680  'foreign_unique' => 'aField',
681  ],
682  ],
683  ],
684  ],
685  ];
686  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
687  'type' => 'group',
688  'internal_type' => 'notDb'
689  ];
690  $this->expectException(\UnexpectedValueException::class);
691  $this->expectExceptionCode(1444999130);
692  $this->subject->addData($input);
693  }
694 
699  {
700  $input = [
701  'processedTca' => [
702  'columns' => [
703  'aField' => [
704  'config' => [
705  'type' => 'inline',
706  'foreign_table' => 'aForeignTableName',
707  'foreign_unique' => 'aField',
708  ],
709  ],
710  ],
711  ],
712  ];
713  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
714  'type' => 'select',
715  ];
716  $this->expectException(\UnexpectedValueException::class);
717  $this->expectExceptionCode(1445078627);
718  $this->subject->addData($input);
719  }
720 
725  {
726  $input = [
727  'processedTca' => [
728  'columns' => [
729  'aField' => [
730  'config' => [
731  'type' => 'inline',
732  'foreign_table' => 'aForeignTableName',
733  'foreign_unique' => 'aField',
734  ],
735  ],
736  ],
737  ],
738  ];
739  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
740  'type' => 'group',
741  'internal_type' => 'db',
742  ];
743  $this->expectException(\UnexpectedValueException::class);
744  $this->expectExceptionCode(1445078628);
745  $this->subject->addData($input);
746  }
747 
752  {
753  $input = [
754  'processedTca' => [
755  'columns' => [
756  'aField' => [
757  'config' => [
758  'type' => 'inline',
759  'foreign_table' => 'aForeignTableName',
760  'foreign_unique' => 'aField',
761  ],
762  ],
763  ],
764  ],
765  ];
766  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
767  'type' => 'select',
768  'foreign_table' => 'anotherForeignTableName',
769  ];
770  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
771  $expected['processedTca']['columns']['aField']['config']['foreign_unique'] = 'aField';
772  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
773  'fieldName' => 'aField',
774  'isSelector' => false,
775  'isUnique' => true,
776  'config' => [
777  'type' => 'select',
778  'foreign_table' => 'anotherForeignTableName',
779  ],
780  'foreignTable' => 'anotherForeignTableName',
781  ];
782  $this->assertEquals($expected, $this->subject->addData($input));
783  }
784 
789  {
790  $input = [
791  'processedTca' => [
792  'columns' => [
793  'aField' => [
794  'config' => [
795  'type' => 'inline',
796  'foreign_table' => 'aForeignTableName',
797  'foreign_selector' => 'aField',
798  'overrideChildTca' => [
799  'columns' => [
800  'aField' => [
801  'config' => [
802  'aGivenSetting' => 'aOverrideValue',
803  'aNewSetting' => 'aNewSetting',
804  'appearance' => [
805  'elementBrowserType' => 'file',
806  'elementBrowserAllowed' => 'jpg,png',
807  ],
808  ],
809  ],
810  ],
811  ],
812  ],
813  ],
814  ],
815  ],
816  ];
817  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
818  'type' => 'group',
819  'internal_type' => 'db',
820  'allowed' => 'anotherForeignTableName',
821  'doNotChangeMe' => 'doNotChangeMe',
822  'aGivenSetting' => 'aGivenValue',
823  ];
824 
825  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
826  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'none';
827  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
828  $expected['processedTca']['columns']['aField']['config']['overrideChildTca']['columns']['aField'] = [
829  'config' => [
830  'aGivenSetting' => 'aOverrideValue',
831  'aNewSetting' => 'aNewSetting',
832  'appearance' => [
833  'elementBrowserType' => 'file',
834  'elementBrowserAllowed' => 'jpg,png',
835  ],
836  ],
837  ];
838 
839  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
840  'fieldName' => 'aField',
841  'isSelector' => true,
842  'isUnique' => false,
843  'config' => [
844  'type' => 'group',
845  'internal_type' => 'db',
846  'allowed' => 'anotherForeignTableName',
847  'doNotChangeMe' => 'doNotChangeMe',
848  'aGivenSetting' => 'aOverrideValue',
849  'aNewSetting' => 'aNewSetting',
850  'appearance' => [
851  'elementBrowserType' => 'file',
852  'elementBrowserAllowed' => 'jpg,png',
853  ],
854  ],
855  'foreignTable' => 'anotherForeignTableName',
856  ];
857  $this->assertEquals($expected, $this->subject->addData($input));
858  }
859 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']