b1267f75ca624f970535ec334d79f37a830ff869
[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' => '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;palette;;and-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;palette,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;palette;special:configuration,thirdField',
148 ),
149 ),
150 ),
151 );
152 $expected = array(
153 'aTable' => array(
154 'types' => array(
155 0 => array(
156 'showitem' => 'aField,anotherField;with;palette,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;palette;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;palette,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' => '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' => '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' => '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 }