19d3d86283a8e974b6677542a603a03fdd62ec98
[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 'items' => array(
478 array('foo', 0, 'EXT:myext/foo/bar.gif'),
479 array('bar', 1, 'EXT:myext/foo/bar.gif'),
480 ),
481 ),
482 ),
483 ),
484 ),
485 );
486
487 $subject = new TcaMigration();
488 $this->assertEquals($expected, $subject->migrate($input));
489 }
490
491 /**
492 * @test
493 */
494 public function migratePathWhichStartsWithIToEXTPath() {
495 $input = array(
496 'aTable' => array(
497 'columns' => array(
498 'foo' => array(
499 'config' => array(
500 'type' => 'select',
501 'items' => array(
502 array('foo', 0, 'i/tt_content.gif'),
503 ),
504 ),
505 ),
506 ),
507 ),
508 );
509
510 $expected = array(
511 'aTable' => array(
512 'columns' => array(
513 'foo' => array(
514 'config' => array(
515 'type' => 'select',
516 'items' => array(
517 array('foo', 0, 'EXT:t3skin/icons/gfx/i/tt_content.gif'),
518 ),
519 ),
520 ),
521 ),
522 ),
523 );
524
525 $subject = new TcaMigration();
526 $this->assertEquals($expected, $subject->migrate($input));
527 }
528
529 /**
530 * @test
531 */
532 public function migrateRemovesIconsInOptionTags() {
533 $input = array(
534 'aTable' => array(
535 'columns' => array(
536 'foo' => array(
537 'config' => array(
538 'type' => 'select',
539 'iconsInOptionTags' => 1,
540 ),
541 ),
542 ),
543 ),
544 );
545 $expected = array(
546 'aTable' => array(
547 'columns' => array(
548 'foo' => array(
549 'config' => array(
550 'type' => 'select',
551 ),
552 ),
553 ),
554 ),
555 );
556
557 $subject = new TcaMigration();
558 $this->assertEquals($expected, $subject->migrate($input));
559 }
560
561 /**
562 * @test
563 */
564 public function migrateRewritesRelativeIconPathToExtensionReference() {
565 $input = [
566 'aTable' => [
567 'ctrl' => [
568 'iconfile' => '../typo3conf/ext/myExt/iconfile.gif',
569 ],
570 ],
571 ];
572 $expected = [
573 'aTable' => [
574 'ctrl' => [
575 'iconfile' => 'EXT:myExt/iconfile.gif',
576 ],
577 ],
578 ];
579 $subject = new TcaMigration();
580 $this->assertEquals($expected, $subject->migrate($input));
581 }
582
583 /**
584 * @test
585 */
586 public function migrateRewritesIconFilenameOnlyToDefaultT3skinExtensionReference() {
587 $input = [
588 'aTable' => [
589 'ctrl' => [
590 'iconfile' => 'iconfile.gif',
591 ],
592 ],
593 ];
594 $expected = [
595 'aTable' => [
596 'ctrl' => [
597 'iconfile' => 'EXT:t3skin/icons/gfx/i/iconfile.gif',
598 ],
599 ],
600 ];
601 $subject = new TcaMigration();
602 $this->assertEquals($expected, $subject->migrate($input));
603 }
604
605 /**
606 * @test
607 */
608 public function migrateKeepsGivenExtensionReference() {
609 $input = [
610 'aTable' => [
611 'ctrl' => [
612 'iconfile' => 'EXT:myExt/iconfile.gif',
613 ],
614 ],
615 ];
616 $expected = [
617 'aTable' => [
618 'ctrl' => [
619 'iconfile' => 'EXT:myExt/iconfile.gif',
620 ],
621 ],
622 ];
623 $subject = new TcaMigration();
624 $this->assertEquals($expected, $subject->migrate($input));
625 }
626 }