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