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