[TASK] Cleanup TCA select field configuration
[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\Tests\UnitTestCase;
18 use TYPO3\CMS\Core\Migrations\TcaMigration;
19
20 /**
21 * Test case
22 */
23 class TcaMigrationTest extends UnitTestCase {
24
25 /**
26 * @test
27 */
28 public function migrateReturnsGivenArrayUnchangedIfNoMigrationNeeded() {
29 $input = $expected = array(
30 'aTable' => array(
31 'ctrl' => array(
32 'aKey' => 'aValue',
33 ),
34 'columns' => array(
35 'aField' => array(
36 'label' => 'foo',
37 'config' => array(
38 'type' => 'aType',
39 'lolli' => 'did this',
40 )
41 ),
42 ),
43 'types' => array(
44 0 => array(
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 $input = array(
59 'aTable' => array(
60 'columns' => array(
61 'bodytext' => array(
62 'exclude' => 1,
63 'label' => 'aLabel',
64 'config' => array(
65 'type' => 'text',
66 'rows' => 42,
67 'wizards' => array(
68 't3editor' => array(
69 'type' => 'userFunc',
70 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
71 'title' => 't3editor',
72 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
73 'module' => array(
74 'name' => 'wizard_table'
75 ),
76 'params' => array(
77 'format' => 'html',
78 'style' => 'width:98%; height: 60%;'
79 ),
80 ),
81 ),
82 ),
83 ),
84 ),
85 ),
86 );
87 $expected = array(
88 'aTable' => array(
89 'columns' => array(
90 'bodytext' => array(
91 'exclude' => 1,
92 'label' => 'aLabel',
93 'config' => array(
94 'type' => 'text',
95 'renderType' => 't3editor',
96 'format' => 'html',
97 'rows' => 42,
98 ),
99 ),
100 ),
101 ),
102 );
103 $subject = new TcaMigration();
104 $this->assertEquals($expected, $subject->migrate($input));
105 }
106
107 /**
108 * @test
109 */
110 public function migrateDropsStylePointerFromShowItem() {
111 $input = array(
112 'aTable' => array(
113 'types' => array(
114 0 => array(
115 'showitem' => 'aField,anotherField;with;;;style-pointer,thirdField',
116 ),
117 1 => array(
118 'showitem' => 'aField,;;;;only-a-style-pointer,anotherField',
119 ),
120 ),
121 ),
122 );
123 $expected = array(
124 'aTable' => array(
125 'types' => array(
126 0 => array(
127 'showitem' => 'aField,anotherField;with,thirdField',
128 ),
129 1 => array(
130 'showitem' => 'aField,anotherField',
131 ),
132 ),
133 ),
134 );
135 $subject = new TcaMigration();
136 $this->assertEquals($expected, $subject->migrate($input));
137 }
138
139 /**
140 * @test
141 */
142 public function migrateMovesSpecialConfigurationToColumnsOverridesDefaultExtras() {
143 $input = array(
144 'aTable' => array(
145 'types' => array(
146 0 => array(
147 'showitem' => 'aField,anotherField;with;;special:configuration,thirdField',
148 ),
149 ),
150 ),
151 );
152 $expected = array(
153 'aTable' => array(
154 'types' => array(
155 0 => array(
156 'showitem' => 'aField,anotherField;with,thirdField',
157 'columnsOverrides' => array(
158 'anotherField' => array(
159 'defaultExtras' => 'special:configuration',
160 ),
161 ),
162 ),
163 ),
164 ),
165 );
166 $subject = new TcaMigration();
167 $this->assertEquals($expected, $subject->migrate($input));
168 }
169
170 /**
171 * @test
172 */
173 public function migrateMovesSpecialConfigurationToColumnsOverridesDefaultExtrasAndMergesExistingDefaultExtras() {
174 $input = array(
175 'aTable' => array(
176 'columns' => array(
177 'anotherField' => array(
178 'defaultExtras' => 'some:values',
179 ),
180 ),
181 'types' => array(
182 0 => array(
183 'showitem' => 'aField,anotherField;with;;special:configuration,thirdField',
184 ),
185 ),
186 ),
187 );
188 $expected = array(
189 'aTable' => array(
190 'columns' => array(
191 'anotherField' => array(
192 'defaultExtras' => 'some:values',
193 ),
194 ),
195 'types' => array(
196 0 => array(
197 'showitem' => 'aField,anotherField;with,thirdField',
198 'columnsOverrides' => array(
199 'anotherField' => array(
200 'defaultExtras' => 'some:values:special:configuration',
201 ),
202 ),
203 ),
204 ),
205 ),
206 );
207 $subject = new TcaMigration();
208 $this->assertEquals($expected, $subject->migrate($input));
209 }
210
211 /**
212 * @test
213 */
214 public function migrateChangesT3editorWizardThatIsEnabledByTypeConfigToRenderTypeInColmnnsOverrides() {
215 $input = array(
216 'aTable' => array(
217 'columns' => array(
218 'bodytext' => array(
219 'exclude' => 1,
220 'label' => 'aLabel',
221 'config' => array(
222 'type' => 'text',
223 'rows' => 42,
224 'wizards' => array(
225 't3editorHtml' => array(
226 'type' => 'userFunc',
227 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
228 'enableByTypeConfig' => 1,
229 'title' => 't3editor',
230 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
231 'module' => array(
232 'name' => 'wizard_table'
233 ),
234 'params' => array(
235 'format' => 'html',
236 'style' => 'width:98%; height: 60%;'
237 ),
238 ),
239 't3editorTypoScript' => array(
240 'type' => 'userFunc',
241 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
242 'enableByTypeConfig' => 1,
243 'title' => 't3editor',
244 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
245 'module' => array(
246 'name' => 'wizard_table'
247 ),
248 'params' => array(
249 'format' => 'typoscript',
250 'style' => 'width:98%; height: 60%;'
251 ),
252 ),
253 ),
254 ),
255 ),
256 ),
257 'types' => array(
258 'firstType' => array(
259 'showitem' => 'foo,bodytext;;;wizards[t3editorTypoScript|someOtherWizard],bar',
260 ),
261 'secondType' => array(
262 'showitem' => 'foo,bodytext;;;nowrap:wizards[t3editorHtml], bar',
263 ),
264 ),
265 ),
266 );
267 $expected = array(
268 'aTable' => array(
269 'columns' => array(
270 'bodytext' => array(
271 'exclude' => 1,
272 'label' => 'aLabel',
273 'config' => array(
274 'type' => 'text',
275 'rows' => 42,
276 ),
277 ),
278 ),
279 'types' => array(
280 'firstType' => array(
281 'showitem' => 'foo,bodytext,bar',
282 'columnsOverrides' => array(
283 'bodytext' => array(
284 'config' => array(
285 'format' => 'typoscript',
286 'renderType' => 't3editor',
287 ),
288 'defaultExtras' => 'wizards[someOtherWizard]',
289 ),
290 ),
291 ),
292 'secondType' => array(
293 'showitem' => 'foo,bodytext,bar',
294 'columnsOverrides' => array(
295 'bodytext' => array(
296 'config' => array(
297 'format' => 'html',
298 'renderType' => 't3editor',
299 ),
300 'defaultExtras' => 'nowrap',
301 ),
302 ),
303 ),
304 ),
305 ),
306 );
307 $subject = new TcaMigration();
308 $this->assertEquals($expected, $subject->migrate($input));
309 }
310
311 /**
312 * @test
313 */
314 public function migrateRemovesAnUnusedT3edtiorDefinitionIfEnabledByTypeConfig() {
315 $input = array(
316 'aTable' => array(
317 'columns' => array(
318 'bodytext' => array(
319 'exclude' => 1,
320 'label' => 'aLabel',
321 'config' => array(
322 'type' => 'text',
323 'rows' => 42,
324 'wizards' => array(
325 't3editorHtml' => array(
326 'type' => 'userFunc',
327 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
328 'enableByTypeConfig' => 1,
329 'title' => 't3editor',
330 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
331 'module' => array(
332 'name' => 'wizard_table'
333 ),
334 'params' => array(
335 'format' => 'html',
336 'style' => 'width:98%; height: 60%;'
337 ),
338 ),
339 ),
340 ),
341 ),
342 ),
343 ),
344 );
345 $expected = array(
346 'aTable' => array(
347 'columns' => array(
348 'bodytext' => array(
349 'exclude' => 1,
350 'label' => 'aLabel',
351 'config' => array(
352 'type' => 'text',
353 'rows' => 42,
354 ),
355 ),
356 ),
357 ),
358 );
359 $subject = new TcaMigration();
360 $this->assertEquals($expected, $subject->migrate($input));
361 }
362
363 /**
364 * @test
365 */
366 public function migrateSpecialConfigurationAndRemoveShowItemStylePointerConfigDoesNotAddMessageIfOnlySyntaxChanged() {
367 $input = array(
368 'aTable' => array(
369 'columns' => array(
370 'anotherField' => array(
371 ),
372 ),
373 'types' => array(
374 0 => array(
375 'showitem' => 'aField;;;',
376 ),
377 ),
378 ),
379 );
380 $subject = new TcaMigration();
381 $subject->migrate($input);
382 $this->assertEmpty($subject->getMessages());
383 }
384
385 /**
386 * @test
387 */
388 public function migrateShowItemMovesAdditionalPaletteToOwnPaletteDefinition() {
389 $input = array(
390 'aTable' => array(
391 'types' => array(
392 'firstType' => array(
393 'showitem' => 'field1;field1Label,field2;fieldLabel2;palette1,field2;;palette2',
394 ),
395 ),
396 ),
397 );
398 $expected = array(
399 'aTable' => array(
400 'types' => array(
401 'firstType' => array(
402 'showitem' => 'field1;field1Label,field2;fieldLabel2,--palette--;;palette1,field2,--palette--;;palette2',
403 ),
404 ),
405 ),
406 );
407 $subject = new TcaMigration();
408 $this->assertEquals($expected, $subject->migrate($input));
409 }
410
411 /**
412 * @test
413 */
414 public function migrateIconsForFormFieldWizardsToNewLocation() {
415 $input = array(
416 'aTable' => array(
417 'columns' => array(
418 'bodytext' => array(
419 'config' => array(
420 'wizards' => array(
421 't3editorHtml' => array(
422 'icon' => 'wizard_table.gif',
423 ),
424 ),
425 ),
426 ),
427 ),
428 ),
429 );
430
431 $expected = array(
432 'aTable' => array(
433 'columns' => array(
434 'bodytext' => array(
435 'config' => array(
436 'wizards' => array(
437 't3editorHtml' => array(
438 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
439 ),
440 ),
441 ),
442 ),
443 ),
444 ),
445 );
446
447 $subject = new TcaMigration();
448 $this->assertEquals($expected, $subject->migrate($input));
449 }
450
451 /**
452 * @test
453 */
454 public function migrateExtAndSysextPathToEXTPath() {
455 $input = array(
456 'aTable' => array(
457 'columns' => array(
458 'foo' => array(
459 'config' => array(
460 'type' => 'select',
461 'items' => array(
462 array('foo', 0, 'ext/myext/foo/bar.gif'),
463 array('bar', 1, 'sysext/myext/foo/bar.gif'),
464 ),
465 ),
466 ),
467 ),
468 ),
469 );
470
471 $expected = array(
472 'aTable' => array(
473 'columns' => array(
474 'foo' => array(
475 'config' => array(
476 'type' => 'select',
477 'renderType' => 'selectSingle',
478 'items' => array(
479 array('foo', 0, 'EXT:myext/foo/bar.gif'),
480 array('bar', 1, 'EXT:myext/foo/bar.gif'),
481 ),
482 ),
483 ),
484 ),
485 ),
486 );
487
488 $subject = new TcaMigration();
489 $this->assertEquals($expected, $subject->migrate($input));
490 }
491
492 /**
493 * @test
494 */
495 public function migratePathWhichStartsWithIToEXTPath() {
496 $input = array(
497 'aTable' => array(
498 'columns' => array(
499 'foo' => array(
500 'config' => array(
501 'type' => 'select',
502 'items' => array(
503 array('foo', 0, 'i/tt_content.gif'),
504 ),
505 ),
506 ),
507 ),
508 ),
509 );
510
511 $expected = array(
512 'aTable' => array(
513 'columns' => array(
514 'foo' => array(
515 'config' => array(
516 'type' => 'select',
517 'renderType' => 'selectSingle',
518 'items' => array(
519 array('foo', 0, 'EXT:t3skin/icons/gfx/i/tt_content.gif'),
520 ),
521 ),
522 ),
523 ),
524 ),
525 );
526
527 $subject = new TcaMigration();
528 $this->assertEquals($expected, $subject->migrate($input));
529 }
530
531 /**
532 * @test
533 */
534 public function migrateRemovesIconsInOptionTags() {
535 $input = array(
536 'aTable' => array(
537 'columns' => array(
538 'foo' => array(
539 'config' => array(
540 'type' => 'select',
541 'iconsInOptionTags' => 1,
542 ),
543 ),
544 ),
545 ),
546 );
547 $expected = array(
548 'aTable' => array(
549 'columns' => array(
550 'foo' => array(
551 'config' => array(
552 'type' => 'select',
553 'renderType' => 'selectSingle',
554 ),
555 ),
556 ),
557 ),
558 );
559
560 $subject = new TcaMigration();
561 $this->assertEquals($expected, $subject->migrate($input));
562 }
563
564 /**
565 * @test
566 */
567 public function migrateRewritesRelativeIconPathToExtensionReference() {
568 $input = [
569 'aTable' => [
570 'ctrl' => [
571 'iconfile' => '../typo3conf/ext/myExt/iconfile.gif',
572 ],
573 ],
574 ];
575 $expected = [
576 'aTable' => [
577 'ctrl' => [
578 'iconfile' => 'EXT:myExt/iconfile.gif',
579 ],
580 ],
581 ];
582 $subject = new TcaMigration();
583 $this->assertEquals($expected, $subject->migrate($input));
584 }
585
586 /**
587 * @test
588 */
589 public function migrateRewritesIconFilenameOnlyToDefaultT3skinExtensionReference() {
590 $input = [
591 'aTable' => [
592 'ctrl' => [
593 'iconfile' => 'iconfile.gif',
594 ],
595 ],
596 ];
597 $expected = [
598 'aTable' => [
599 'ctrl' => [
600 'iconfile' => 'EXT:t3skin/icons/gfx/i/iconfile.gif',
601 ],
602 ],
603 ];
604 $subject = new TcaMigration();
605 $this->assertEquals($expected, $subject->migrate($input));
606 }
607
608 /**
609 * @test
610 */
611 public function migrateKeepsGivenExtensionReference() {
612 $input = [
613 'aTable' => [
614 'ctrl' => [
615 'iconfile' => 'EXT:myExt/iconfile.gif',
616 ],
617 ],
618 ];
619 $expected = [
620 'aTable' => [
621 'ctrl' => [
622 'iconfile' => 'EXT:myExt/iconfile.gif',
623 ],
624 ],
625 ];
626 $subject = new TcaMigration();
627 $this->assertEquals($expected, $subject->migrate($input));
628 }
629
630 /**
631 * @test
632 */
633 public function migrateSelectFieldRenderType() {
634 $input = [
635 'aTable-do-not-migrate-because-renderType-is-set' => [
636 'columns' => [
637 'a-column' => [
638 'config' => [
639 'type' => 'select',
640 'renderType' => 'fooBar'
641 ]
642 ]
643 ],
644 ],
645 'aTable-do-migrate-because-renderType-is-not-set' => [
646 'columns' => [
647 'a-tree-column' => [
648 'config' => [
649 'type' => 'select',
650 'renderMode' => 'tree'
651 ]
652 ],
653 'a-singlebox-column' => [
654 'config' => [
655 'type' => 'select',
656 'renderMode' => 'singlebox'
657 ]
658 ],
659 'a-checkbox-column' => [
660 'config' => [
661 'type' => 'select',
662 'renderMode' => 'checkbox'
663 ]
664 ],
665 'an-unknown-column' => [
666 'config' => [
667 'type' => 'select',
668 'renderMode' => 'unknown'
669 ]
670 ],
671 'a-maxitems-column-not-set' => [
672 'config' => [
673 'type' => 'select',
674 ]
675 ],
676 'a-maxitems-column-0' => [
677 'config' => [
678 'type' => 'select',
679 'maxitems' => '0'
680 ]
681 ],
682 'a-maxitems-column-1' => [
683 'config' => [
684 'type' => 'select',
685 'maxitems' => '1'
686 ]
687 ],
688 'a-maxitems-column-2' => [
689 'config' => [
690 'type' => 'select',
691 'maxitems' => '2'
692 ]
693 ],
694 'a-tree-column-with-maxitems' => [
695 'config' => [
696 'type' => 'select',
697 'renderMode' => 'tree',
698 'maxitems' => '1'
699 ]
700 ],
701 'a-singlebox-column-with-maxitems' => [
702 'config' => [
703 'type' => 'select',
704 'renderMode' => 'singlebox',
705 'maxitems' => '1'
706 ]
707 ],
708 'a-checkbox-column-with-maxitems' => [
709 'config' => [
710 'type' => 'select',
711 'renderMode' => 'checkbox',
712 'maxitems' => '1'
713 ]
714 ],
715 ],
716 ],
717 ];
718 $expected = [
719 'aTable-do-not-migrate-because-renderType-is-set' => [
720 'columns' => [
721 'a-column' => [
722 'config' => [
723 'type' => 'select',
724 'renderType' => 'fooBar'
725 ]
726 ]
727 ],
728 ],
729 'aTable-do-migrate-because-renderType-is-not-set' => [
730 'columns' => [
731 'a-tree-column' => [
732 'config' => [
733 'type' => 'select',
734 'renderMode' => 'tree',
735 'renderType' => 'selectTree'
736 ]
737 ],
738 'a-singlebox-column' => [
739 'config' => [
740 'type' => 'select',
741 'renderMode' => 'singlebox',
742 'renderType' => 'selectSingleBox'
743 ]
744 ],
745 'a-checkbox-column' => [
746 'config' => [
747 'type' => 'select',
748 'renderMode' => 'checkbox',
749 'renderType' => 'selectCheckBox'
750 ]
751 ],
752 'an-unknown-column' => [
753 'config' => [
754 'type' => 'select',
755 'renderMode' => 'unknown'
756 ]
757 ],
758 'a-maxitems-column-not-set' => [
759 'config' => [
760 'type' => 'select',
761 'renderType' => 'selectSingle'
762 ]
763 ],
764 'a-maxitems-column-0' => [
765 'config' => [
766 'type' => 'select',
767 'maxitems' => '0',
768 'renderType' => 'selectSingle'
769 ]
770 ],
771 'a-maxitems-column-1' => [
772 'config' => [
773 'type' => 'select',
774 'maxitems' => '1',
775 'renderType' => 'selectSingle'
776 ]
777 ],
778 'a-maxitems-column-2' => [
779 'config' => [
780 'type' => 'select',
781 'maxitems' => '2',
782 'renderType' => 'selectMultipleSideBySide'
783 ]
784 ],
785 'a-tree-column-with-maxitems' => [
786 'config' => [
787 'type' => 'select',
788 'renderMode' => 'tree',
789 'renderType' => 'selectTree',
790 'maxitems' => '1'
791 ]
792 ],
793 'a-singlebox-column-with-maxitems' => [
794 'config' => [
795 'type' => 'select',
796 'renderMode' => 'singlebox',
797 'renderType' => 'selectSingleBox',
798 'maxitems' => '1'
799 ]
800 ],
801 'a-checkbox-column-with-maxitems' => [
802 'config' => [
803 'type' => 'select',
804 'renderMode' => 'checkbox',
805 'renderType' => 'selectCheckBox',
806 'maxitems' => '1'
807 ]
808 ],
809 ],
810 ],
811 ];
812 $subject = new TcaMigration();
813 $this->assertEquals($expected, $subject->migrate($input));
814 }
815 }