d05ef95653446f79a68655c5e9d871bb2db9899f
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Migrations / TcaMigrationTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Migrations;
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
17 use TYPO3\CMS\Core\Migrations\TcaMigration;
18
19 /**
20 * Test case
21 */
22 class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @test
26 */
27 public function migrateReturnsGivenArrayUnchangedIfNoMigrationNeeded()
28 {
29 $input = $expected = [
30 'aTable' => [
31 'ctrl' => [
32 'aKey' => 'aValue',
33 ],
34 'columns' => [
35 'aField' => [
36 'label' => 'foo',
37 'config' => [
38 'type' => 'aType',
39 'lolli' => 'did this',
40 ]
41 ],
42 ],
43 'types' => [
44 0 => [
45 'showitem' => 'this,should;stay,this,too',
46 ],
47 ],
48 ],
49 ];
50 $subject = new TcaMigration();
51 $this->assertEquals($expected, $subject->migrate($input));
52 }
53
54 /**
55 * @test
56 */
57 public function migrateChangesT3editorWizardToT3editorRenderTypeIfNotEnabledByTypeConfig()
58 {
59 $input = [
60 'aTable' => [
61 'columns' => [
62 'bodytext' => [
63 'exclude' => true,
64 'label' => 'aLabel',
65 'config' => [
66 'type' => 'text',
67 'rows' => 42,
68 'wizards' => [
69 't3editor' => [
70 'type' => 'userFunc',
71 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
72 'title' => 't3editor',
73 'icon' => 'content-table',
74 'module' => [
75 'name' => 'wizard_table'
76 ],
77 'params' => [
78 'format' => 'html',
79 'style' => 'width:98%; height: 60%;'
80 ],
81 ],
82 ],
83 ],
84 ],
85 ],
86 ],
87 ];
88 $expected = [
89 'aTable' => [
90 'columns' => [
91 'bodytext' => [
92 'exclude' => true,
93 'label' => 'aLabel',
94 'config' => [
95 'type' => 'text',
96 'renderType' => 't3editor',
97 'format' => 'html',
98 'rows' => 42,
99 ],
100 ],
101 ],
102 ],
103 ];
104 $subject = new TcaMigration();
105 $this->assertEquals($expected, $subject->migrate($input));
106 }
107
108 /**
109 * @test
110 */
111 public function migrateDropsStylePointerFromShowItem()
112 {
113 $input = [
114 'aTable' => [
115 'types' => [
116 0 => [
117 'showitem' => 'aField,anotherField;with;;;style-pointer,thirdField',
118 ],
119 1 => [
120 'showitem' => 'aField,;;;;only-a-style-pointer,anotherField',
121 ],
122 ],
123 ],
124 ];
125 $expected = [
126 'aTable' => [
127 'types' => [
128 0 => [
129 'showitem' => 'aField,anotherField;with,thirdField',
130 ],
131 1 => [
132 'showitem' => 'aField,anotherField',
133 ],
134 ],
135 ],
136 ];
137 $subject = new TcaMigration();
138 $this->assertEquals($expected, $subject->migrate($input));
139 }
140
141 /**
142 * @test
143 */
144 public function migrateMovesSpecialConfigurationToColumnsOverridesDefaultExtras()
145 {
146 $input = [
147 'aTable' => [
148 'types' => [
149 0 => [
150 'showitem' => 'aField,anotherField;with;;special:configuration,thirdField',
151 ],
152 ],
153 ],
154 ];
155 $expected = [
156 'aTable' => [
157 'types' => [
158 0 => [
159 'showitem' => 'aField,anotherField;with,thirdField',
160 'columnsOverrides' => [
161 'anotherField' => [
162 'defaultExtras' => 'special:configuration',
163 ],
164 ],
165 ],
166 ],
167 ],
168 ];
169 $subject = new TcaMigration();
170 $this->assertEquals($expected, $subject->migrate($input));
171 }
172
173 /**
174 * @test
175 */
176 public function migrateMovesSpecialConfigurationToColumnsOverridesDefaultExtrasAndMergesExistingDefaultExtras()
177 {
178 $input = [
179 'aTable' => [
180 'columns' => [
181 'anotherField' => [
182 'defaultExtras' => 'some:values',
183 ],
184 ],
185 'types' => [
186 0 => [
187 'showitem' => 'aField,anotherField;with;;special:configuration,thirdField',
188 ],
189 ],
190 ],
191 ];
192 $expected = [
193 'aTable' => [
194 'columns' => [
195 'anotherField' => [
196 'defaultExtras' => 'some:values',
197 ],
198 ],
199 'types' => [
200 0 => [
201 'showitem' => 'aField,anotherField;with,thirdField',
202 'columnsOverrides' => [
203 'anotherField' => [
204 'defaultExtras' => 'some:values:special:configuration',
205 ],
206 ],
207 ],
208 ],
209 ],
210 ];
211 $subject = new TcaMigration();
212 $this->assertEquals($expected, $subject->migrate($input));
213 }
214
215 /**
216 * @test
217 */
218 public function migrateChangesT3editorWizardThatIsEnabledByTypeConfigToRenderTypeInColmnnsOverrides()
219 {
220 $input = [
221 'aTable' => [
222 'columns' => [
223 'bodytext' => [
224 'exclude' => true,
225 'label' => 'aLabel',
226 'config' => [
227 'type' => 'text',
228 'rows' => 42,
229 'wizards' => [
230 't3editorHtml' => [
231 'type' => 'userFunc',
232 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
233 'enableByTypeConfig' => 1,
234 'title' => 't3editor',
235 'icon' => 'content-table',
236 'module' => [
237 'name' => 'wizard_table'
238 ],
239 'params' => [
240 'format' => 'html',
241 'style' => 'width:98%; height: 60%;'
242 ],
243 ],
244 't3editorTypoScript' => [
245 'type' => 'userFunc',
246 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
247 'enableByTypeConfig' => 1,
248 'title' => 't3editor',
249 'icon' => 'content-table',
250 'module' => [
251 'name' => 'wizard_table'
252 ],
253 'params' => [
254 'format' => 'typoscript',
255 'style' => 'width:98%; height: 60%;'
256 ],
257 ],
258 ],
259 ],
260 ],
261 ],
262 'types' => [
263 'firstType' => [
264 'showitem' => 'foo,bodytext;;;wizards[t3editorTypoScript|someOtherWizard],bar',
265 ],
266 'secondType' => [
267 'showitem' => 'foo,bodytext;;;nowrap:wizards[t3editorHtml], bar',
268 ],
269 ],
270 ],
271 ];
272 $expected = [
273 'aTable' => [
274 'columns' => [
275 'bodytext' => [
276 'exclude' => true,
277 'label' => 'aLabel',
278 'config' => [
279 'type' => 'text',
280 'rows' => 42,
281 ],
282 ],
283 ],
284 'types' => [
285 'firstType' => [
286 'showitem' => 'foo,bodytext,bar',
287 'columnsOverrides' => [
288 'bodytext' => [
289 'config' => [
290 'format' => 'typoscript',
291 'renderType' => 't3editor',
292 ],
293 'defaultExtras' => 'wizards[someOtherWizard]',
294 ],
295 ],
296 ],
297 'secondType' => [
298 'showitem' => 'foo,bodytext,bar',
299 'columnsOverrides' => [
300 'bodytext' => [
301 'config' => [
302 'format' => 'html',
303 'renderType' => 't3editor',
304 ],
305 'defaultExtras' => 'nowrap',
306 ],
307 ],
308 ],
309 ],
310 ],
311 ];
312 $subject = new TcaMigration();
313 $this->assertEquals($expected, $subject->migrate($input));
314 }
315
316 /**
317 * @test
318 */
319 public function migrateRemovesAnUnusedT3edtiorDefinitionIfEnabledByTypeConfig()
320 {
321 $input = [
322 'aTable' => [
323 'columns' => [
324 'bodytext' => [
325 'exclude' => true,
326 'label' => 'aLabel',
327 'config' => [
328 'type' => 'text',
329 'rows' => 42,
330 'wizards' => [
331 't3editorHtml' => [
332 'type' => 'userFunc',
333 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
334 'enableByTypeConfig' => 1,
335 'title' => 't3editor',
336 'icon' => 'content-table',
337 'module' => [
338 'name' => 'wizard_table'
339 ],
340 'params' => [
341 'format' => 'html',
342 'style' => 'width:98%; height: 60%;'
343 ],
344 ],
345 ],
346 ],
347 ],
348 ],
349 ],
350 ];
351 $expected = [
352 'aTable' => [
353 'columns' => [
354 'bodytext' => [
355 'exclude' => true,
356 'label' => 'aLabel',
357 'config' => [
358 'type' => 'text',
359 'rows' => 42,
360 ],
361 ],
362 ],
363 ],
364 ];
365 $subject = new TcaMigration();
366 $this->assertEquals($expected, $subject->migrate($input));
367 }
368
369 /**
370 * @test
371 */
372 public function migrateSpecialConfigurationAndRemoveShowItemStylePointerConfigDoesNotAddMessageIfOnlySyntaxChanged()
373 {
374 $input = [
375 'aTable' => [
376 'columns' => [
377 'anotherField' => [
378 ],
379 ],
380 'types' => [
381 0 => [
382 'showitem' => 'aField;;;',
383 ],
384 1 => []
385 ],
386 ],
387 ];
388 $subject = new TcaMigration();
389 $subject->migrate($input);
390 $this->assertEmpty($subject->getMessages());
391 }
392
393 /**
394 * @test
395 */
396 public function migrateShowItemMovesAdditionalPaletteToOwnPaletteDefinition()
397 {
398 $input = [
399 'aTable' => [
400 'types' => [
401 'firstType' => [
402 'showitem' => 'field1;field1Label,field2;fieldLabel2;palette1,field2;;palette2',
403 ],
404 ],
405 ],
406 ];
407 $expected = [
408 'aTable' => [
409 'types' => [
410 'firstType' => [
411 'showitem' => 'field1;field1Label,field2;fieldLabel2,--palette--;;palette1,field2,--palette--;;palette2',
412 ],
413 ],
414 ],
415 ];
416 $subject = new TcaMigration();
417 $this->assertEquals($expected, $subject->migrate($input));
418 }
419
420 /**
421 * @test
422 */
423 public function migrateIconsForFormFieldWizardsToNewLocation()
424 {
425 $input = [
426 'aTable' => [
427 'columns' => [
428 'bodytext' => [
429 'config' => [
430 'wizards' => [
431 't3editorHtml' => [
432 'icon' => 'wizard_table.gif',
433 ],
434 ],
435 ],
436 ],
437 ],
438 ],
439 ];
440
441 $expected = [
442 'aTable' => [
443 'columns' => [
444 'bodytext' => [
445 'config' => [
446 'wizards' => [
447 't3editorHtml' => [
448 'icon' => 'content-table',
449 ],
450 ],
451 ],
452 ],
453 ],
454 ],
455 ];
456
457 $subject = new TcaMigration();
458 $this->assertEquals($expected, $subject->migrate($input));
459 }
460
461 /**
462 * @test
463 */
464 public function migrateExtAndSysextPathToEXTPath()
465 {
466 $input = [
467 'aTable' => [
468 'columns' => [
469 'foo' => [
470 'config' => [
471 'type' => 'select',
472 'items' => [
473 ['foo', 0, 'ext/myext/foo/bar.gif'],
474 ['bar', 1, 'sysext/myext/foo/bar.gif'],
475 ],
476 ],
477 ],
478 ],
479 ],
480 ];
481
482 $expected = [
483 'aTable' => [
484 'columns' => [
485 'foo' => [
486 'config' => [
487 'type' => 'select',
488 'renderType' => 'selectSingle',
489 'items' => [
490 ['foo', 0, 'EXT:myext/foo/bar.gif'],
491 ['bar', 1, 'EXT:myext/foo/bar.gif'],
492 ],
493 ],
494 ],
495 ],
496 ],
497 ];
498
499 $subject = new TcaMigration();
500 $this->assertEquals($expected, $subject->migrate($input));
501 }
502
503 /**
504 * @test
505 */
506 public function migratePathWhichStartsWithIToEXTPath()
507 {
508 $input = [
509 'aTable' => [
510 'columns' => [
511 'foo' => [
512 'config' => [
513 'type' => 'select',
514 'items' => [
515 ['foo', 0, 'i/tt_content.gif'],
516 ],
517 ],
518 ],
519 ],
520 ],
521 ];
522
523 $expected = [
524 'aTable' => [
525 'columns' => [
526 'foo' => [
527 'config' => [
528 'type' => 'select',
529 'renderType' => 'selectSingle',
530 'items' => [
531 ['foo', 0, 'EXT:t3skin/icons/gfx/i/tt_content.gif'],
532 ],
533 ],
534 ],
535 ],
536 ],
537 ];
538
539 $subject = new TcaMigration();
540 $this->assertEquals($expected, $subject->migrate($input));
541 }
542
543 /**
544 * @test
545 */
546 public function migrateRemovesIconsInOptionTags()
547 {
548 $input = [
549 'aTable' => [
550 'columns' => [
551 'foo' => [
552 'config' => [
553 'type' => 'select',
554 'iconsInOptionTags' => 1,
555 ],
556 ],
557 ],
558 ],
559 ];
560 $expected = [
561 'aTable' => [
562 'columns' => [
563 'foo' => [
564 'config' => [
565 'type' => 'select',
566 'renderType' => 'selectSingle',
567 ],
568 ],
569 ],
570 ],
571 ];
572
573 $subject = new TcaMigration();
574 $this->assertEquals($expected, $subject->migrate($input));
575 }
576
577 /**
578 * @test
579 */
580 public function migrateRewritesRelativeIconPathToExtensionReference()
581 {
582 $input = [
583 'aTable' => [
584 'ctrl' => [
585 'iconfile' => '../typo3conf/ext/myExt/iconfile.gif',
586 ],
587 ],
588 ];
589 $expected = [
590 'aTable' => [
591 'ctrl' => [
592 'iconfile' => 'EXT:myExt/iconfile.gif',
593 ],
594 ],
595 ];
596 $subject = new TcaMigration();
597 $this->assertEquals($expected, $subject->migrate($input));
598 }
599
600 /**
601 * @test
602 */
603 public function migrateRewritesIconFilenameOnlyToDefaultT3skinExtensionReference()
604 {
605 $input = [
606 'aTable' => [
607 'ctrl' => [
608 'iconfile' => 'iconfile.gif',
609 ],
610 ],
611 ];
612 $expected = [
613 'aTable' => [
614 'ctrl' => [
615 'iconfile' => 'EXT:t3skin/icons/gfx/i/iconfile.gif',
616 ],
617 ],
618 ];
619 $subject = new TcaMigration();
620 $this->assertEquals($expected, $subject->migrate($input));
621 }
622
623 /**
624 * @test
625 */
626 public function migrateKeepsGivenExtensionReference()
627 {
628 $input = [
629 'aTable' => [
630 'ctrl' => [
631 'iconfile' => 'EXT:myExt/iconfile.gif',
632 ],
633 ],
634 ];
635 $expected = [
636 'aTable' => [
637 'ctrl' => [
638 'iconfile' => 'EXT:myExt/iconfile.gif',
639 ],
640 ],
641 ];
642 $subject = new TcaMigration();
643 $this->assertEquals($expected, $subject->migrate($input));
644 }
645
646 /**
647 * @test
648 */
649 public function migrateSelectFieldRenderType()
650 {
651 $input = [
652 'aTable-do-not-migrate-because-renderType-is-set' => [
653 'columns' => [
654 'a-column' => [
655 'config' => [
656 'type' => 'select',
657 'renderType' => 'fooBar'
658 ]
659 ]
660 ],
661 ],
662 'aTable-do-migrate-because-renderType-is-not-set' => [
663 'columns' => [
664 'a-tree-column' => [
665 'config' => [
666 'type' => 'select',
667 'renderMode' => 'tree'
668 ]
669 ],
670 'a-singlebox-column' => [
671 'config' => [
672 'type' => 'select',
673 'renderMode' => 'singlebox'
674 ]
675 ],
676 'a-checkbox-column' => [
677 'config' => [
678 'type' => 'select',
679 'renderMode' => 'checkbox'
680 ]
681 ],
682 'an-unknown-column' => [
683 'config' => [
684 'type' => 'select',
685 'renderMode' => 'unknown'
686 ]
687 ],
688 'a-maxitems-column-not-set' => [
689 'config' => [
690 'type' => 'select',
691 ]
692 ],
693 'a-maxitems-column-0' => [
694 'config' => [
695 'type' => 'select',
696 'maxitems' => '0'
697 ]
698 ],
699 'a-maxitems-column-1' => [
700 'config' => [
701 'type' => 'select',
702 'maxitems' => '1'
703 ]
704 ],
705 'a-maxitems-column-2' => [
706 'config' => [
707 'type' => 'select',
708 'maxitems' => '2'
709 ]
710 ],
711 'a-tree-column-with-maxitems' => [
712 'config' => [
713 'type' => 'select',
714 'renderMode' => 'tree',
715 'maxitems' => '1'
716 ]
717 ],
718 'a-singlebox-column-with-maxitems' => [
719 'config' => [
720 'type' => 'select',
721 'renderMode' => 'singlebox',
722 'maxitems' => '1'
723 ]
724 ],
725 'a-checkbox-column-with-maxitems' => [
726 'config' => [
727 'type' => 'select',
728 'renderMode' => 'checkbox',
729 'maxitems' => '1'
730 ]
731 ],
732 ],
733 ],
734 ];
735 $expected = [
736 'aTable-do-not-migrate-because-renderType-is-set' => [
737 'columns' => [
738 'a-column' => [
739 'config' => [
740 'type' => 'select',
741 'renderType' => 'fooBar'
742 ]
743 ]
744 ],
745 ],
746 'aTable-do-migrate-because-renderType-is-not-set' => [
747 'columns' => [
748 'a-tree-column' => [
749 'config' => [
750 'type' => 'select',
751 'renderMode' => 'tree',
752 'renderType' => 'selectTree'
753 ]
754 ],
755 'a-singlebox-column' => [
756 'config' => [
757 'type' => 'select',
758 'renderMode' => 'singlebox',
759 'renderType' => 'selectSingleBox'
760 ]
761 ],
762 'a-checkbox-column' => [
763 'config' => [
764 'type' => 'select',
765 'renderMode' => 'checkbox',
766 'renderType' => 'selectCheckBox'
767 ]
768 ],
769 'an-unknown-column' => [
770 'config' => [
771 'type' => 'select',
772 'renderMode' => 'unknown'
773 ]
774 ],
775 'a-maxitems-column-not-set' => [
776 'config' => [
777 'type' => 'select',
778 'renderType' => 'selectSingle'
779 ]
780 ],
781 'a-maxitems-column-0' => [
782 'config' => [
783 'type' => 'select',
784 'maxitems' => '0',
785 'renderType' => 'selectSingle'
786 ]
787 ],
788 'a-maxitems-column-1' => [
789 'config' => [
790 'type' => 'select',
791 'maxitems' => 1,
792 'renderType' => 'selectSingle'
793 ]
794 ],
795 'a-maxitems-column-2' => [
796 'config' => [
797 'type' => 'select',
798 'maxitems' => 2,
799 'renderType' => 'selectMultipleSideBySide'
800 ]
801 ],
802 'a-tree-column-with-maxitems' => [
803 'config' => [
804 'type' => 'select',
805 'renderMode' => 'tree',
806 'renderType' => 'selectTree',
807 'maxitems' => '1'
808 ]
809 ],
810 'a-singlebox-column-with-maxitems' => [
811 'config' => [
812 'type' => 'select',
813 'renderMode' => 'singlebox',
814 'renderType' => 'selectSingleBox',
815 'maxitems' => '1'
816 ]
817 ],
818 'a-checkbox-column-with-maxitems' => [
819 'config' => [
820 'type' => 'select',
821 'renderMode' => 'checkbox',
822 'renderType' => 'selectCheckBox',
823 'maxitems' => '1'
824 ]
825 ],
826 ],
827 ],
828 ];
829 $subject = new TcaMigration();
830 $this->assertEquals($expected, $subject->migrate($input));
831 }
832
833 /**
834 * @return array
835 */
836 public function migrateSetsShowIconTableIfMissingDataProvider()
837 {
838 return [
839 'not-a-select-is-kept' => [
840 [
841 // Given config section
842 'type' => 'input',
843 ],
844 [
845 // Expected config section
846 'type' => 'input',
847 ],
848 ],
849 'not-a-selectSingle-is-kept' => [
850 [
851 'type' => 'select',
852 'renderType' => 'selectCheckBox',
853 ],
854 [
855 'type' => 'select',
856 'renderType' => 'selectCheckBox',
857 ],
858 ],
859 'noIconsBelowSelect-true-is-removed' => [
860 [
861 'type' => 'select',
862 'renderType' => 'selectSingle',
863 'noIconsBelowSelect' => true,
864 ],
865 [
866 'type' => 'select',
867 'renderType' => 'selectSingle',
868 ],
869 ],
870 'noIconsBelowSelect-false-is-removed-sets-showIconTable' => [
871 [
872 'type' => 'select',
873 'renderType' => 'selectSingle',
874 'noIconsBelowSelect' => false,
875 ],
876 [
877 'type' => 'select',
878 'renderType' => 'selectSingle',
879 'showIconTable' => true,
880 ],
881 ],
882 'noIconsBelowSelect-false-is-removed-keeps-given-showIconTable' => [
883 [
884 'type' => 'select',
885 'renderType' => 'selectSingle',
886 'noIconsBelowSelect' => false,
887 'showIconTable' => false,
888 ],
889 [
890 'type' => 'select',
891 'renderType' => 'selectSingle',
892 'showIconTable' => false,
893 ],
894 ],
895 'suppress-icons-1-is-removed' => [
896 [
897 'type' => 'select',
898 'renderType' => 'selectSingle',
899 'suppress_icons' => '1',
900 ],
901 [
902 'type' => 'select',
903 'renderType' => 'selectSingle',
904 ],
905 ],
906 'suppress-icons-value-is-removed' => [
907 [
908 'type' => 'select',
909 'renderType' => 'selectSingle',
910 'suppress_icons' => 'IF_VALUE_FALSE',
911 ],
912 [
913 'type' => 'select',
914 'renderType' => 'selectSingle',
915 ],
916 ],
917 'selicon-cols-sets-showIconTable' => [
918 [
919 'type' => 'select',
920 'renderType' => 'selectSingle',
921 'selicon_cols' => 16,
922 ],
923 [
924 'type' => 'select',
925 'renderType' => 'selectSingle',
926 'selicon_cols' => 16,
927 'showIconTable' => true,
928 ],
929 ],
930 'selicon-cols-does-not-override-given-showIconTable' => [
931 [
932 'type' => 'select',
933 'renderType' => 'selectSingle',
934 'selicon_cols' => 16,
935 'showIconTable' => false,
936 ],
937 [
938 'type' => 'select',
939 'renderType' => 'selectSingle',
940 'selicon_cols' => 16,
941 'showIconTable' => false,
942 ],
943 ],
944 'foreign_table_loadIcons-is-removed' => [
945 [
946 'type' => 'select',
947 'renderType' => 'selectSingle',
948 'foreign_table_loadIcons' => true,
949 ],
950 [
951 'type' => 'select',
952 'renderType' => 'selectSingle',
953 ],
954 ],
955 ];
956 }
957
958 /**
959 * @test
960 * @dataProvider migrateSetsShowIconTableIfMissingDataProvider
961 * @param array $givenConfig
962 * @param array $expectedConfig
963 */
964 public function migrateSetsShowIconTableIfMissing(array $givenConfig, array $expectedConfig)
965 {
966 $input = [
967 'aTable' => [
968 'columns' => [
969 'aField' => [
970 'config' => $givenConfig,
971 ]
972 ],
973 ],
974 ];
975 $expected = $input;
976 $expected['aTable']['columns']['aField']['config'] = $expectedConfig;
977
978 $subject = new TcaMigration();
979 $this->assertEquals($expected, $subject->migrate($input));
980 }
981
982 /**
983 * @test
984 */
985 public function migrateFixesReferenceToLinkHandler()
986 {
987 $input = [
988 'aTable' => [
989 'columns' => [
990 'aCol' => [
991 'config' => [
992 'wizards' => [
993 'link' => [
994 'module' => [
995 'name' => 'wizard_element_browser',
996 'urlParameters' => [
997 'mode' => 'wizard'
998 ]
999 ],
1000 ],
1001 ],
1002 ],
1003 ],
1004 ],
1005 ],
1006 ];
1007 $expected = [
1008 'aTable' => [
1009 'columns' => [
1010 'aCol' => [
1011 'config' => [
1012 'wizards' => [
1013 'link' => [
1014 'module' => [
1015 'name' => 'wizard_link',
1016 ],
1017 ],
1018 ],
1019 ],
1020 ],
1021 ],
1022 ],
1023 ];
1024
1025 $subject = new TcaMigration();
1026 $this->assertEquals($expected, $subject->migrate($input));
1027 }
1028
1029 /**
1030 * @return array
1031 */
1032 public function migrateRemovesRteTransformOptionsDataProvider()
1033 {
1034 return [
1035 'remove empty options in columns' => [
1036 [
1037 // Given config section
1038 'aTable' => [
1039 'columns' => [
1040 'aField' => [
1041 'defaultExtras' => 'richtext:rte_transform[]'
1042 ]
1043 ]
1044 ]
1045 ],
1046 [
1047 // Expected config section
1048 'aTable' => [
1049 'columns' => [
1050 'aField' => [
1051 'defaultExtras' => 'richtext:rte_transform'
1052 ]
1053 ]
1054 ]
1055 ],
1056 ],
1057 'remove nothing in columns' => [
1058 [
1059 'aTable' => [
1060 'columns' => [
1061 'aField' => [
1062 'defaultExtras' => 'richtext:rte_transform'
1063 ]
1064 ]
1065 ]
1066 ],
1067 [
1068 'aTable' => [
1069 'columns' => [
1070 'aField' => [
1071 'defaultExtras' => 'richtext:rte_transform'
1072 ]
1073 ]
1074 ]
1075 ],
1076 ],
1077 'remove mode in columns' => [
1078 [
1079 'aTable' => [
1080 'columns' => [
1081 'aField' => [
1082 'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
1083 ]
1084 ]
1085 ]
1086 ],
1087 [
1088 'aTable' => [
1089 'columns' => [
1090 'aField' => [
1091 'defaultExtras' => 'richtext:rte_transform'
1092 ]
1093 ]
1094 ]
1095 ],
1096 ],
1097 'remove flag and mode in columns' => [
1098 [
1099 'aTable' => [
1100 'columns' => [
1101 'aField' => [
1102 'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css]'
1103 ]
1104 ]
1105 ]
1106 ],
1107 [
1108 'aTable' => [
1109 'columns' => [
1110 'aField' => [
1111 'defaultExtras' => 'richtext:rte_transform'
1112 ]
1113 ]
1114 ]
1115 ],
1116 ],
1117 'remove flag and mode in columns with array notation' => [
1118 [
1119 'aTable' => [
1120 'columns' => [
1121 'aField' => [
1122 'defaultExtras' => 'richtext[]:rte_transform[flag=rte_enabled|mode=ts_css]'
1123 ]
1124 ]
1125 ]
1126 ],
1127 [
1128 'aTable' => [
1129 'columns' => [
1130 'aField' => [
1131 'defaultExtras' => 'richtext[]:rte_transform'
1132 ]
1133 ]
1134 ]
1135 ],
1136 ],
1137 'remove flag and mode in columns with array notation and index' => [
1138 [
1139 'aTable' => [
1140 'columns' => [
1141 'aField' => [
1142 'defaultExtras' => 'richtext[*]:rte_transform[flag=rte_enabled|mode=ts_css]'
1143 ]
1144 ]
1145 ]
1146 ],
1147 [
1148 'aTable' => [
1149 'columns' => [
1150 'aField' => [
1151 'defaultExtras' => 'richtext[*]:rte_transform'
1152 ]
1153 ]
1154 ]
1155 ],
1156 ],
1157 'remove flag and mode in columns with array notation and index and option list' => [
1158 [
1159 'aTable' => [
1160 'columns' => [
1161 'aField' => [
1162 'defaultExtras' => 'richtext[cut|copy|paste]:rte_transform[flag=rte_enabled|mode=ts_css]'
1163 ]
1164 ]
1165 ]
1166 ],
1167 [
1168 'aTable' => [
1169 'columns' => [
1170 'aField' => [
1171 'defaultExtras' => 'richtext[cut|copy|paste]:rte_transform'
1172 ]
1173 ]
1174 ]
1175 ],
1176 ],
1177 'remove empty options in columnsOverrides' => [
1178 [
1179 'aTable' => [
1180 'types' => [
1181 'aType' => [
1182 'columnsOverrides' => [
1183 'aField' => [
1184 'defaultExtras' => 'richtext:rte_transform[]'
1185 ]
1186 ]
1187 ]
1188 ]
1189 ]
1190 ],
1191 [
1192 'aTable' => [
1193 'types' => [
1194 'aType' => [
1195 'columnsOverrides' => [
1196 'aField' => [
1197 'defaultExtras' => 'richtext:rte_transform'
1198 ]
1199 ]
1200 ]
1201 ]
1202 ]
1203 ],
1204 ],
1205 'remove nothing in columnsOverrides' => [
1206 [
1207 'aTable' => [
1208 'types' => [
1209 'aType' => [
1210 'columnsOverrides' => [
1211 'aField' => [
1212 'defaultExtras' => 'richtext:rte_transform'
1213 ]
1214 ]
1215 ]
1216 ]
1217 ]
1218 ],
1219 [
1220 'aTable' => [
1221 'types' => [
1222 'aType' => [
1223 'columnsOverrides' => [
1224 'aField' => [
1225 'defaultExtras' => 'richtext:rte_transform'
1226 ]
1227 ]
1228 ]
1229 ]
1230 ]
1231 ],
1232 ],
1233 'remove mode in columnsOverrides' => [
1234 [
1235 'aTable' => [
1236 'types' => [
1237 'aType' => [
1238 'columnsOverrides' => [
1239 'aField' => [
1240 'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
1241 ]
1242 ]
1243 ]
1244 ]
1245 ]
1246 ],
1247 [
1248 'aTable' => [
1249 'types' => [
1250 'aType' => [
1251 'columnsOverrides' => [
1252 'aField' => [
1253 'defaultExtras' => 'richtext:rte_transform'
1254 ]
1255 ]
1256 ]
1257 ]
1258 ]
1259 ],
1260 ],
1261 'remove flag and mode in columnsOverrides' => [
1262 [
1263 'aTable' => [
1264 'types' => [
1265 'aType' => [
1266 'columnsOverrides' => [
1267 'aField' => [
1268 'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css]'
1269 ]
1270 ]
1271 ]
1272 ]
1273 ]
1274 ],
1275 [
1276 'aTable' => [
1277 'types' => [
1278 'aType' => [
1279 'columnsOverrides' => [
1280 'aField' => [
1281 'defaultExtras' => 'richtext:rte_transform'
1282 ]
1283 ]
1284 ]
1285 ]
1286 ]
1287 ],
1288 ],
1289 'remove flag and mode in columnsOverrides with array notation' => [
1290 [
1291 'aTable' => [
1292 'types' => [
1293 'aType' => [
1294 'columnsOverrides' => [
1295 'aField' => [
1296 'defaultExtras' => 'richtext[]:rte_transform[flag=rte_enabled|mode=ts_css]'
1297 ]
1298 ]
1299 ]
1300 ]
1301 ]
1302 ],
1303 [
1304 'aTable' => [
1305 'types' => [
1306 'aType' => [
1307 'columnsOverrides' => [
1308 'aField' => [
1309 'defaultExtras' => 'richtext[]:rte_transform'
1310 ]
1311 ]
1312 ]
1313 ]
1314 ]
1315 ],
1316 ],
1317 'remove flag and mode in columnsOverrides with array notation and index' => [
1318 [
1319 'aTable' => [
1320 'types' => [
1321 'aType' => [
1322 'columnsOverrides' => [
1323 'aField' => [
1324 'defaultExtras' => 'richtext[*]:rte_transform[flag=rte_enabled|mode=ts_css]'
1325 ]
1326 ]
1327 ]
1328 ]
1329 ]
1330 ],
1331 [
1332 'aTable' => [
1333 'types' => [
1334 'aType' => [
1335 'columnsOverrides' => [
1336 'aField' => [
1337 'defaultExtras' => 'richtext[*]:rte_transform'
1338 ]
1339 ]
1340 ]
1341 ]
1342 ]
1343 ],
1344 ],
1345 'remove flag and mode in columnsOverrides with array notation and index and option list' => [
1346 [
1347 'aTable' => [
1348 'types' => [
1349 'aType' => [
1350 'columnsOverrides' => [
1351 'aField' => [
1352 'defaultExtras' => 'richtext[copy|cut|paste]:rte_transform[flag=rte_enabled|mode=ts_css]'
1353 ]
1354 ]
1355 ]
1356 ]
1357 ]
1358 ],
1359 [
1360 'aTable' => [
1361 'types' => [
1362 'aType' => [
1363 'columnsOverrides' => [
1364 'aField' => [
1365 'defaultExtras' => 'richtext[copy|cut|paste]:rte_transform'
1366 ]
1367 ]
1368 ]
1369 ]
1370 ]
1371 ],
1372 ],
1373 ];
1374 }
1375
1376 /**
1377 * @test
1378 * @dataProvider migrateRemovesRteTransformOptionsDataProvider
1379 * @param array $givenConfig
1380 * @param array $expectedConfig
1381 */
1382 public function migrateRemovesRteTransformOptions(array $givenConfig, array $expectedConfig)
1383 {
1384 $subject = new TcaMigration();
1385 $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
1386 }
1387
1388 /**
1389 * @test
1390 */
1391 public function migrateRewritesColorpickerWizard()
1392 {
1393 $input = [
1394 'aTable' => [
1395 'columns' => [
1396 'aCol' => [
1397 'config' => [
1398 'wizards' => [
1399 'colorpicker' => [
1400 'type' => 'colorbox',
1401 'title' => 'Color picker',
1402 'module' => [
1403 'name' => 'wizard_colorpicker',
1404 ],
1405 'JSopenParams' => 'height=300,width=500,status=0,menubar=0,scrollbars=1',
1406 ],
1407 ],
1408 ],
1409 ],
1410 ],
1411 ],
1412 ];
1413 $expected = [
1414 'aTable' => [
1415 'columns' => [
1416 'aCol' => [
1417 'config' => [
1418 'renderType' => 'colorpicker',
1419 ],
1420 ],
1421 ],
1422 ],
1423 ];
1424
1425 $subject = new TcaMigration();
1426 $this->assertEquals($expected, $subject->migrate($input));
1427 }
1428
1429 /**
1430 * @return array
1431 */
1432 public function migrateSelectTreeOptionsDataProvider()
1433 {
1434 return [
1435 'remove width' => [
1436 [
1437 // Given config section
1438 'aTable' => [
1439 'columns' => [
1440 'aField' => [
1441 'config' => [
1442 'renderType' => 'selectTree',
1443 'treeConfig' => [
1444 'appearance' => [
1445 'width' => 200
1446 ]
1447 ]
1448 ]
1449 ]
1450 ]
1451 ]
1452 ],
1453 [
1454 // Expected config section
1455 'aTable' => [
1456 'columns' => [
1457 'aField' => [
1458 'config' => [
1459 'renderType' => 'selectTree',
1460 'treeConfig' => [
1461 'appearance' => [
1462 ]
1463 ]
1464 ]
1465 ]
1466 ]
1467 ]
1468 ]
1469 ],
1470 'remove allowRecursiveMode' => [
1471 [
1472 // Given config section
1473 'aTable' => [
1474 'columns' => [
1475 'aField' => [
1476 'config' => [
1477 'renderType' => 'selectTree',
1478 'treeConfig' => [
1479 'appearance' => [
1480 'someKey' => 'value',
1481 'allowRecursiveMode' => true
1482 ]
1483 ]
1484 ]
1485 ]
1486 ]
1487 ]
1488 ],
1489 [
1490 // Expected config section
1491 'aTable' => [
1492 'columns' => [
1493 'aField' => [
1494 'config' => [
1495 'renderType' => 'selectTree',
1496 'treeConfig' => [
1497 'appearance' => [
1498 'someKey' => 'value'
1499 ]
1500 ]
1501 ]
1502 ]
1503 ]
1504 ]
1505 ]
1506 ],
1507 'move autoSizeMax to size' => [
1508 [
1509 // Given config section
1510 'aTable' => [
1511 'columns' => [
1512 'aField' => [
1513 'config' => [
1514 'renderType' => 'selectTree',
1515 'autoSizeMax' => 20,
1516 'size' => 10
1517 ]
1518 ]
1519 ]
1520 ]
1521 ],
1522 [
1523 // Expected config section
1524 'aTable' => [
1525 'columns' => [
1526 'aField' => [
1527 'config' => [
1528 'renderType' => 'selectTree',
1529 'size' => 20
1530 ]
1531 ]
1532 ]
1533 ]
1534 ]
1535 ],
1536 'keep settings for non selectTree' => [
1537 [
1538 // Given config section
1539 'aTable' => [
1540 'columns' => [
1541 'aField' => [
1542 'config' => [
1543 'renderType' => 'not a select tree',
1544 'autoSizeMax' => 20,
1545 'size' => 10,
1546 'treeConfig' => [
1547 'appearance' => [
1548 'someKey' => 'value',
1549 'allowRecursiveMode' => true,
1550 'width' => 200
1551 ]
1552 ]
1553 ]
1554 ]
1555 ]
1556 ]
1557 ],
1558 [
1559 // Expected config section
1560 'aTable' => [
1561 'columns' => [
1562 'aField' => [
1563 'config' => [
1564 'renderType' => 'not a select tree',
1565 'autoSizeMax' => 20,
1566 'size' => 10,
1567 'treeConfig' => [
1568 'appearance' => [
1569 'someKey' => 'value',
1570 'allowRecursiveMode' => true,
1571 'width' => 200
1572 ]
1573 ]
1574 ]
1575 ]
1576 ]
1577 ]
1578 ]
1579 ]
1580 ];
1581 }
1582
1583 /**
1584 * @test
1585 * @dataProvider migrateSelectTreeOptionsDataProvider
1586 * @param array $input
1587 * @param array $expected
1588 */
1589 public function migrateSelectTreeOptions(array $input, array $expected)
1590 {
1591 $subject = new TcaMigration();
1592 $this->assertEquals($expected, $subject->migrate($input));
1593 }
1594
1595 public function migrateTsTemplateSoftReferencesDataProvider()
1596 {
1597 return [
1598 'nothing removed' => [
1599 [
1600 'aTable' => [
1601 'columns' => [
1602 'aCol' => [
1603 'config' => [
1604 'softref' => 'email,somethingelse'
1605 ],
1606 ],
1607 ],
1608 ],
1609 ],
1610 [
1611 'aTable' => [
1612 'columns' => [
1613 'aCol' => [
1614 'config' => [
1615 'softref' => 'email,somethingelse',
1616 ],
1617 ],
1618 ],
1619 ],
1620 ]
1621 ],
1622 'TStemplate only' => [
1623 [
1624 'aTable' => [
1625 'columns' => [
1626 'aCol' => [
1627 'config' => [
1628 'softref' => 'TStemplate,somethingelse'
1629 ],
1630 ],
1631 ],
1632 ],
1633 ],
1634 [
1635 'aTable' => [
1636 'columns' => [
1637 'aCol' => [
1638 'config' => [
1639 'softref' => 'somethingelse',
1640 ],
1641 ],
1642 ],
1643 ],
1644 ]
1645 ],
1646 'TStemplate and TSconfig' => [
1647 [
1648 'aTable' => [
1649 'columns' => [
1650 'aCol' => [
1651 'config' => [
1652 'softref' => 'TStemplate,somethingelse,TSconfig'
1653 ],
1654 ],
1655 ],
1656 ],
1657 ],
1658 [
1659 'aTable' => [
1660 'columns' => [
1661 'aCol' => [
1662 'config' => [
1663 'softref' => 'somethingelse',
1664 ],
1665 ],
1666 ],
1667 ],
1668 ]
1669 ],
1670 ];
1671 }
1672
1673 /**
1674 * @test
1675 * @dataProvider migrateTsTemplateSoftReferencesDataProvider
1676 * @param array $givenConfig
1677 * @param array $expectedConfig
1678 */
1679 public function migrateTsTemplateSoftReferences(array $givenConfig, array $expectedConfig)
1680 {
1681 $subject = new TcaMigration();
1682 $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
1683 }
1684
1685 public function migrateShowIfRTESettingDataProvider()
1686 {
1687 return [
1688 'nothing removed' => [
1689 [
1690 'aTable' => [
1691 'columns' => [
1692 'aCol' => [
1693 'config' => [
1694 'type' => 'check'
1695 ],
1696 ],
1697 ],
1698 ],
1699 ],
1700 [
1701 'aTable' => [
1702 'columns' => [
1703 'aCol' => [
1704 'config' => [
1705 'type' => 'check'
1706 ],
1707 ],
1708 ],
1709 ],
1710 ]
1711 ],
1712 'Option removed' => [
1713 [
1714 'aTable' => [
1715 'columns' => [
1716 'aCol' => [
1717 'config' => [
1718 'type' => 'check',
1719 'showIfRTE' => false
1720 ],
1721 ],
1722 ],
1723 ],
1724 ],
1725 [
1726 'aTable' => [
1727 'columns' => [
1728 'aCol' => [
1729 'config' => [
1730 'type' => 'check'
1731 ],
1732 ],
1733 ],
1734 ],
1735 ]
1736
1737 ],
1738 ];
1739 }
1740
1741 /**
1742 * @test
1743 * @dataProvider migrateShowIfRTESettingDataProvider
1744 * @param array $givenConfig
1745 * @param array $expectedConfig
1746 */
1747 public function migrateShowIfRTESetting(array $givenConfig, array $expectedConfig)
1748 {
1749 $subject = new TcaMigration();
1750 $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
1751 }
1752
1753 public function migrateWorkspaceSettingsDataProvider()
1754 {
1755 return [
1756 'no workspaces enabled' => [
1757 [
1758 'aTable' => [
1759 'ctrl' => [
1760 'versioningWS' => false
1761 ],
1762 ],
1763 ],
1764 [
1765 'aTable' => [
1766 'ctrl' => [
1767 'versioningWS' => false
1768 ],
1769 ],
1770 ]
1771 ],
1772 'nothing activated' => [
1773 [
1774 'aTable' => [
1775 'ctrl' => [
1776 'label' => 'blabla'
1777 ],
1778 ],
1779 ],
1780 [
1781 'aTable' => [
1782 'ctrl' => [
1783 'label' => 'blabla'
1784 ],
1785 ],
1786 ]
1787 ],
1788 'nothing changed, workspaces enabled' => [
1789 [
1790 'aTable' => [
1791 'ctrl' => [
1792 'versioningWS' => true
1793 ],
1794 ],
1795 ],
1796 [
1797 'aTable' => [
1798 'ctrl' => [
1799 'versioningWS' => true
1800 ],
1801 ],
1802 ]
1803 ],
1804 'cast workspaces to bool' => [
1805 [
1806 'aTable' => [
1807 'ctrl' => [
1808 'versioningWS' => 1
1809 ],
1810 ],
1811 ],
1812 [
1813 'aTable' => [
1814 'ctrl' => [
1815 'versioningWS' => true
1816 ],
1817 ],
1818 ]
1819 ],
1820 'cast workspaces v2 to bool' => [
1821 [
1822 'aTable' => [
1823 'ctrl' => [
1824 'versioningWS' => 2
1825 ],
1826 ],
1827 ],
1828 [
1829 'aTable' => [
1830 'ctrl' => [
1831 'versioningWS' => true
1832 ],
1833 ],
1834 ]
1835 ],
1836 'cast workspaces v2 to bool and remove followpages' => [
1837 [
1838 'aTable' => [
1839 'ctrl' => [
1840 'versioningWS' => 2,
1841 'versioning_followPages' => true
1842 ],
1843 ],
1844 ],
1845 [
1846 'aTable' => [
1847 'ctrl' => [
1848 'versioningWS' => true
1849 ],
1850 ],
1851 ]
1852 ],
1853 ];
1854 }
1855
1856 /**
1857 * @test
1858 * @dataProvider migrateWorkspaceSettingsDataProvider
1859 * @param array $givenConfig
1860 * @param array $expectedConfig
1861 */
1862 public function migrateWorkspaceSettings(array $givenConfig, array $expectedConfig)
1863 {
1864 $subject = new TcaMigration();
1865 $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
1866 }
1867
1868 /**
1869 * @return array
1870 */
1871 public function migrateTranslationTableDataProvider()
1872 {
1873 return [
1874 'remove transForeignTable' => [
1875 [
1876 'aTable' => [
1877 'ctrl' => [
1878 'transForeignTable' => 'pages_language_overlay',
1879 ],
1880 ],
1881 ],
1882 [
1883 'aTable' => [
1884 'ctrl' => [],
1885 ],
1886 ]
1887 ],
1888 'remove transOrigPointerTable' => [
1889 [
1890 'aTable' => [
1891 'ctrl' => [
1892 'transOrigPointerTable' => 'pages',
1893 ],
1894 ],
1895 ],
1896 [
1897 'aTable' => [
1898 'ctrl' => [],
1899 ],
1900 ]
1901 ]
1902 ];
1903 }
1904
1905 /**
1906 * @param array $givenConfig
1907 * @param array $expectedConfig
1908 * @test
1909 * @dataProvider migrateTranslationTableDataProvider
1910 */
1911 public function migrateTranslationTable(array $givenConfig, array $expectedConfig)
1912 {
1913 $subject = new TcaMigration();
1914 $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
1915 }
1916
1917 /**
1918 * @return array
1919 */
1920 public function migrateMovesRequestUpdateCtrlFieldToColumnsDataProvider()
1921 {
1922 return [
1923 'move single field name' => [
1924 [
1925 'aTable' => [
1926 'ctrl' => [
1927 'requestUpdate' => 'aField',
1928 ],
1929 'columns' => [
1930 'aField' => [
1931 'label' => 'foo',
1932 'config' => [],
1933 ],
1934 ],
1935 ],
1936 ],
1937 [
1938 'aTable' => [
1939 'ctrl' => [],
1940 'columns' => [
1941 'aField' => [
1942 'label' => 'foo',
1943 'config' => [],
1944 'onChange' => 'reload',
1945 ],
1946 ],
1947 ],
1948 ],
1949 ],
1950 'ignore missing field but migrate others' => [
1951 [
1952 'aTable' => [
1953 'ctrl' => [
1954 'requestUpdate' => 'aField, bField, cField, ',
1955 ],
1956 'columns' => [
1957 'aField' => [],
1958 'cField' => [],
1959 ],
1960 ],
1961 ],
1962 [
1963 'aTable' => [
1964 'ctrl' => [],
1965 'columns' => [
1966 'aField' => [
1967 'onChange' => 'reload',
1968 ],
1969 'cField' => [
1970 'onChange' => 'reload',
1971 ],
1972 ],
1973 ],
1974 ],
1975 ],
1976 ];
1977 }
1978
1979 /**
1980 * @param array $input
1981 * @param array $expected
1982 * @test
1983 * @dataProvider migrateMovesRequestUpdateCtrlFieldToColumnsDataProvider
1984 */
1985 public function migrateMovesRequestUpdateCtrlFieldToColumns(array $input, array $expected)
1986 {
1987 $this->assertEquals($expected, (new TcaMigration())->migrate($input));
1988 }
1989 }