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