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