‪TYPO3CMS  ‪main
TcaInlineConfigurationTest.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;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 final class ‪TcaInlineConfigurationTest extends UnitTestCase
25 {
29  protected array ‪$defaultConfig = [
30  'type' => 'inline',
31  'foreign_table' => 'aForeignTableName',
32  'minitems' => 0,
33  'maxitems' => 99999,
34  'appearance' => [
35  'levelLinksPosition' => 'top',
36  'showPossibleLocalizationRecords' => false,
37  'enabledControls' => [
38  'info' => true,
39  'new' => true,
40  'dragdrop' => true,
41  'sort' => true,
42  'hide' => true,
43  'delete' => true,
44  'localize' => true,
45  ],
46  ],
47  ];
48 
49  #[Test]
51  {
52  $input = [
53  'tableName' => 'aTable',
54  'databaseRow' => [],
55  'processedTca' => [
56  'columns' => [
57  'aField' => [
58  'config' => [
59  'type' => 'inline',
60  ],
61  ],
62  ],
63  ],
64  ];
65  $this->expectException(\UnexpectedValueException::class);
66  $this->expectExceptionCode(1443793404);
67  (new ‪TcaInlineConfiguration())->addData($input);
68  }
69 
70  #[Test]
71  public function ‪addDataSetsDefaults(): void
72  {
73  $input = [
74  'processedTca' => [
75  'columns' => [
76  'aField' => [
77  'config' => [
78  'type' => 'inline',
79  'foreign_table' => 'aForeignTableName',
80  ],
81  ],
82  ],
83  ],
84  ];
85  $expected = [];
86  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
87  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
88  }
89 
90  #[Test]
91  public function ‪addDataKeepsGivenMinitems(): void
92  {
93  $input = [
94  'processedTca' => [
95  'columns' => [
96  'aField' => [
97  'config' => [
98  'type' => 'inline',
99  'foreign_table' => 'aForeignTableName',
100  'minitems' => 23,
101  ],
102  ],
103  ],
104  ],
105  ];
106  $expected = [];
107  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
108  $expected['processedTca']['columns']['aField']['config']['minitems'] = 23;
109  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
110  }
111 
112  #[Test]
113  public function ‪addDataForcesMinitemsPositive(): void
114  {
115  $input = [
116  'processedTca' => [
117  'columns' => [
118  'aField' => [
119  'config' => [
120  'type' => 'inline',
121  'foreign_table' => 'aForeignTableName',
122  'minitems' => -23,
123  ],
124  ],
125  ],
126  ],
127  ];
128  $expected = [];
129  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
130  $expected['processedTca']['columns']['aField']['config']['minitems'] = 0;
131  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
132  }
133 
134  #[Test]
135  public function ‪addDataKeepsGivenMaxitems(): void
136  {
137  $input = [
138  'processedTca' => [
139  'columns' => [
140  'aField' => [
141  'config' => [
142  'type' => 'inline',
143  'foreign_table' => 'aForeignTableName',
144  'maxitems' => 23,
145  ],
146  ],
147  ],
148  ],
149  ];
150  $expected = [];
151  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
152  $expected['processedTca']['columns']['aField']['config']['maxitems'] = 23;
153  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
154  }
155 
156  #[Test]
157  public function ‪addDataForcesMaxitemsPositive(): void
158  {
159  $input = [
160  'processedTca' => [
161  'columns' => [
162  'aField' => [
163  'config' => [
164  'type' => 'inline',
165  'foreign_table' => 'aForeignTableName',
166  'maxitems' => '-23',
167  ],
168  ],
169  ],
170  ],
171  ];
172  $expected = [];
173  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
174  $expected['processedTca']['columns']['aField']['config']['maxitems'] = 1;
175  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
176  }
177 
178  #[Test]
180  {
181  $input = [
182  'processedTca' => [
183  'columns' => [
184  'aField' => [
185  'config' => [
186  'type' => 'inline',
187  'foreign_table' => 'aForeignTableName',
188  'appearance' => [
189  'levelLinksPosition' => 'both',
190  'enabledControls' => [
191  'dragdrop' => false,
192  ],
193  ],
194  ],
195  ],
196  ],
197  ],
198  ];
199  $expected = [];
200  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
201  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
202  $expected['processedTca']['columns']['aField']['config']['appearance']['enabledControls']['dragdrop'] = false;
203  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
204  }
205 
206  #[Test]
208  {
209  $input = [
210  'processedTca' => [
211  'columns' => [
212  'aField' => [
213  'config' => [
214  'type' => 'inline',
215  'foreign_table' => 'aForeignTableName',
216  'foreign_selector' => 'aField',
217  'appearance' => [
218  'levelLinksPosition' => 'both',
219  ],
220  ],
221  ],
222  ],
223  ],
224  ];
225  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
226  'type' => 'select',
227  'foreign_table' => 'anotherForeignTableName',
228  ];
229  $expected = [];
230  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
231  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
232  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
233  'fieldName' => 'aField',
234  'isSelector' => true,
235  'isUnique' => false,
236  'config' => [
237  'type' => 'select',
238  'foreign_table' => 'anotherForeignTableName',
239  ],
240  'foreignTable' => 'anotherForeignTableName',
241  ];
242  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
243  $expected['processedTca']['columns']['aField']['config']['appearance']['showAllLocalizationLink'] = false;
244  $expected['processedTca']['columns']['aField']['config']['appearance']['showSynchronizationLink'] = false;
245  $expected['processedTca']['columns']['aField']['config']['appearance']['showNewRecordLink'] = false;
246  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
247  }
248 
249  #[Test]
251  {
252  $input = [
253  'processedTca' => [
254  'columns' => [
255  'aField' => [
256  'config' => [
257  'type' => 'inline',
258  'foreign_table' => 'aForeignTableName',
259  'foreign_selector' => 'aField',
260  'appearance' => [
261  'useCombination' => true,
262  'levelLinksPosition' => 'both',
263  ],
264  ],
265  ],
266  ],
267  ],
268  ];
269  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
270  'type' => 'select',
271  'foreign_table' => 'anotherForeignTableName',
272  ];
273  $expected = [];
274  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
275  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
276  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
277  'fieldName' => 'aField',
278  'isSelector' => true,
279  'isUnique' => false,
280  'config' => [
281  'type' => 'select',
282  'foreign_table' => 'anotherForeignTableName',
283  ],
284  'foreignTable' => 'anotherForeignTableName',
285  ];
286  $expected['processedTca']['columns']['aField']['config']['appearance']['useCombination'] = true;
287  $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
288  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
289  }
290 
291  #[Test]
293  {
294  $input = [
295  'processedTca' => [
296  'columns' => [
297  'aField' => [
298  'config' => [
299  'type' => 'inline',
300  'foreign_table' => 'aForeignTableName',
301  'appearance' => [
302  'showPossibleLocalizationRecords' => '1',
303  ],
304  ],
305  ],
306  ],
307  ],
308  ];
309  $expected = [];
310  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
311  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = true;
312  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
313  }
314 
315  #[Test]
317  {
318  $input = [
319  'processedTca' => [
320  'columns' => [
321  'aField' => [
322  'config' => [
323  'type' => 'inline',
324  'foreign_table' => 'aForeignTableName',
325  'appearance' => [
326  'showPossibleLocalizationRecords' => 0,
327  ],
328  ],
329  ],
330  ],
331  ],
332  ];
333  $expected = [];
334  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
335  $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = false;
336  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
337  }
338 
339  #[Test]
341  {
342  $input = [
343  'tableName' => 'aTable',
344  'processedTca' => [
345  'columns' => [
346  'aField' => [
347  'config' => [
348  'type' => 'inline',
349  'foreign_table' => 'aForeignTableName',
350  'foreign_selector' => 'aField',
351  'foreign_unique' => 'aDifferentField',
352  ],
353  ],
354  ],
355  ],
356  ];
357  $this->expectException(\UnexpectedValueException::class);
358  $this->expectExceptionCode(1444995464);
359  (new ‪TcaInlineConfiguration())->addData($input);
360  }
361 
362  #[Test]
364  {
365  $input = [
366  'tableName' => 'aTable',
367  'processedTca' => [
368  'columns' => [
369  'aField' => [
370  'config' => [
371  'type' => 'inline',
372  'foreign_table' => 'aForeignTableName',
373  'foreign_selector' => 'aField',
374  ],
375  ],
376  ],
377  ],
378  ];
379  $this->expectException(\UnexpectedValueException::class);
380  $this->expectExceptionCode(1444996537);
381  (new ‪TcaInlineConfiguration())->addData($input);
382  }
383 
384  #[Test]
386  {
387  $input = [
388  'tableName' => 'aTable',
389  'processedTca' => [
390  'columns' => [
391  'aField' => [
392  'config' => [
393  'type' => 'inline',
394  'foreign_table' => 'aForeignTableName',
395  'foreign_unique' => 'aField',
396  ],
397  ],
398  ],
399  ],
400  ];
401  $this->expectException(\UnexpectedValueException::class);
402  $this->expectExceptionCode(1444996537);
403  (new ‪TcaInlineConfiguration())->addData($input);
404  }
405 
406  #[Test]
408  {
409  $input = [
410  'tableName' => 'aTable',
411  'processedTca' => [
412  'columns' => [
413  'aField' => [
414  'config' => [
415  'type' => 'inline',
416  'foreign_table' => 'aForeignTableName',
417  'foreign_unique' => 'aField',
418  ],
419  ],
420  ],
421  ],
422  ];
423  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
424  'type' => 'notSelectOrGroup',
425  ];
426  $this->expectException(\UnexpectedValueException::class);
427  $this->expectExceptionCode(1444996537);
428  (new ‪TcaInlineConfiguration())->addData($input);
429  }
430 
431  #[Test]
433  {
434  $input = [
435  'tableName' => 'aTable',
436  'processedTca' => [
437  'columns' => [
438  'aField' => [
439  'config' => [
440  'type' => 'inline',
441  'foreign_table' => 'aForeignTableName',
442  'foreign_unique' => 'aField',
443  ],
444  ],
445  ],
446  ],
447  ];
448  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
449  'type' => 'select',
450  ];
451  $this->expectException(\UnexpectedValueException::class);
452  $this->expectExceptionCode(1445078627);
453  (new ‪TcaInlineConfiguration())->addData($input);
454  }
455 
456  #[Test]
458  {
459  $input = [
460  'tableName' => 'aTable',
461  'processedTca' => [
462  'columns' => [
463  'aField' => [
464  'config' => [
465  'type' => 'inline',
466  'foreign_table' => 'aForeignTableName',
467  'foreign_unique' => 'aField',
468  ],
469  ],
470  ],
471  ],
472  ];
473  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
474  'type' => 'group',
475  ];
476  $this->expectException(\UnexpectedValueException::class);
477  $this->expectExceptionCode(1445078628);
478  (new ‪TcaInlineConfiguration())->addData($input);
479  }
480 
481  #[Test]
483  {
484  $input = [
485  'processedTca' => [
486  'columns' => [
487  'aField' => [
488  'config' => [
489  'type' => 'inline',
490  'foreign_table' => 'aForeignTableName',
491  'foreign_unique' => 'aField',
492  ],
493  ],
494  ],
495  ],
496  ];
497  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
498  'type' => 'select',
499  'foreign_table' => 'anotherForeignTableName',
500  ];
501  $expected = [];
502  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
503  $expected['processedTca']['columns']['aField']['config']['foreign_unique'] = 'aField';
504  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
505  'fieldName' => 'aField',
506  'isSelector' => false,
507  'isUnique' => true,
508  'config' => [
509  'type' => 'select',
510  'foreign_table' => 'anotherForeignTableName',
511  ],
512  'foreignTable' => 'anotherForeignTableName',
513  ];
514  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
515  }
516 
517  #[Test]
519  {
520  $input = [
521  'processedTca' => [
522  'columns' => [
523  'aField' => [
524  'config' => [
525  'type' => 'inline',
526  'foreign_table' => 'aForeignTableName',
527  'foreign_selector' => 'aField',
528  'overrideChildTca' => [
529  'columns' => [
530  'aField' => [
531  'config' => [
532  'aGivenSetting' => 'aOverrideValue',
533  'aNewSetting' => 'aNewSetting',
534  'appearance' => [
535  'useSortable' => true,
536  ],
537  ],
538  ],
539  ],
540  ],
541  ],
542  ],
543  ],
544  ],
545  ];
546  ‪$GLOBALS['TCA']['aForeignTableName']['columns']['aField']['config'] = [
547  'type' => 'group',
548  'allowed' => 'anotherForeignTableName',
549  'doNotChangeMe' => 'doNotChangeMe',
550  'aGivenSetting' => 'aGivenValue',
551  ];
552 
553  $expected = [];
554  $expected['processedTca']['columns']['aField']['config'] = ‪$this->defaultConfig;
555  $expected['processedTca']['columns']['aField']['config']['appearance']['showAllLocalizationLink'] = false;
556  $expected['processedTca']['columns']['aField']['config']['appearance']['showSynchronizationLink'] = false;
557  $expected['processedTca']['columns']['aField']['config']['appearance']['showNewRecordLink'] = false;
558  $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'aField';
559  $expected['processedTca']['columns']['aField']['config']['overrideChildTca']['columns']['aField'] = [
560  'config' => [
561  'aGivenSetting' => 'aOverrideValue',
562  'aNewSetting' => 'aNewSetting',
563  'appearance' => [
564  'useSortable' => true,
565  ],
566  ],
567  ];
568 
569  $expected['processedTca']['columns']['aField']['config']['selectorOrUniqueConfiguration'] = [
570  'fieldName' => 'aField',
571  'isSelector' => true,
572  'isUnique' => false,
573  'config' => [
574  'type' => 'group',
575  'allowed' => 'anotherForeignTableName',
576  'doNotChangeMe' => 'doNotChangeMe',
577  'aGivenSetting' => 'aOverrideValue',
578  'aNewSetting' => 'aNewSetting',
579  'appearance' => [
580  'useSortable' => true,
581  ],
582  ],
583  'foreignTable' => 'anotherForeignTableName',
584  ];
585  self::assertEquals($expected, (new ‪TcaInlineConfiguration())->addData($input));
586  }
587 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignUniqueGroupDoesNotDefineForeignTable
‪addDataThrowsExceptionIfForeignUniqueGroupDoesNotDefineForeignTable()
Definition: TcaInlineConfigurationTest.php:457
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionForInlineFieldWithoutForeignTableConfig
‪addDataThrowsExceptionForInlineFieldWithoutForeignTableConfig()
Definition: TcaInlineConfigurationTest.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataKeepsGivenMaxitems
‪addDataKeepsGivenMaxitems()
Definition: TcaInlineConfigurationTest.php:135
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataAddsSelectorOrUniqueConfigurationForForeignUnique
‪addDataAddsSelectorOrUniqueConfigurationForForeignUnique()
Definition: TcaInlineConfigurationTest.php:482
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest
Definition: TcaInlineConfigurationTest.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataForcesMaxitemsPositive
‪addDataForcesMaxitemsPositive()
Definition: TcaInlineConfigurationTest.php:157
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignUniqueSelectDoesNotDefineForeignTable
‪addDataThrowsExceptionIfForeignUniqueSelectDoesNotDefineForeignTable()
Definition: TcaInlineConfigurationTest.php:432
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignSelectorPointsToANotExistingField
‪addDataThrowsExceptionIfForeignSelectorPointsToANotExistingField()
Definition: TcaInlineConfigurationTest.php:363
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataSetsDefaults
‪addDataSetsDefaults()
Definition: TcaInlineConfigurationTest.php:71
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignUniqueTargetIsNotTypeSelectOrGroup
‪addDataThrowsExceptionIfForeignUniqueTargetIsNotTypeSelectOrGroup()
Definition: TcaInlineConfigurationTest.php:407
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanTrue
‪addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanTrue()
Definition: TcaInlineConfigurationTest.php:292
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration
Definition: TcaInlineConfiguration.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataMergesForeignSelectorFieldTcaOverride
‪addDataMergesForeignSelectorFieldTcaOverride()
Definition: TcaInlineConfigurationTest.php:518
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataMergesWithGivenAppearanceSettings
‪addDataMergesWithGivenAppearanceSettings()
Definition: TcaInlineConfigurationTest.php:179
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataKeepsLevelLinksPositionWithForeignSelectorAndUseCombination
‪addDataKeepsLevelLinksPositionWithForeignSelectorAndUseCombination()
Definition: TcaInlineConfigurationTest.php:250
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataKeepsGivenMinitems
‪addDataKeepsGivenMinitems()
Definition: TcaInlineConfigurationTest.php:91
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignUniquePointsToANotExistingField
‪addDataThrowsExceptionIfForeignUniquePointsToANotExistingField()
Definition: TcaInlineConfigurationTest.php:385
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanFalse
‪addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanFalse()
Definition: TcaInlineConfigurationTest.php:316
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataForcesMinitemsPositive
‪addDataForcesMinitemsPositive()
Definition: TcaInlineConfigurationTest.php:113
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataThrowsExceptionIfForeignSelectorAndForeignUniquePointToDifferentFields
‪addDataThrowsExceptionIfForeignSelectorAndForeignUniquePointToDifferentFields()
Definition: TcaInlineConfigurationTest.php:340
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\addDataForcesLevelLinksWithForeignSelector
‪addDataForcesLevelLinksWithForeignSelector()
Definition: TcaInlineConfigurationTest.php:207
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineConfigurationTest\$defaultConfig
‪array $defaultConfig
Definition: TcaInlineConfigurationTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18