9717db4b21e6dba19201363eb7d51d86e9b878ba
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / Configuration / InheritancesResolverServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration;
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\Form\Mvc\Configuration\Exception\CycleInheritancesException;
18 use TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService;
19
20 /**
21 * Test case
22 */
23 class InheritancesResolverServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * Subject is not notice free, disable E_NOTICES
27 */
28 protected static $suppressNotices = true;
29
30 /**
31 * @var InheritancesResolverService
32 */
33 protected $subject;
34
35 protected function setUp()
36 {
37 $this->subject = new InheritancesResolverService();
38 }
39
40 /**
41 * @test
42 * Test for the explicit example in service class comment
43 */
44 public function getDocExampleInheritance()
45 {
46 $input = [
47 'Form' => [
48 'part1' => [
49 'key1' => 'value1',
50 'key2' => 'value2',
51 'key3' => 'value3',
52 ],
53 'part2' => [
54 '__inheritances' => [
55 10 => 'Form.part1',
56 ],
57 'key2' => 'another_value'
58 ],
59 ],
60 ];
61
62 $expected = [
63 'Form' => [
64 'part1' => [
65 'key1' => 'value1',
66 'key2' => 'value2',
67 'key3' => 'value3',
68 ],
69 'part2' => [
70 'key1' => 'value1',
71 'key2' => 'another_value',
72 'key3' => 'value3'
73 ],
74 ],
75 ];
76
77 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
78 }
79
80 /**
81 * @test
82 */
83 public function getMergedConfigurationSimpleInheritance()
84 {
85 $input = [
86 'Form' => [
87 'klaus01' => [
88 'key01' => 'value',
89 'key02' => [
90 'key03' => 'value',
91 ],
92 ],
93 'klaus02' => [
94 '__inheritances' => [
95 10 => 'Form.klaus01',
96 ],
97 ],
98 ],
99 ];
100
101 $expected = [
102 'Form' => [
103 'klaus01' => [
104 'key01' => 'value',
105 'key02' => [
106 'key03' => 'value'
107 ],
108 ],
109 'klaus02' => [
110 'key01' => 'value',
111 'key02' => [
112 'key03' => 'value',
113 ],
114 ],
115 ],
116 ];
117
118 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
119 }
120
121 /**
122 * @test
123 */
124 public function getMergedConfigurationSimpleInheritanceOverrideValue()
125 {
126 $input = [
127 'Form' => [
128 'klaus01' => [
129 'key' => 'value',
130 ],
131 'klaus02' => [
132 '__inheritances' => [
133 10 => 'Form.klaus01',
134 ],
135 'key' => 'value override',
136 ],
137 ],
138 ];
139
140 $expected = [
141 'Form' => [
142 'klaus01' => [
143 'key' => 'value',
144 ],
145 'klaus02' => [
146 'key' => 'value override',
147 ],
148 ],
149 ];
150
151 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
152 }
153
154 /**
155 * @test
156 */
157 public function getMergedConfigurationSimpleInheritanceRemoveValue()
158 {
159 $input = [
160 'Form' => [
161 'klaus01' => [
162 'key01' => [
163 'key02' => 'value',
164 ],
165 'key02' => [
166 10 => [
167 'key' => 'value',
168 ],
169 20 => [
170 'key' => 'value',
171 ],
172 ],
173 ],
174 'klaus02' => [
175 '__inheritances' => [
176 10 => 'Form.klaus01',
177 ],
178 'key01' => null,
179 'key02' => [
180 10 => null,
181 20 => [
182 'key' => null,
183 ],
184 ],
185 ],
186 ],
187 ];
188
189 $expected = [
190 'Form' => [
191 'klaus01' => [
192 'key01' => [
193 'key02' => 'value',
194 ],
195 'key02' => [
196 10 => [
197 'key' => 'value',
198 ],
199 20 => [
200 'key' => 'value',
201 ],
202 ],
203 ],
204 'klaus02' => [
205 'key01' => null,
206 'key02' => [
207 10 => null,
208 20 => [
209 'key' => null,
210 ],
211 ],
212 ],
213 ],
214 ];
215
216 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
217 }
218
219 /**
220 * @test
221 */
222 public function getMergedConfigurationSimpleMixin()
223 {
224 $input = [
225 'Form' => [
226 'mixin01' => [
227 'key' => 'value',
228 ],
229 'klaus01' => [
230 '__inheritances' => [
231 10 => 'Form.mixin01',
232 ],
233 ],
234 'klaus02' => [
235 'key' => [
236 '__inheritances' => [
237 10 => 'Form.mixin01',
238 ],
239 ],
240 ],
241 ],
242 ];
243
244 $expected = [
245 'Form' => [
246 'mixin01' => [
247 'key' => 'value',
248 ],
249 'klaus01' => [
250 'key' => 'value',
251 ],
252 'klaus02' => [
253 'key' => [
254 'key' => 'value',
255 ],
256 ],
257 ],
258 ];
259
260 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
261 }
262
263 /**
264 * @test
265 */
266 public function getMergedConfigurationAdvancedMixin()
267 {
268 $input = [
269 'Form' => [
270 'mixin01' => [
271 'key01' => 'value01',
272 'key02' => 'value02',
273 ],
274 'mixin02' => [
275 '__inheritances' => [
276 10 => 'Form.mixin01',
277 ],
278 ],
279 'mixin03' => [
280 'key03' => 'value03',
281 ],
282
283 'klaus01' => [
284 '__inheritances' => [
285 10 => 'Form.mixin01',
286 ],
287 'key01' => 'value01 override 01',
288 ],
289 'klaus02' => [
290 '__inheritances' => [
291 10 => 'Form.klaus01',
292 20 => 'Form.mixin03',
293 ],
294 'key01' => 'value01 override 02',
295 'key02' => [
296 'horst01' => 'gerda01'
297 ],
298 'key03' => [
299 '__inheritances' => [
300 10 => 'Form.mixin02',
301 ],
302 'key02' => null,
303 ],
304 ],
305 'klaus03' => [
306 '__inheritances' => [
307 10 => 'Form.klaus02',
308 ],
309 ],
310 ],
311 ];
312
313 $expected = [
314 'Form' => [
315 'mixin01' => [
316 'key01' => 'value01',
317 'key02' => 'value02',
318 ],
319 'mixin02' => [
320 'key01' => 'value01',
321 'key02' => 'value02',
322 ],
323 'mixin03' => [
324 'key03' => 'value03',
325 ],
326 'klaus01' => [
327 'key01' => 'value01 override 01',
328 'key02' => 'value02',
329 ],
330 'klaus02' => [
331 'key01' => 'value01 override 02',
332 'key02' => [
333 'horst01' => 'gerda01'
334 ],
335 'key03' => [
336 'key01' => 'value01',
337 'key02' => null,
338 ],
339 ],
340 'klaus03' => [
341 'key01' => 'value01 override 02',
342 'key02' => [
343 'horst01' => 'gerda01'
344 ],
345 'key03' => [
346 'key01' => 'value01',
347 'key02' => null,
348 ],
349 ],
350 ],
351 ];
352
353 $this->assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input));
354 }
355
356 /**
357 * @test
358 */
359 public function getResolvedConfigurationThrowsExceptionIfCycleDepenciesOnSameLevelIsFound()
360 {
361 $input = [
362 'TYPO3' => [
363 'CMS' => [
364 'Form' => [
365 'someKey' => [
366 '__inheritances' => [
367 10 => 'TYPO3.CMS.Form.anotherKey',
368 ],
369 ],
370 'anotherKey' => [
371 '__inheritances' => [
372 10 => 'TYPO3.CMS.Form.someKey',
373 ],
374 ],
375 ],
376 ],
377 ],
378 ];
379
380 $this->expectException(CycleInheritancesException::class);
381 $this->expectExceptionCode(1474900797);
382
383 $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input);
384 }
385
386 /**
387 * @test
388 */
389 public function getResolvedConfigurationThrowsExceptionIfCycleDepenciesOnSameLevelWithGapIsFound()
390 {
391 $input = [
392 'TYPO3' => [
393 'CMS' => [
394 'Form' => [
395 'klaus1' => [
396 '__inheritances' => [
397 10 => 'TYPO3.CMS.Form.klaus2',
398 ],
399 ],
400 'klaus2' => [
401 '__inheritances' => [
402 10 => 'TYPO3.CMS.Form.mixin1',
403 ],
404 ],
405 'mixin1' => [
406 '__inheritances' => [
407 10 => 'TYPO3.CMS.Form.mixin2',
408 ],
409 ],
410 'mixin2' => [
411 '__inheritances' => [
412 10 => 'TYPO3.CMS.Form.klaus2',
413 ],
414 ],
415 ],
416 ],
417 ],
418 ];
419
420 $this->expectException(CycleInheritancesException::class);
421 $this->expectExceptionCode(1474900799);
422
423 $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input);
424 }
425
426 /**
427 * @test
428 */
429 public function getResolvedConfigurationThrowsExceptionIfCycleDepenciesOnHigherLevelIsFound()
430 {
431 $input = [
432 'TYPO3' => [
433 'CMS' => [
434 'Form' => [
435 'klaus1' => [
436 'key01' => 'value',
437 'key02' => [
438 '__inheritances' => [
439 10 => 'TYPO3.CMS.Form.mixin01',
440 ],
441 ],
442 ],
443 'klaus2' => [
444 '__inheritances' => [
445 10 => 'TYPO3.CMS.Form.klaus1',
446 ],
447 'key02' => [
448 '__inheritances' => [
449 10 => 'TYPO3.CMS.Form.mixin01',
450 20 => 'TYPO3.CMS.Form.mixin02',
451 ],
452 ],
453 ],
454 'mixin01' => [
455 'liselotte01' => 'value',
456 ],
457 'mixin02' => [
458 '__inheritances' => [
459 10 => 'TYPO3.CMS.Form.klaus2',
460 ],
461 'liselotte02' => 'value',
462 ],
463 ],
464 ],
465 ],
466 ];
467
468 $this->expectException(CycleInheritancesException::class);
469 $this->expectExceptionCode(1474900797);
470
471 $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration($input);
472 }
473 }