TYPO3 CMS  TYPO3_7-6
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 
19 
24 {
28  protected $subject;
29 
30  protected function setUp()
31  {
32  $this->subject = new TcaInlineConfiguration();
33  }
34 
38  protected $defaultConfig = [
39  'type' => 'inline',
40  'foreign_table' => 'aForeignTableName',
41  'minitems' => 0,
42  'maxitems' => 100000,
43  'behaviour' => [
44  'localizationMode' => 'none',
45  ],
46  'appearance' => [
47  'levelLinksPosition' => 'top',
48  'showPossibleLocalizationRecords' => false,
49  'showRemovedLocalizationRecords' => false,
50  'enabledControls' => [
51  'info' => true,
52  'new' => true,
53  'dragdrop' => true,
54  'sort' => true,
55  'hide' => true,
56  'delete' => true,
57  'localize' => true,
58  ],
59  ],
60  ];
61 
66  {
67  $input = [
68  'databaseRow' => [],
69  'processedTca' => [
70  'columns' => [
71  'aField' => [
72  'config' => [
73  'type' => 'inline',
74  ],
75  ],
76  ],
77  ],
78  ];
79  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 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->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443829370);
218  $this->subject->addData($input);
219  }
220 
225  {
226  $input = [
227  'defaultLanguageRow' => [],
228  'processedTca' => [
229  'columns' => [
230  'aField' => [
231  'config' => [
232  'type' => 'inline',
233  'foreign_table' => 'aForeignTableName',
234  'behaviour' => [
235  'localizationMode' => 'select',
236  ]
237  ],
238  ],
239  ],
240  ],
241  ];
242  // not $globals definition for child here -> not localizable
243  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443944274);
244  $this->subject->addData($input);
245  }
246 
251  {
252  $input = [
253  'defaultLanguageRow' => [],
254  'processedTca' => [
255  'columns' => [
256  'aField' => [
257  'config' => [
258  'type' => 'inline',
259  'foreign_table' => 'aForeignTableName',
260  'behaviour' => [
261  'localizationMode' => 'select',
262  ]
263  ],
264  ],
265  ],
266  ],
267  ];
268  $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
269  'languageField' => 'theLanguageField',
270  'transOrigPointerField' => 'theTransOrigPointerField',
271  ];
272  $expected = $input;
273  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
274  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
275  $this->assertEquals($expected, $this->subject->addData($input));
276  }
277 
282  {
283  $input = [
284  'defaultLanguageRow' => [],
285  'processedTca' => [
286  'columns' => [
287  'aField' => [
288  'config' => [
289  'type' => 'inline',
290  'foreign_table' => 'aForeignTableName',
291  'behaviour' => [
292  'localizationMode' => 'keep',
293  ]
294  ],
295  ],
296  ],
297  ],
298  ];
299  $expected = $input;
300  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
301  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'keep';
302  $this->assertEquals($expected, $this->subject->addData($input));
303  }
304 
309  {
310  $input = [
311  'defaultLanguageRow' => [],
312  'processedTca' => [
313  'columns' => [
314  'aField' => [
315  'config' => [
316  'type' => 'inline',
317  'foreign_table' => 'aForeignTableName',
318  ],
319  ],
320  ],
321  ],
322  ];
323  $expected = $input;
324  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
325  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'none';
326  $this->assertEquals($expected, $this->subject->addData($input));
327  }
328 
333  {
334  $input = [
335  'defaultLanguageRow' => [],
336  'processedTca' => [
337  'columns' => [
338  'aField' => [
339  'config' => [
340  'type' => 'inline',
341  'foreign_table' => 'aForeignTableName',
342  ],
343  ],
344  ],
345  ],
346  ];
347  $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
348  'languageField' => 'theLanguageField',
349  'transOrigPointerField' => 'theTransOrigPointerField',
350  ];
351  $expected = $input;
352  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
353  $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
354  $this->assertEquals($expected, $this->subject->addData($input));
355  }
356 
361  {
362  $input = [
363  'processedTca' => [
364  'columns' => [
365  'aField' => [
366  'config' => [
367  'type' => 'inline',
368  'foreign_table' => 'aForeignTableName',
369  'appearance' => [
370  'levelLinksPosition' => 'both',
371  'enabledControls' => [
372  'dragdrop' => false,
373  ],
374  ],
375  ],
376  ],
377  ],
378  ],
379  ];
380  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
381  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
382  $expected['processedTca']['columns']['aField']['config']['appearance']['enabledControls']['dragdrop'] = false;
383  $this->assertEquals($expected, $this->subject->addData($input));
384  }
385 
390  {
391  $input = [
392  'processedTca' => [
393  'columns' => [
394  'aField' => [
395  'config' => [
396  'type' => 'inline',
397  'foreign_table' => 'aForeignTableName',
398  'foreign_selector' => 'aField',
399  'appearance' => [
400  'levelLinksPosition' => 'both',
401  ],
402  ],
403  ],
404  ],
405  ],
406  ];
407  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
408  'type' => 'select',
409  'foreign_table' => 'anotherForeignTableName',
410  ];
411  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
412  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
413  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
414  'fieldName' => 'aField',
415  'isSelector' => true,
416  'isUnique' => false,
417  'config' => [
418  'type' => 'select',
419  'foreign_table' => 'anotherForeignTableName',
420  ],
421  'foreignTable' => 'anotherForeignTableName',
422  ];
423  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'none';
424  $this->assertEquals($expected, $this->subject->addData($input));
425  }
426 
431  {
432  $input = [
433  'processedTca' => [
434  'columns' => [
435  'aField' => [
436  'config' => [
437  'type' => 'inline',
438  'foreign_table' => 'aForeignTableName',
439  'foreign_selector' => 'aField',
440  'appearance' => [
441  'useCombination' => true,
442  'levelLinksPosition' => 'both',
443  ],
444  ],
445  ],
446  ],
447  ],
448  ];
449  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
450  'type' => 'select',
451  'foreign_table' => 'anotherForeignTableName',
452  ];
453  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
454  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
455  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
456  'fieldName' => 'aField',
457  'isSelector' => true,
458  'isUnique' => false,
459  'config' => [
460  'type' => 'select',
461  'foreign_table' => 'anotherForeignTableName',
462  ],
463  'foreignTable' => 'anotherForeignTableName',
464  ];
465  $expected['processedTca']['columns']['aField']['config']['appearance']['useCombination'] = true;
466  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
467  $this->assertEquals($expected, $this->subject->addData($input));
468  }
469 
474  {
475  $input = [
476  'processedTca' => [
477  'columns' => [
478  'aField' => [
479  'config' => [
480  'type' => 'inline',
481  'foreign_table' => 'aForeignTableName',
482  'appearance' => [
483  'showPossibleLocalizationRecords' => '1',
484  ],
485  ],
486  ],
487  ],
488  ],
489  ];
490  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
491  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = true;
492  $this->assertEquals($expected, $this->subject->addData($input));
493  }
494 
499  {
500  $input = [
501  'processedTca' => [
502  'columns' => [
503  'aField' => [
504  'config' => [
505  'type' => 'inline',
506  'foreign_table' => 'aForeignTableName',
507  'appearance' => [
508  'showPossibleLocalizationRecords' => 0,
509  ],
510  ],
511  ],
512  ],
513  ],
514  ];
515  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
516  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = false;
517  $this->assertEquals($expected, $this->subject->addData($input));
518  }
519 
524  {
525  $input = [
526  'processedTca' => [
527  'columns' => [
528  'aField' => [
529  'config' => [
530  'type' => 'inline',
531  'foreign_table' => 'aForeignTableName',
532  'appearance' => [
533  'showRemovedLocalizationRecords' => 1,
534  ],
535  ],
536  ],
537  ],
538  ],
539  ];
540  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
541  $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = true;
542  $this->assertEquals($expected, $this->subject->addData($input));
543  }
544 
549  {
550  $input = [
551  'processedTca' => [
552  'columns' => [
553  'aField' => [
554  'config' => [
555  'type' => 'inline',
556  'foreign_table' => 'aForeignTableName',
557  'appearance' => [
558  'showRemovedLocalizationRecords' => '',
559  ],
560  ],
561  ],
562  ],
563  ],
564  ];
565  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
566  $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = false;
567  $this->assertEquals($expected, $this->subject->addData($input));
568  }
569 
574  {
575  $input = [
576  'processedTca' => [
577  'columns' => [
578  'aField' => [
579  'config' => [
580  'type' => 'inline',
581  'foreign_table' => 'aForeignTableName',
582  'foreign_selector' => 'aField',
583  'foreign_unique' => 'aDifferentField',
584  ],
585  ],
586  ],
587  ],
588  ];
589  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444995464);
590  $this->subject->addData($input);
591  }
592 
597  {
598  $input = [
599  'processedTca' => [
600  'columns' => [
601  'aField' => [
602  'config' => [
603  'type' => 'inline',
604  'foreign_table' => 'aForeignTableName',
605  'foreign_selector' => 'aField',
606  ],
607  ],
608  ],
609  ],
610  ];
611  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444996537);
612  $this->subject->addData($input);
613  }
614 
619  {
620  $input = [
621  'processedTca' => [
622  'columns' => [
623  'aField' => [
624  'config' => [
625  'type' => 'inline',
626  'foreign_table' => 'aForeignTableName',
627  'foreign_unique' => 'aField',
628  ],
629  ],
630  ],
631  ],
632  ];
633  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444996537);
634  $this->subject->addData($input);
635  }
636 
641  {
642  $input = [
643  'processedTca' => [
644  'columns' => [
645  'aField' => [
646  'config' => [
647  'type' => 'inline',
648  'foreign_table' => 'aForeignTableName',
649  'foreign_unique' => 'aField',
650  ],
651  ],
652  ],
653  ],
654  ];
655  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
656  'type' => 'notSelectOrGroup',
657  ];
658  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444996537);
659  $this->subject->addData($input);
660  }
661 
666  {
667  $input = [
668  'processedTca' => [
669  'columns' => [
670  'aField' => [
671  'config' => [
672  'type' => 'inline',
673  'foreign_table' => 'aForeignTableName',
674  'foreign_unique' => 'aField',
675  ],
676  ],
677  ],
678  ],
679  ];
680  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
681  'type' => 'group',
682  'internal_type' => 'notDb'
683  ];
684  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444999130);
685  $this->subject->addData($input);
686  }
687 
692  {
693  $input = [
694  'processedTca' => [
695  'columns' => [
696  'aField' => [
697  'config' => [
698  'type' => 'inline',
699  'foreign_table' => 'aForeignTableName',
700  'foreign_unique' => 'aField',
701  ],
702  ],
703  ],
704  ],
705  ];
706  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
707  'type' => 'select',
708  ];
709  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1445078627);
710  $this->subject->addData($input);
711  }
712 
717  {
718  $input = [
719  'processedTca' => [
720  'columns' => [
721  'aField' => [
722  'config' => [
723  'type' => 'inline',
724  'foreign_table' => 'aForeignTableName',
725  'foreign_unique' => 'aField',
726  ],
727  ],
728  ],
729  ],
730  ];
731  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
732  'type' => 'group',
733  'internal_type' => 'db',
734  ];
735  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1445078628);
736  $this->subject->addData($input);
737  }
738 
743  {
744  $input = [
745  'processedTca' => [
746  'columns' => [
747  'aField' => [
748  'config' => [
749  'type' => 'inline',
750  'foreign_table' => 'aForeignTableName',
751  'foreign_unique' => 'aField',
752  ],
753  ],
754  ],
755  ],
756  ];
757  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
758  'type' => 'select',
759  'foreign_table' => 'anotherForeignTableName',
760  ];
761  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
762  $expected['processedTca']['columns']['aField']['config']['foreign_unique'] = 'aField';
763  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
764  'fieldName' => 'aField',
765  'isSelector' => false,
766  'isUnique' => true,
767  'config' => [
768  'type' => 'select',
769  'foreign_table' => 'anotherForeignTableName',
770  ],
771  'foreignTable' => 'anotherForeignTableName',
772  ];
773  $this->assertEquals($expected, $this->subject->addData($input));
774  }
775 
780  {
781  $input = [
782  'processedTca' => [
783  'columns' => [
784  'aField' => [
785  'config' => [
786  'type' => 'inline',
787  'foreign_table' => 'aForeignTableName',
788  'foreign_selector' => 'aField',
789  'foreign_selector_fieldTcaOverride' => [
790  'config' => [
791  'aGivenSetting' => 'aOverrideValue',
792  'aNewSetting' => 'aNewSetting',
793  'appearance' => [
794  'elementBrowserType' => 'file',
795  'elementBrowserAllowed' => 'jpg,png',
796  ],
797  ],
798  ],
799  ],
800  ],
801  ],
802  ],
803  ];
804  $GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
805  'type' => 'group',
806  'internal_type' => 'db',
807  'allowed' => 'anotherForeignTableName',
808  'doNotChangeMe' => 'doNotChangeMe',
809  'aGivenSetting' => 'aGivenValue',
810  ];
811 
812  $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
813  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'none';
814  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
815  $expected['processedTca']['columns']['aField']['config']['foreign_selector_fieldTcaOverride'] = [
816  'config' => [
817  'aGivenSetting' => 'aOverrideValue',
818  'aNewSetting' => 'aNewSetting',
819  'appearance' => [
820  'elementBrowserType' => 'file',
821  'elementBrowserAllowed' => 'jpg,png',
822  ],
823  ],
824  ];
825 
826  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
827  'fieldName' => 'aField',
828  'isSelector' => true,
829  'isUnique' => false,
830  'config' => [
831  'type' => 'group',
832  'internal_type' => 'db',
833  'allowed' => 'anotherForeignTableName',
834  'doNotChangeMe' => 'doNotChangeMe',
835  'aGivenSetting' => 'aOverrideValue',
836  'aNewSetting' => 'aNewSetting',
837  'appearance' => [
838  'elementBrowserType' => 'file',
839  'elementBrowserAllowed' => 'jpg,png',
840  ],
841  ],
842  'foreignTable' => 'anotherForeignTableName',
843  ];
844  $this->assertEquals($expected, $this->subject->addData($input));
845  }
846 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']