8a13f0b1e01adede51df5f7474fa7d6153185a48
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaInlineConfigurationTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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\Backend\Form\FormDataProvider\TcaInlineConfiguration;
19
20 /**
21 * Test case
22 */
23 class TcaInlineConfigurationTest extends UnitTestCase
24 {
25 /**
26 * @var TcaInlineConfiguration
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new TcaInlineConfiguration();
33 }
34
35 /**
36 * @var array Set of default controls
37 */
38 protected $defaultConfig = [
39 'type' => 'inline',
40 'foreign_table' => 'aForeignTableName',
41 'minitems' => 0,
42 'maxitems' => 100000,
43 'behaviour' => [
44 'localizationMode' => 'none',
45 ],
46 'appearance' => [
47 'levelLinksPosition' => 'top',
48 'showPossibleLocalizationRecords' => false,
49 'showRemovedLocalizationRecords' => false,
50 'enabledControls' => [
51 'info' => true,
52 'new' => true,
53 'dragdrop' => true,
54 'sort' => true,
55 'hide' => true,
56 'delete' => true,
57 'localize' => true,
58 ],
59 ],
60 ];
61
62 /**
63 * @test
64 */
65 public function addDataThrowsExceptionForInlineFieldWithoutForeignTableConfig()
66 {
67 $input = [
68 'databaseRow' => [],
69 'processedTca' => [
70 'columns' => [
71 'aField' => [
72 'config' => [
73 'type' => 'inline',
74 ],
75 ],
76 ],
77 ],
78 ];
79 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443793404);
80 $this->subject->addData($input);
81 }
82
83 /**
84 * @test
85 */
86 public function addDataSetsDefaults()
87 {
88 $input = [
89 'processedTca' => [
90 'columns' => [
91 'aField' => [
92 'config' => [
93 'type' => 'inline',
94 'foreign_table' => 'aForeignTableName',
95 ],
96 ],
97 ],
98 ],
99 ];
100 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
101 $this->assertEquals($expected, $this->subject->addData($input));
102 }
103
104 /**
105 * @test
106 */
107 public function addDataKeepsGivenMinitems()
108 {
109 $input = [
110 'processedTca' => [
111 'columns' => [
112 'aField' => [
113 'config' => [
114 'type' => 'inline',
115 'foreign_table' => 'aForeignTableName',
116 'minitems' => 23,
117 ],
118 ],
119 ],
120 ],
121 ];
122 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
123 $expected['processedTca']['columns']['aField']['config']['minitems'] = 23;
124 $this->assertEquals($expected, $this->subject->addData($input));
125 }
126
127 /**
128 * @test
129 */
130 public function addDataForcesMinitemsPositive()
131 {
132 $input = [
133 'processedTca' => [
134 'columns' => [
135 'aField' => [
136 'config' => [
137 'type' => 'inline',
138 'foreign_table' => 'aForeignTableName',
139 'minitems' => '-23',
140 ],
141 ],
142 ],
143 ],
144 ];
145 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
146 $expected['processedTca']['columns']['aField']['config']['minitems'] = 0;
147 $this->assertEquals($expected, $this->subject->addData($input));
148 }
149
150 /**
151 * @test
152 */
153 public function addDataKeepsGivenMaxitems()
154 {
155 $input = [
156 'processedTca' => [
157 'columns' => [
158 'aField' => [
159 'config' => [
160 'type' => 'inline',
161 'foreign_table' => 'aForeignTableName',
162 'maxitems' => 23,
163 ],
164 ],
165 ],
166 ],
167 ];
168 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
169 $expected['processedTca']['columns']['aField']['config']['maxitems'] = 23;
170 $this->assertEquals($expected, $this->subject->addData($input));
171 }
172
173 /**
174 * @test
175 */
176 public function addDataForcesMaxitemsPositive()
177 {
178 $input = [
179 'processedTca' => [
180 'columns' => [
181 'aField' => [
182 'config' => [
183 'type' => 'inline',
184 'foreign_table' => 'aForeignTableName',
185 'maxitems' => '-23',
186 ],
187 ],
188 ],
189 ],
190 ];
191 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
192 $expected['processedTca']['columns']['aField']['config']['maxitems'] = 1;
193 $this->assertEquals($expected, $this->subject->addData($input));
194 }
195
196 /**
197 * @test
198 */
199 public function addDataThrowsExceptionIfLocalizationModeIsSetButNotToKeepOrSelect()
200 {
201 $input = [
202 'defaultLanguageRow' => [],
203 'processedTca' => [
204 'columns' => [
205 'aField' => [
206 'config' => [
207 'type' => 'inline',
208 'foreign_table' => 'aForeignTableName',
209 'behaviour' => [
210 'localizationMode' => 'foo',
211 ]
212 ],
213 ],
214 ],
215 ],
216 ];
217 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443829370);
218 $this->subject->addData($input);
219 }
220
221 /**
222 * @test
223 */
224 public function addDataThrowsExceptionIfLocalizationModeIsSetToSelectAndChildIsNotLocalizable()
225 {
226 $input = [
227 'defaultLanguageRow' => [],
228 'processedTca' => [
229 'columns' => [
230 'aField' => [
231 'config' => [
232 'type' => 'inline',
233 'foreign_table' => 'aForeignTableName',
234 'behaviour' => [
235 'localizationMode' => 'select',
236 ]
237 ],
238 ],
239 ],
240 ],
241 ];
242 // not $globals definition for child here -> not localizable
243 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443944274);
244 $this->subject->addData($input);
245 }
246
247 /**
248 * @test
249 */
250 public function addDataKeepsLocalizationModeSelectIfChildIsLocalizable()
251 {
252 $input = [
253 'defaultLanguageRow' => [],
254 'processedTca' => [
255 'columns' => [
256 'aField' => [
257 'config' => [
258 'type' => 'inline',
259 'foreign_table' => 'aForeignTableName',
260 'behaviour' => [
261 'localizationMode' => 'select',
262 ]
263 ],
264 ],
265 ],
266 ],
267 ];
268 $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
269 'languageField' => 'theLanguageField',
270 'transOrigPointerField' => 'theTransOrigPointerField',
271 ];
272 $expected = $input;
273 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
274 $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
275 $this->assertEquals($expected, $this->subject->addData($input));
276 }
277
278 /**
279 * @test
280 */
281 public function addDataKeepsLocalizationModeKeep()
282 {
283 $input = [
284 'defaultLanguageRow' => [],
285 'processedTca' => [
286 'columns' => [
287 'aField' => [
288 'config' => [
289 'type' => 'inline',
290 'foreign_table' => 'aForeignTableName',
291 'behaviour' => [
292 'localizationMode' => 'keep',
293 ]
294 ],
295 ],
296 ],
297 ],
298 ];
299 $expected = $input;
300 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
301 $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'keep';
302 $this->assertEquals($expected, $this->subject->addData($input));
303 }
304
305 /**
306 * @test
307 */
308 public function addDataSetsLocalizationModeToNoneIfNotSetAndChildIsNotLocalizable()
309 {
310 $input = [
311 'defaultLanguageRow' => [],
312 'processedTca' => [
313 'columns' => [
314 'aField' => [
315 'config' => [
316 'type' => 'inline',
317 'foreign_table' => 'aForeignTableName',
318 ],
319 ],
320 ],
321 ],
322 ];
323 $expected = $input;
324 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
325 $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'none';
326 $this->assertEquals($expected, $this->subject->addData($input));
327 }
328
329 /**
330 * @test
331 */
332 public function addDataSetsLocalizationModeToSelectIfNotSetAndChildIsLocalizable()
333 {
334 $input = [
335 'defaultLanguageRow' => [],
336 'processedTca' => [
337 'columns' => [
338 'aField' => [
339 'config' => [
340 'type' => 'inline',
341 'foreign_table' => 'aForeignTableName',
342 ],
343 ],
344 ],
345 ],
346 ];
347 $GLOBALS['TCA']['aForeignTableName']['ctrl'] = [
348 'languageField' => 'theLanguageField',
349 'transOrigPointerField' => 'theTransOrigPointerField',
350 ];
351 $expected = $input;
352 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
353 $expected['processedTca']['columns']['aField']['config']['behaviour']['localizationMode'] = 'select';
354 $this->assertEquals($expected, $this->subject->addData($input));
355 }
356
357 /**
358 * @test
359 */
360 public function addDataMergesWithGivenAppearanceSettings()
361 {
362 $input = [
363 'processedTca' => [
364 'columns' => [
365 'aField' => [
366 'config' => [
367 'type' => 'inline',
368 'foreign_table' => 'aForeignTableName',
369 'appearance' => [
370 'levelLinksPosition' => 'both',
371 'enabledControls' => [
372 'dragdrop' => false,
373 ],
374 ],
375 ],
376 ],
377 ],
378 ],
379 ];
380 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
381 $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
382 $expected['processedTca']['columns']['aField']['config']['appearance']['enabledControls']['dragdrop'] = false;
383 $this->assertEquals($expected, $this->subject->addData($input));
384 }
385
386 /**
387 * @test
388 */
389 public function addDataForcesLevelLinksPositionWithForeignSelector()
390 {
391 $input = [
392 'processedTca' => [
393 'columns' => [
394 'aField' => [
395 'config' => [
396 'type' => 'inline',
397 'foreign_table' => 'aForeignTableName',
398 'foreign_selector' => 'foo',
399 'appearance' => [
400 'levelLinksPosition' => 'both',
401 ],
402 ],
403 ],
404 ],
405 ],
406 ];
407 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
408 $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'foo';
409 $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'none';
410 $this->assertEquals($expected, $this->subject->addData($input));
411 }
412
413 /**
414 * @test
415 */
416 public function addDataKeepsLevelLinksPositionWithForeignSelectorAndUseCombination()
417 {
418 $input = [
419 'processedTca' => [
420 'columns' => [
421 'aField' => [
422 'config' => [
423 'type' => 'inline',
424 'foreign_table' => 'aForeignTableName',
425 'foreign_selector' => 'foo',
426 'appearance' => [
427 'useCombination' => true,
428 'levelLinksPosition' => 'both',
429 ],
430 ],
431 ],
432 ],
433 ],
434 ];
435 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
436 $expected['processedTca']['columns']['aField']['config']['foreign_selector'] = 'foo';
437 $expected['processedTca']['columns']['aField']['config']['appearance']['useCombination'] = true;
438 $expected['processedTca']['columns']['aField']['config']['appearance']['levelLinksPosition'] = 'both';
439 $this->assertEquals($expected, $this->subject->addData($input));
440 }
441
442 /**
443 * @test
444 */
445 public function addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanTrue()
446 {
447 $input = [
448 'processedTca' => [
449 'columns' => [
450 'aField' => [
451 'config' => [
452 'type' => 'inline',
453 'foreign_table' => 'aForeignTableName',
454 'appearance' => [
455 'showPossibleLocalizationRecords' => '1',
456 ],
457 ],
458 ],
459 ],
460 ],
461 ];
462 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
463 $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = true;
464 $this->assertEquals($expected, $this->subject->addData($input));
465 }
466
467 /**
468 * @test
469 */
470 public function addDataKeepsShowPossibleLocalizationRecordsButForcesBooleanFalse()
471 {
472 $input = [
473 'processedTca' => [
474 'columns' => [
475 'aField' => [
476 'config' => [
477 'type' => 'inline',
478 'foreign_table' => 'aForeignTableName',
479 'appearance' => [
480 'showPossibleLocalizationRecords' => 0,
481 ],
482 ],
483 ],
484 ],
485 ],
486 ];
487 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
488 $expected['processedTca']['columns']['aField']['config']['appearance']['showPossibleLocalizationRecords'] = false;
489 $this->assertEquals($expected, $this->subject->addData($input));
490 }
491
492 /**
493 * @test
494 */
495 public function addDataKeepshowRemovedLocalizationRecordsButForcesBooleanTrue()
496 {
497 $input = [
498 'processedTca' => [
499 'columns' => [
500 'aField' => [
501 'config' => [
502 'type' => 'inline',
503 'foreign_table' => 'aForeignTableName',
504 'appearance' => [
505 'showRemovedLocalizationRecords' => 1,
506 ],
507 ],
508 ],
509 ],
510 ],
511 ];
512 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
513 $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = true;
514 $this->assertEquals($expected, $this->subject->addData($input));
515 }
516
517 /**
518 * @test
519 */
520 public function addDataKeepsShowRemovedLocalizationRecordsButForcesBooleanFalse()
521 {
522 $input = [
523 'processedTca' => [
524 'columns' => [
525 'aField' => [
526 'config' => [
527 'type' => 'inline',
528 'foreign_table' => 'aForeignTableName',
529 'appearance' => [
530 'showRemovedLocalizationRecords' => '',
531 ],
532 ],
533 ],
534 ],
535 ],
536 ];
537 $expected['processedTca']['columns']['aField']['config'] = $this->defaultConfig;
538 $expected['processedTca']['columns']['aField']['config']['appearance']['showRemovedLocalizationRecords'] = false;
539 $this->assertEquals($expected, $this->subject->addData($input));
540 }
541 }