‪TYPO3CMS  ‪main
InheritancesResolverServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪InheritancesResolverServiceTest extends UnitTestCase
26 {
30  protected ‪$subject;
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  $this->subject = new ‪InheritancesResolverService();
36  }
37 
38  #[Test]
39  public function ‪getDocExampleInheritance(): void
40  {
41  $input = [
42  'Form' => [
43  'part1' => [
44  'key1' => 'value1',
45  'key2' => 'value2',
46  'key3' => 'value3',
47  ],
48  'part2' => [
49  '__inheritances' => [
50  10 => 'Form.part1',
51  ],
52  'key2' => 'another_value',
53  ],
54  ],
55  ];
56 
57  $expected = [
58  'Form' => [
59  'part1' => [
60  'key1' => 'value1',
61  'key2' => 'value2',
62  'key3' => 'value3',
63  ],
64  'part2' => [
65  'key1' => 'value1',
66  'key2' => 'another_value',
67  'key3' => 'value3',
68  ],
69  ],
70  ];
71 
72  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
73  }
74 
75  #[Test]
76  public function ‪getMergedConfigurationSimpleInheritance(): void
77  {
78  $input = [
79  'Form' => [
80  'klaus01' => [
81  'key01' => 'value',
82  'key02' => [
83  'key03' => 'value',
84  ],
85  ],
86  'klaus02' => [
87  '__inheritances' => [
88  10 => 'Form.klaus01',
89  ],
90  ],
91  ],
92  ];
93 
94  $expected = [
95  'Form' => [
96  'klaus01' => [
97  'key01' => 'value',
98  'key02' => [
99  'key03' => 'value',
100  ],
101  ],
102  'klaus02' => [
103  'key01' => 'value',
104  'key02' => [
105  'key03' => 'value',
106  ],
107  ],
108  ],
109  ];
110 
111  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
112  }
113 
114  #[Test]
116  {
117  $input = [
118  'Form' => [
119  'klaus01' => [
120  'key' => 'value',
121  ],
122  'klaus02' => [
123  '__inheritances' => [
124  10 => 'Form.klaus01',
125  ],
126  'key' => 'value override',
127  ],
128  ],
129  ];
130 
131  $expected = [
132  'Form' => [
133  'klaus01' => [
134  'key' => 'value',
135  ],
136  'klaus02' => [
137  'key' => 'value override',
138  ],
139  ],
140  ];
141 
142  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
143  }
144 
145  #[Test]
147  {
148  $input = [
149  'Form' => [
150  'klaus01' => [
151  'key01' => [
152  'key02' => 'value',
153  ],
154  'key02' => [
155  10 => [
156  'key' => 'value',
157  ],
158  20 => [
159  'key' => 'value',
160  ],
161  ],
162  ],
163  'klaus02' => [
164  '__inheritances' => [
165  10 => 'Form.klaus01',
166  ],
167  'key01' => null,
168  'key02' => [
169  10 => null,
170  20 => [
171  'key' => null,
172  ],
173  ],
174  ],
175  ],
176  ];
177 
178  $expected = [
179  'Form' => [
180  'klaus01' => [
181  'key01' => [
182  'key02' => 'value',
183  ],
184  'key02' => [
185  10 => [
186  'key' => 'value',
187  ],
188  20 => [
189  'key' => 'value',
190  ],
191  ],
192  ],
193  'klaus02' => [
194  'key01' => null,
195  'key02' => [
196  10 => null,
197  20 => [
198  'key' => null,
199  ],
200  ],
201  ],
202  ],
203  ];
204 
205  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
206  }
207 
208  #[Test]
209  public function ‪getMergedConfigurationSimpleMixin(): void
210  {
211  $input = [
212  'Form' => [
213  'mixin01' => [
214  'key' => 'value',
215  ],
216  'klaus01' => [
217  '__inheritances' => [
218  10 => 'Form.mixin01',
219  ],
220  ],
221  'klaus02' => [
222  'key' => [
223  '__inheritances' => [
224  10 => 'Form.mixin01',
225  ],
226  ],
227  ],
228  ],
229  ];
230 
231  $expected = [
232  'Form' => [
233  'mixin01' => [
234  'key' => 'value',
235  ],
236  'klaus01' => [
237  'key' => 'value',
238  ],
239  'klaus02' => [
240  'key' => [
241  'key' => 'value',
242  ],
243  ],
244  ],
245  ];
246 
247  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
248  }
249 
250  #[Test]
251  public function ‪getMergedConfigurationAdvancedMixin(): void
252  {
253  $input = [
254  'Form' => [
255  'mixin01' => [
256  'key01' => 'value01',
257  'key02' => 'value02',
258  ],
259  'mixin02' => [
260  '__inheritances' => [
261  10 => 'Form.mixin01',
262  ],
263  ],
264  'mixin03' => [
265  'key03' => 'value03',
266  ],
267 
268  'klaus01' => [
269  '__inheritances' => [
270  10 => 'Form.mixin01',
271  ],
272  'key01' => 'value01 override 01',
273  ],
274  'klaus02' => [
275  '__inheritances' => [
276  10 => 'Form.klaus01',
277  20 => 'Form.mixin03',
278  ],
279  'key01' => 'value01 override 02',
280  'key02' => [
281  'horst01' => 'gerda01',
282  ],
283  'key03' => [
284  '__inheritances' => [
285  10 => 'Form.mixin02',
286  ],
287  'key02' => null,
288  ],
289  ],
290  'klaus03' => [
291  '__inheritances' => [
292  10 => 'Form.klaus02',
293  ],
294  ],
295  ],
296  ];
297 
298  $expected = [
299  'Form' => [
300  'mixin01' => [
301  'key01' => 'value01',
302  'key02' => 'value02',
303  ],
304  'mixin02' => [
305  'key01' => 'value01',
306  'key02' => 'value02',
307  ],
308  'mixin03' => [
309  'key03' => 'value03',
310  ],
311  'klaus01' => [
312  'key01' => 'value01 override 01',
313  'key02' => 'value02',
314  ],
315  'klaus02' => [
316  'key01' => 'value01 override 02',
317  'key02' => [
318  'horst01' => 'gerda01',
319  ],
320  'key03' => [
321  'key01' => 'value01',
322  'key02' => null,
323  ],
324  ],
325  'klaus03' => [
326  'key01' => 'value01 override 02',
327  'key02' => [
328  'horst01' => 'gerda01',
329  ],
330  'key03' => [
331  'key01' => 'value01',
332  'key02' => null,
333  ],
334  ],
335  ],
336  ];
337 
338  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
339  }
340 
341  #[Test]
343  {
344  $input = [
345  'mixin01' => [
346  'key01' => 'value01',
347  'key02' => 'value02',
348  ],
349  'mixin02' => [
350  '__inheritances' => [
351  10 => 'mixin01',
352  ],
353  ],
354  'mixin03' => [
355  'key03' => 'value03',
356  ],
357 
358  'klaus01' => [
359  '__inheritances' => [
360  10 => 'TYPO3.CMS.Form.mixin01',
361  ],
362  'key01' => 'value01 override 01',
363  ],
364  'klaus02' => [
365  '__inheritances' => [
366  10 => 'klaus01',
367  20 => 'TYPO3.CMS.Form.mixin03',
368  ],
369  'key01' => 'value01 override 02',
370  'key02' => [
371  'horst01' => 'gerda01',
372  ],
373  'key03' => [
374  '__inheritances' => [
375  10 => 'mixin02',
376  ],
377  'key02' => null,
378  ],
379  ],
380  'klaus03' => [
381  '__inheritances' => [
382  10 => 'klaus02',
383  ],
384  ],
385  ];
386 
387  $expected = [
388  'mixin01' => [
389  'key01' => 'value01',
390  'key02' => 'value02',
391  ],
392  'mixin02' => [
393  'key01' => 'value01',
394  'key02' => 'value02',
395  ],
396  'mixin03' => [
397  'key03' => 'value03',
398  ],
399  'klaus01' => [
400  'key01' => 'value01 override 01',
401  'key02' => 'value02',
402  ],
403  'klaus02' => [
404  'key01' => 'value01 override 02',
405  'key02' => [
406  'horst01' => 'gerda01',
407  ],
408  'key03' => [
409  'key01' => 'value01',
410  'key02' => null,
411  ],
412  ],
413  'klaus03' => [
414  'key01' => 'value01 override 02',
415  'key02' => [
416  'horst01' => 'gerda01',
417  ],
418  'key03' => [
419  'key01' => 'value01',
420  'key02' => null,
421  ],
422  ],
423  ];
424 
425  self::assertSame($expected, $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration());
426  }
427 
428  #[Test]
430  {
431  $input = [
432  'someKey' => [
433  '__inheritances' => [
434  10 => 'TYPO3.CMS.Form.anotherKey',
435  ],
436  ],
437  'anotherKey' => [
438  '__inheritances' => [
439  10 => 'TYPO3.CMS.Form.someKey',
440  ],
441  ],
442  ];
443 
444  $this->expectException(CycleInheritancesException::class);
445  $this->expectExceptionCode(1474900797);
446 
447  $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration();
448  }
449 
450  #[Test]
452  {
453  $input = [
454  'klaus1' => [
455  '__inheritances' => [
456  10 => 'TYPO3.CMS.Form.klaus2',
457  ],
458  ],
459  'klaus2' => [
460  '__inheritances' => [
461  10 => 'TYPO3.CMS.Form.mixin1',
462  ],
463  ],
464  'mixin1' => [
465  '__inheritances' => [
466  10 => 'TYPO3.CMS.Form.mixin2',
467  ],
468  ],
469  'mixin2' => [
470  '__inheritances' => [
471  10 => 'TYPO3.CMS.Form.klaus2',
472  ],
473  ],
474  ];
475 
476  $this->expectException(CycleInheritancesException::class);
477  $this->expectExceptionCode(1474900799);
478 
479  $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration();
480  }
481 
482  #[Test]
484  {
485  $input = [
486  'klaus1' => [
487  'key01' => 'value',
488  'key02' => [
489  '__inheritances' => [
490  10 => 'TYPO3.CMS.Form.mixin01',
491  ],
492  ],
493  ],
494  'klaus2' => [
495  '__inheritances' => [
496  10 => 'TYPO3.CMS.Form.klaus1',
497  ],
498  'key02' => [
499  '__inheritances' => [
500  10 => 'TYPO3.CMS.Form.mixin01',
501  20 => 'TYPO3.CMS.Form.mixin02',
502  ],
503  ],
504  ],
505  'mixin01' => [
506  'liselotte01' => 'value',
507  ],
508  'mixin02' => [
509  '__inheritances' => [
510  10 => 'TYPO3.CMS.Form.klaus2',
511  ],
512  'liselotte02' => 'value',
513  ],
514  ];
515 
516  $this->expectException(CycleInheritancesException::class);
517  $this->expectExceptionCode(1474900797);
518 
519  $this->subject->reset()->setReferenceConfiguration($input)->getResolvedConfiguration();
520  }
521 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationSimpleMixin
‪getMergedConfigurationSimpleMixin()
Definition: InheritancesResolverServiceTest.php:208
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration
Definition: ConfigurationManagerTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationSimpleInheritanceOverrideValue
‪getMergedConfigurationSimpleInheritanceOverrideValue()
Definition: InheritancesResolverServiceTest.php:114
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnSameLevelIsFound
‪getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnSameLevelIsFound()
Definition: InheritancesResolverServiceTest.php:428
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationSimpleInheritance
‪getMergedConfigurationSimpleInheritance()
Definition: InheritancesResolverServiceTest.php:75
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\setUp
‪setUp()
Definition: InheritancesResolverServiceTest.php:31
‪TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService
Definition: InheritancesResolverService.php:64
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationSimpleInheritanceRemoveValue
‪getMergedConfigurationSimpleInheritanceRemoveValue()
Definition: InheritancesResolverServiceTest.php:145
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getDocExampleInheritance
‪getDocExampleInheritance()
Definition: InheritancesResolverServiceTest.php:38
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\$subject
‪InheritancesResolverService $subject
Definition: InheritancesResolverServiceTest.php:29
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\CycleInheritancesException
Definition: CycleInheritancesException.php:28
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnSameLevelWithGapIsFound
‪getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnSameLevelWithGapIsFound()
Definition: InheritancesResolverServiceTest.php:450
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationAdvancedMixin
‪getMergedConfigurationAdvancedMixin()
Definition: InheritancesResolverServiceTest.php:250
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest
Definition: InheritancesResolverServiceTest.php:26
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getMergedConfigurationResolvesInheritancesWithAndWithoutVendorNamespacePrefix
‪getMergedConfigurationResolvesInheritancesWithAndWithoutVendorNamespacePrefix()
Definition: InheritancesResolverServiceTest.php:341
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration\InheritancesResolverServiceTest\getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnHigherLevelIsFound
‪getResolvedConfigurationThrowsExceptionIfCycleDependenciesOnHigherLevelIsFound()
Definition: InheritancesResolverServiceTest.php:482