‪TYPO3CMS  10.4
TcaMigrationTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪TcaMigrationTest extends UnitTestCase
27 {
31  public function ‪missingTypeThrowsException(): void
32  {
33  $input = [
34  'aTable' => [
35  'columns' => [
36  'field_a' => [
37  'label' => 'aLabel',
38  'config' => [
39  'type' => 'text',
40  ],
41  ],
42  'field_b' => [
43  'label' => 'bLabel',
44  'config' => [
45  'rows' => 42,
46  'wizards' => []
47  ],
48  ],
49  ],
50  ],
51  ];
52  $this->expectException(\RuntimeException::class);
53  $this->expectExceptionCode(1482394401);
54  $subject = new ‪TcaMigration();
55  $subject->migrate($input);
56  }
57 
62  {
63  $input = $expected = [
64  'aTable' => [
65  'ctrl' => [
66  'aKey' => 'aValue',
67  ],
68  'columns' => [
69  'aField' => [
70  'label' => 'foo',
71  'config' => [
72  'type' => 'aType',
73  'lolli' => 'did this',
74  ]
75  ],
76  ],
77  'types' => [
78  0 => [
79  'showitem' => 'this,should;stay,this,too',
80  ],
81  ],
82  ],
83  ];
84  $subject = new ‪TcaMigration();
85  self::assertEquals($expected, $subject->migrate($input));
86  }
87 
91  public function ‪migrateAddsMissingColumnsConfig(): void
92  {
93  $input = [
94  'aTable' => [
95  'columns' => [
96  'aField' => [
97  'exclude' => true,
98  ],
99  'bField' => [
100  ],
101  'cField' => [
102  'config' => 'i am a string but should be an array',
103  ],
104  'dField' => [
105  // This kept as is, 'config' is not added. This is relevant
106  // for "flex" data structure arrays with section containers
107  // that have 'type'=>'array' on this level and an 'el' sub array
108  // with details.
109  'type' => 'array',
110  ],
111  ]
112  ],
113  ];
114  $expected = [
115  'aTable' => [
116  'columns' => [
117  'aField' => [
118  'exclude' => true,
119  'config' => [
120  'type' => 'none',
121  ],
122  ],
123  'bField' => [
124  'config' => [
125  'type' => 'none',
126  ],
127  ],
128  'cField' => [
129  'config' => [
130  'type' => 'none',
131  ],
132  ],
133  'dField' => [
134  'type' => 'array',
135  ],
136  ],
137  ],
138  ];
139  $subject = new ‪TcaMigration();
140  self::assertEquals($expected, $subject->migrate($input));
141  }
142 
147  {
148  $input = [
149  'aTable' => [
150  'ctrl' => [
151  'selicon_field' => 'aField',
152  'selicon_field_path' => 'my/folder'
153  ],
154  'columns' => [
155  'aField' => [
156  'config' => [
157  'type' => 'none',
158  ],
159  ],
160  ]
161  ],
162  ];
163  $expected = [
164  'aTable' => [
165  'ctrl' => [
166  'selicon_field' => 'aField'
167  ],
168  'columns' => [
169  'aField' => [
170  'config' => [
171  'type' => 'none',
172  ],
173  ],
174  ],
175  ],
176  ];
177  $subject = new ‪TcaMigration();
178  self::assertEquals($expected, $subject->migrate($input));
179  }
180 
185  {
186  $input = [
187  'aTable' => [
188  'ctrl' => [
189  'title' => 'aField',
190  'setToDefaultOnCopy' => 'aField,anotherField',
191  ],
192  'columns' => [
193  'aField' => [
194  'config' => [
195  'type' => 'none',
196  ],
197  ],
198  ]
199  ]
200  ];
201  $expected = [
202  'aTable' => [
203  'ctrl' => [
204  'title' => 'aField',
205  ],
206  'columns' => [
207  'aField' => [
208  'config' => [
209  'type' => 'none',
210  ],
211  ],
212  ],
213  ],
214  ];
215  $subject = new ‪TcaMigration();
216  self::assertEquals($expected, $subject->migrate($input));
217  }
218 
223  {
224  return [
225  'filled columns' => [
226  // tca
227  [
228  'aTable' => [
229  'ctrl' => [
230  'origUid' => 'aField',
231  'languageField' => 'bField',
232  'transOrigPointerField' => 'cField',
233  'translationSource' => 'dField',
234  ],
235  'columns' => [
236  'aField' => [
237  'label' => 'aField',
238  'config' => [
239  'type' => 'none',
240  ],
241  ],
242  'bField' => [
243  'label' => 'bField',
244  'config' => [
245  'type' => 'none',
246  ],
247  ],
248  'cField' => [
249  'label' => 'cField',
250  'config' => [
251  'type' => 'none',
252  ],
253  ],
254  'dField' => [
255  'label' => 'dField',
256  'config' => [
257  'type' => 'none',
258  ],
259  ],
260  ],
261  ],
262  ],
263  // expectation
264  [
265  'aTable' => [
266  'ctrl' => [
267  'origUid' => 'aField',
268  'languageField' => 'bField',
269  'transOrigPointerField' => 'cField',
270  'translationSource' => 'dField',
271  ],
272  'columns' => [
273  'aField' => [
274  'label' => 'aField',
275  'config' => [
276  'type' => 'none',
277  ],
278  ],
279  'bField' => [
280  'label' => 'bField',
281  'config' => [
282  'type' => 'none',
283  ],
284  ],
285  'cField' => [
286  'label' => 'cField',
287  'config' => [
288  'type' => 'none',
289  ],
290  ],
291  'dField' => [
292  'label' => 'dField',
293  'config' => [
294  'type' => 'none',
295  ],
296  ],
297  ],
298  ],
299  ],
300  ],
301  'mixed columns' => [
302  // tca
303  [
304  'aTable' => [
305  'ctrl' => [
306  'origUid' => 'aField',
307  'languageField' => 'bField',
308  'transOrigPointerField' => 'cField',
309  'translationSource' => 'dField',
310  ],
311  'columns' => [
312  'aField' => [
313  'label' => 'aField',
314  'config' => [
315  'type' => 'none',
316  ],
317  ],
318  'bField' => [
319  'label' => 'bField',
320  'config' => [
321  'type' => 'none',
322  ],
323  ],
324  ],
325  ],
326  ],
327  // expectation
328  [
329  'aTable' => [
330  'ctrl' => [
331  'origUid' => 'aField',
332  'languageField' => 'bField',
333  'transOrigPointerField' => 'cField',
334  'translationSource' => 'dField',
335  ],
336  'columns' => [
337  'aField' => [
338  'label' => 'aField',
339  'config' => [
340  'type' => 'none',
341  ],
342  ],
343  'bField' => [
344  'label' => 'bField',
345  'config' => [
346  'type' => 'none',
347  ],
348  ],
349  'cField' => [
350  'config' => [
351  'type' => 'passthrough',
352  'default' => 0,
353  ],
354  ],
355  'dField' => [
356  'config' => [
357  'type' => 'passthrough',
358  'default' => 0,
359  ],
360  ],
361  ],
362  ],
363  ],
364  ],
365  'empty columns' => [
366  // tca
367  [
368  'aTable' => [
369  'ctrl' => [
370  'origUid' => 'aField',
371  'languageField' => 'bField',
372  'transOrigPointerField' => 'cField',
373  'translationSource' => 'dField',
374  ],
375  'columns' => [],
376  ],
377  ],
378  // expectation
379  [
380  'aTable' => [
381  'ctrl' => [
382  'origUid' => 'aField',
383  'languageField' => 'bField',
384  'transOrigPointerField' => 'cField',
385  'translationSource' => 'dField',
386  ],
387  'columns' => [
388  'aField' => [
389  'config' => [
390  'type' => 'passthrough',
391  'default' => 0,
392  ],
393  ],
394  'bField' => [
395  'config' => [
396  'type' => 'passthrough',
397  'default' => 0,
398  ],
399  ],
400  'cField' => [
401  'config' => [
402  'type' => 'passthrough',
403  'default' => 0,
404  ],
405  ],
406  'dField' => [
407  'config' => [
408  'type' => 'passthrough',
409  'default' => 0,
410  ],
411  ],
412  ],
413  ],
414  ],
415  ],
416  ];
417  }
418 
426  public function ‪ctrlIntegrityColumnsAreAvailable(array ‪$tca, array $expectation)
427  {
428  $subject = new ‪TcaMigration();
429  self::assertSame($expectation, $subject->migrate(‪$tca));
430  }
431 
436  {
437  $input = [
438  'aTable' => [
439  'columns' => [
440  'aField' => [
441  'config' => [
442  'type' => 'input',
443  'enableMultiSelectFilterTextfield' => false,
444  ],
445  ],
446  'bField' => [
447  'config' => [
448  'type' => 'select',
449  ],
450  ],
451  'cField' => [
452  'config' => [
453  'type' => 'select',
454  'enableMultiSelectFilterTextfield' => true,
455  ],
456  ],
457  ]
458  ],
459  ];
460  $expected = [
461  'aTable' => [
462  'columns' => [
463  'aField' => [
464  'config' => [
465  'type' => 'input',
466  ],
467  ],
468  'bField' => [
469  'config' => [
470  'type' => 'select',
471  ],
472  ],
473  'cField' => [
474  'config' => [
475  'type' => 'select',
476  ],
477  ],
478  ],
479  ],
480  ];
481  $subject = new ‪TcaMigration();
482  self::assertEquals($expected, $subject->migrate($input));
483  }
484 
489  {
490  $input = [
491  'aTable' => [
492  'ctrl' => [
493  'transOrigPointerField' => 'l10n_parent'
494  ],
495  'columns' => [
496  'l10n_parent' => [
497  'exclude' => true,
498  'config' => [
499  'type' => 'select'
500  ]
501  ]
502  ]
503  ],
504  'bTable' => [
505  'ctrl' => [
506  'transOrigPointerField' => 'l10n_parent'
507  ],
508  'columns' => [
509  'l10n_parent' => [
510  'config' => [
511  'type' => 'select'
512  ]
513  ]
514  ]
515  ],
516  'cTable' => [
517  'columns' => [
518  'l10n_parent' => [
519  'exclude' => true,
520  'config' => [
521  'type' => 'select'
522  ]
523  ]
524  ]
525  ]
526  ];
527  $expected = [
528  'aTable' => [
529  'ctrl' => [
530  'transOrigPointerField' => 'l10n_parent'
531  ],
532  'columns' => [
533  'l10n_parent' => [
534  'config' => [
535  'type' => 'select'
536  ]
537  ]
538  ]
539  ],
540  'bTable' => [
541  'ctrl' => [
542  'transOrigPointerField' => 'l10n_parent'
543  ],
544  'columns' => [
545  'l10n_parent' => [
546  'config' => [
547  'type' => 'select'
548  ]
549  ]
550  ]
551  ],
552  'cTable' => [
553  'columns' => [
554  'l10n_parent' => [
555  'exclude' => true,
556  'config' => [
557  'type' => 'select'
558  ]
559  ]
560  ]
561  ]
562  ];
563  $subject = new ‪TcaMigration();
564  self::assertEquals($expected, $subject->migrate($input));
565  }
566 
571  {
572  $input = [
573  'aTable' => [
574  'interface' => [
575  'showRecordFieldList' => 'title,text,description',
576  ]
577  ],
578  'bTable' => [
579  'interface' => [
580  'showRecordFieldList' => 'title,text,description',
581  'maxDBListItems' => 30,
582  'maxSingleDBListItems' => 50
583  ]
584  ]
585  ];
586  $expected = [
587  'aTable' => [
588  ],
589  'bTable' => [
590  'interface' => [
591  'maxDBListItems' => 30,
592  'maxSingleDBListItems' => 50
593  ]
594  ]
595  ];
596  $subject = new ‪TcaMigration();
597  self::assertEquals($expected, $subject->migrate($input));
598  }
599 
601  {
602  yield 'authMode=individual with keyword EXPL_ALLOW in items array migrated to new position' => [
603  'tca' => [
604  'aTable' => [
605  'columns' => [
606  'aColumn' => [
607  'config' => [
608  'type' => 'select',
609  'authMode' => 'individual',
610  'items' => [
611  [
612  'Label 1',
613  'Value 1',
614  null,
615  null,
616  'EXPL_ALLOW',
617  ],
618  ],
619  ],
620  ],
621  ],
622  ],
623  ],
624  'expected' => [
625  'aTable' => [
626  'columns' => [
627  'aColumn' => [
628  'config' => [
629  'type' => 'select',
630  'authMode' => 'individual',
631  'items' => [
632  [
633  'Label 1',
634  'Value 1',
635  null,
636  null,
637  '',
638  'EXPL_ALLOW',
639  ],
640  ],
641  ],
642  ],
643  ],
644  ],
645  ],
646  ];
647 
648  yield 'authMode=individual with keyword EXPL_DENY in items array migrated to new position' => [
649  'tca' => [
650  'aTable' => [
651  'columns' => [
652  'aColumn' => [
653  'config' => [
654  'type' => 'select',
655  'authMode' => 'individual',
656  'items' => [
657  [
658  'Label 1',
659  'Value 1',
660  null,
661  null,
662  'EXPL_DENY',
663  ],
664  ],
665  ],
666  ],
667  ],
668  ],
669  ],
670  'expected' => [
671  'aTable' => [
672  'columns' => [
673  'aColumn' => [
674  'config' => [
675  'type' => 'select',
676  'authMode' => 'individual',
677  'items' => [
678  [
679  'Label 1',
680  'Value 1',
681  null,
682  null,
683  '',
684  'EXPL_DENY',
685  ],
686  ],
687  ],
688  ],
689  ],
690  ],
691  ],
692  ];
693 
694  yield 'authMode=individual without keyword in items array NOT migrated to new position' => [
695  'tca' => [
696  'aTable' => [
697  'columns' => [
698  'aColumn' => [
699  'config' => [
700  'type' => 'select',
701  'authMode' => 'individual',
702  'items' => [
703  [
704  'Label 1',
705  'Value 1',
706  null,
707  null,
708  'EXPL_DENY',
709  ],
710  [
711  'Label 2',
712  'Value 2',
713  null,
714  null,
715  'Description 2',
716  ],
717  ],
718  ],
719  ],
720  ],
721  ],
722  ],
723  'expected' => [
724  'aTable' => [
725  'columns' => [
726  'aColumn' => [
727  'config' => [
728  'type' => 'select',
729  'authMode' => 'individual',
730  'items' => [
731  [
732  'Label 1',
733  'Value 1',
734  null,
735  null,
736  '',
737  'EXPL_DENY',
738  ],
739  [
740  'Label 2',
741  'Value 2',
742  null,
743  null,
744  'Description 2',
745  ],
746  ],
747  ],
748  ],
749  ],
750  ],
751  ],
752  ];
753 
754  yield 'items array NOT migrated to new position without authMode=individual set' => [
755  'tca' => [
756  'aTable' => [
757  'columns' => [
758  'aColumn' => [
759  'config' => [
760  'type' => 'select',
761  'authMode' => 'explicitAllow',
762  'items' => [
763  [
764  'Label 1',
765  'Value 1',
766  null,
767  null,
768  'Desription',
769  ],
770  ],
771  ],
772  ],
773  ],
774  ],
775  ],
776  'expected' => [
777  'aTable' => [
778  'columns' => [
779  'aColumn' => [
780  'config' => [
781  'type' => 'select',
782  'authMode' => 'explicitAllow',
783  'items' => [
784  [
785  'Label 1',
786  'Value 1',
787  null,
788  null,
789  'Desription',
790  ],
791  ],
792  ],
793  ],
794  ],
795  ],
796  ],
797  ];
798  }
799 
804  public function ‪selectIndividualAllowDenyMigratedToNewPosition(array $input, array $expected): void
805  {
806  $subject = new ‪TcaMigration();
807  self::assertEquals($expected, $subject->migrate($input));
808  }
809 }
‪TYPO3\CMS\Core\Migrations\TcaMigration
Definition: TcaMigration.php:26
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\ctrlIntegrityColumnsAreAvailable
‪ctrlIntegrityColumnsAreAvailable(array $tca, array $expectation)
Definition: TcaMigrationTest.php:426
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\removeShowRecordFieldListFieldIsRemoved
‪removeShowRecordFieldListFieldIsRemoved()
Definition: TcaMigrationTest.php:570
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\missingTypeThrowsException
‪missingTypeThrowsException()
Definition: TcaMigrationTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest
Definition: TcaMigrationTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\ctrlIntegrityColumnsAreAvailableDataProvider
‪array ctrlIntegrityColumnsAreAvailableDataProvider()
Definition: TcaMigrationTest.php:222
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\ctrlSelIconFieldPathIsRemoved
‪ctrlSelIconFieldPathIsRemoved()
Definition: TcaMigrationTest.php:146
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\migrateReturnsGivenArrayUnchangedIfNoMigrationNeeded
‪migrateReturnsGivenArrayUnchangedIfNoMigrationNeeded()
Definition: TcaMigrationTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Migrations
Definition: TcaMigrationTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\selectIndividualAllowDenyMigratedToNewPosition
‪selectIndividualAllowDenyMigratedToNewPosition(array $input, array $expected)
Definition: TcaMigrationTest.php:804
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\migrateAddsMissingColumnsConfig
‪migrateAddsMissingColumnsConfig()
Definition: TcaMigrationTest.php:91
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\removeEnableMultiSelectFilterTextfieldConfigurationIsRemoved
‪removeEnableMultiSelectFilterTextfieldConfigurationIsRemoved()
Definition: TcaMigrationTest.php:435
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\removeExcludeFieldForTransOrigPointerFieldIsRemoved
‪removeExcludeFieldForTransOrigPointerFieldIsRemoved()
Definition: TcaMigrationTest.php:488
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\selectIndividualAllowDenyMigratedToNewPositionDataProvider
‪selectIndividualAllowDenyMigratedToNewPositionDataProvider()
Definition: TcaMigrationTest.php:600
‪TYPO3\CMS\Core\Tests\Unit\Migrations\TcaMigrationTest\ctrlSetToDefaultOnCopyIsRemoved
‪ctrlSetToDefaultOnCopyIsRemoved()
Definition: TcaMigrationTest.php:184