TYPO3 CMS  TYPO3_7-6
TcaMigrationTest.php
Go to the documentation of this file.
1 <?php
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 
19 
24 {
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 
59  {
60  $input = [
61  'aTable' => [
62  'columns' => [
63  'bodytext' => [
64  'exclude' => 1,
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' => 1,
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 
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 
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 
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 
220  {
221  $input = [
222  'aTable' => [
223  'columns' => [
224  'bodytext' => [
225  'exclude' => 1,
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' => 1,
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 
321  {
322  $input = [
323  'aTable' => [
324  'columns' => [
325  'bodytext' => [
326  'exclude' => 1,
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' => 1,
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 }
migrateSetsShowIconTableIfMissing(array $givenConfig, array $expectedConfig)