‪TYPO3CMS  10.4
VariableProcessorTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪VariableProcessorTest extends UnitTestCase
24 {
28  protected ‪$subject;
29 
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->subject = new ‪VariableProcessor();
34  }
35 
36  protected function ‪tearDown(): void
37  {
38  unset($this->subject);
39  parent::tearDown();
40  }
41 
42  public function ‪routePathDataProvider(): array
43  {
44  $plainInflatedRoutePath = '/static/{aa}/{bb}/{some_cc}/tail';
45  $enforcedInflatedRoutePath = '/static/{!aa}/{bb}/{some_cc}/tail';
46 
47  return [
48  'no arguments, no namespace (plain)' => [
49  null,
50  [],
51  $plainInflatedRoutePath,
52  '/static/{aa}/{bb}/{some_cc}/tail'
53  ],
54  'no arguments, no namespace (enforced)' => [
55  null,
56  [],
57  $enforcedInflatedRoutePath,
58  '/static/{!aa}/{bb}/{some_cc}/tail'
59  ],
60  'aa -> 1, no namespace (plain)' => [
61  null,
62  ['aa' => 1],
63  $plainInflatedRoutePath,
64  '/static/{1}/{bb}/{some_cc}/tail'
65  ],
66  'aa -> zz, no namespace (plain)' => [
67  null,
68  ['aa' => 'zz'],
69  $plainInflatedRoutePath,
70  '/static/{zz}/{bb}/{some_cc}/tail'
71  ],
72  'aa -> zz, no namespace (enforced)' => [
73  null,
74  ['aa' => 'zz'],
75  $enforcedInflatedRoutePath,
76  '/static/{!zz}/{bb}/{some_cc}/tail'
77  ],
78  'aa -> @any/nested, no namespace (plain)' => [
79  null,
80  ['aa' => '@any/nested'],
81  $plainInflatedRoutePath,
82  '/static/{qbeced67e6b340abc67a397f6e90bb0}/{bb}/{some_cc}/tail'
83  ],
84  'aa -> @any/nested, no namespace (enforced)' => [
85  null,
86  ['aa' => '@any/nested'],
87  $enforcedInflatedRoutePath,
88  '/static/{!qbeced67e6b340abc67a397f6e90bb0}/{bb}/{some_cc}/tail'
89  ],
90  'no arguments, first (plain)' => [
91  'first',
92  [],
93  $plainInflatedRoutePath,
94  '/static/{first__aa}/{first__bb}/{first__some_cc}/tail'
95  ],
96  'no arguments, first (enforced)' => [
97  'first',
98  [],
99  $enforcedInflatedRoutePath,
100  '/static/{!first__aa}/{first__bb}/{first__some_cc}/tail'
101  ],
102  'aa -> zz, first (plain)' => [
103  'first',
104  ['aa' => 'zz'],
105  $plainInflatedRoutePath,
106  '/static/{first__zz}/{first__bb}/{first__some_cc}/tail'
107  ],
108  'aa -> zz, first (enforced)' => [
109  'first',
110  ['aa' => 'zz'],
111  $enforcedInflatedRoutePath,
112  '/static/{!first__zz}/{first__bb}/{first__some_cc}/tail'
113  ],
114  'aa -> any/nested, first (plain)' => [
115  'first',
116  ['aa' => 'any/nested'],
117  $plainInflatedRoutePath,
118  '/static/{first__any__nested}/{first__bb}/{first__some_cc}/tail'
119  ],
120  'aa -> any/nested, first (enforced)' => [
121  'first',
122  ['aa' => 'any/nested'],
123  $enforcedInflatedRoutePath,
124  '/static/{!first__any__nested}/{first__bb}/{first__some_cc}/tail'
125  ],
126  'aa -> @any/nested, first (plain)' => [
127  'first',
128  ['aa' => '@any/nested'],
129  $plainInflatedRoutePath,
130  '/static/{ab0ce8f9f822228b4f324ec38b9c038}/{first__bb}/{first__some_cc}/tail'
131  ],
132  'aa -> @any/nested, first (enforced)' => [
133  'first',
134  ['aa' => '@any/nested'],
135  $enforcedInflatedRoutePath,
136  '/static/{!ab0ce8f9f822228b4f324ec38b9c038}/{first__bb}/{first__some_cc}/tail'
137  ],
138  ];
139  }
140 
150  public function ‪isRoutePathProcessed(?string $namespace, array $arguments, string $inflatedRoutePath, string $deflatedRoutePath)
151  {
152  self::assertSame(
153  $deflatedRoutePath,
154  $this->subject->deflateRoutePath($inflatedRoutePath, $namespace, $arguments)
155  );
156  self::assertSame(
157  $inflatedRoutePath,
158  $this->subject->inflateRoutePath($deflatedRoutePath, $namespace, $arguments)
159  );
160  }
161 
165  public function ‪parametersDataProvider(): array
166  {
167  return [
168  'no namespace, no arguments' => [
169  [],
170  ['a' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
171  ],
172  'no namespace, a -> newA' => [
173  ['a' => 'newA'],
174  ['newA' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
175  ],
176  'no namespace, a -> 1' => [
177  ['a' => 1],
178  [1 => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
179  ],
180  'no namespace, a -> @any/nested' => [
181  ['a' => '@any/nested'],
182  ['qbeced67e6b340abc67a397f6e90bb0' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
183  ],
184  ];
185  }
186 
194  public function ‪parametersAreProcessed(array $arguments, array $deflatedParameters)
195  {
196  $inflatedParameters = ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]];
197  self::assertEquals(
198  $deflatedParameters,
199  $this->subject->deflateParameters($inflatedParameters, $arguments)
200  );
201  self::assertEquals(
202  $inflatedParameters,
203  $this->subject->inflateParameters($deflatedParameters, $arguments)
204  );
205  }
206 
210  public function ‪namespaceParametersDataProvider(): array
211  {
212  return [
213  // no changes expected without having a non-empty namespace
214  'no namespace, no arguments' => [
215  '',
216  [],
217  ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]]
218  ],
219  'no namespace, a -> 1' => [
220  '',
221  ['a' => 1],
222  ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]]
223  ],
224  'no namespace, a -> newA' => [
225  '',
226  ['a' => 'newA'],
227  ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]]
228  ],
229  'no namespace, a -> @any/nested' => [
230  '',
231  ['a' => '@any/nested'],
232  ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]]
233  ],
234  // changes for namespace 'first' are expected
235  'first, no arguments' => [
236  'first',
237  [],
238  ['a' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
239  ],
240  'first, aa -> newAA' => [
241  'first',
242  ['aa' => 'newAA'],
243  ['a' => 'a', 'first__newAA' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
244  ],
245  'first, second -> newSecond' => [
246  'first',
247  ['second' => 'newSecond'],
248  ['a' => 'a', 'first__aa' => 'aa', 'first__newSecond__aaa' => 'aaa', 'q7aded81f5d1607191c695720db7ab2' => '@any']
249  ],
250  'first, aa -> any/nested' => [
251  'first',
252  ['aa' => 'any/nested'],
253  ['a' => 'a', 'first__any__nested' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
254  ],
255  'first, aa -> @any/nested' => [
256  'first',
257  ['aa' => '@any/nested'],
258  ['a' => 'a', 'ab0ce8f9f822228b4f324ec38b9c038' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any']
259  ],
260  'first, aa -> newAA, second => newSecond' => [
261  'first',
262  ['aa' => 'newAA', 'second' => 'newSecond'],
263  ['a' => 'a', 'first__newAA' => 'aa', 'first__newSecond__aaa' => 'aaa', 'q7aded81f5d1607191c695720db7ab2' => '@any']
264  ],
265  ];
266  }
267 
276  public function ‪namespaceParametersAreProcessed(string $namespace, array $arguments, array $deflatedParameters)
277  {
278  $inflatedParameters = ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]];
279  self::assertEquals(
280  $deflatedParameters,
281  $this->subject->deflateNamespaceParameters($inflatedParameters, $namespace, $arguments)
282  );
283  self::assertEquals(
284  $inflatedParameters,
285  $this->subject->inflateNamespaceParameters($deflatedParameters, $namespace, $arguments)
286  );
287  }
288 
289  public function ‪keysDataProvider(): array
290  {
291  return array_merge(
294  );
295  }
296 
297  public function ‪regularKeysDataProvider(): array
298  {
299  return [
300  'no arguments, no namespace' => [
301  null,
302  [],
303  ['a' => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']]
304  ],
305  'a -> 1, no namespace' => [
306  null,
307  ['a' => 1],
308  [1 => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']]
309  ],
310  'a -> newA, no namespace' => [
311  null,
312  ['a' => 'newA'],
313  ['newA' => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']]
314  ],
315  'no arguments, first' => [
316  'first',
317  [],
318  ['first__a' => 'a', 'first__b' => 'b', 'first__c' => ['d' => 'd', 'e' => 'e']]
319  ],
320  'a -> newA, first' => [
321  'first',
322  ['a' => 'newA'],
323  ['first__newA' => 'a', 'first__b' => 'b', 'first__c' => ['d' => 'd', 'e' => 'e']]
324  ],
325  'a -> any/nested, first' => [
326  'first',
327  ['a' => 'any/nested'],
328  ['first__any__nested' => 'a', 'first__b' => 'b', 'first__c' => ['d' => 'd', 'e' => 'e']]
329  ],
330  'd -> newD, first' => [
331  'first',
332  ['d' => 'newD'], // not substituted, which is expected
333  ['first__a' => 'a', 'first__b' => 'b', 'first__c' => ['d' => 'd', 'e' => 'e']]
334  ],
335  ];
336  }
337 
338  public function ‪specialKeysDataProvider(): array
339  {
340  return [
341  'a -> @any/nested, no namespace' => [
342  null,
343  ['a' => '@any/nested'],
344  ['qbeced67e6b340abc67a397f6e90bb0' => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']]
345  ],
346  'a -> newA, namespace_being_longer_than_32_characters' => [
347  'namespace_being_longer_than_32_characters',
348  ['a' => 'newA'],
349  ['qaea1f31c57b9c3e78c8205838d4563' => 'a', 'ub5e2989b61a4964ba4e06fc6de8527' => 'b', 'oabf16f448f7b02c6ecb13d155e5a4b' => ['d' => 'd', 'e' => 'e']]
350  ],
351  'a -> @any/nested, first' => [
352  'first',
353  ['a' => '@any/nested'],
354  ['ab0ce8f9f822228b4f324ec38b9c038' => 'a', 'first__b' => 'b', 'first__c' => ['d' => 'd', 'e' => 'e']]
355  ],
356  ];
357  }
358 
367  public function ‪keysAreDeflated(?string $namespace, array $arguments, array $deflatedKeys)
368  {
369  $inflatedKeys = ['a' => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']];
370  self::assertEquals(
371  $deflatedKeys,
372  $this->subject->deflateKeys($inflatedKeys, $namespace, $arguments)
373  );
374  self::assertEquals(
375  $inflatedKeys,
376  $this->subject->inflateKeys($deflatedKeys, $namespace, $arguments)
377  );
378  }
379 
388  public function ‪specialKeysAreNotInflatedWithoutBeingDeflated(?string $namespace, array $arguments, array $deflatedKeys)
389  {
390  $this->expectException(\OutOfRangeException::class);
391  $this->expectExceptionCode(1537633463);
392  $this->subject->inflateKeys($deflatedKeys, $namespace, $arguments);
393  }
394 }
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\parametersDataProvider
‪array parametersDataProvider()
Definition: VariableProcessorTest.php:164
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\namespaceParametersAreProcessed
‪namespaceParametersAreProcessed(string $namespace, array $arguments, array $deflatedParameters)
Definition: VariableProcessorTest.php:275
‪TYPO3\CMS\Core\Routing\Enhancer\VariableProcessor
Definition: VariableProcessor.php:24
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\specialKeysAreNotInflatedWithoutBeingDeflated
‪specialKeysAreNotInflatedWithoutBeingDeflated(?string $namespace, array $arguments, array $deflatedKeys)
Definition: VariableProcessorTest.php:387
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\tearDown
‪tearDown()
Definition: VariableProcessorTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\regularKeysDataProvider
‪regularKeysDataProvider()
Definition: VariableProcessorTest.php:296
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\keysAreDeflated
‪keysAreDeflated(?string $namespace, array $arguments, array $deflatedKeys)
Definition: VariableProcessorTest.php:366
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\namespaceParametersDataProvider
‪array namespaceParametersDataProvider()
Definition: VariableProcessorTest.php:209
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\keysDataProvider
‪keysDataProvider()
Definition: VariableProcessorTest.php:288
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\routePathDataProvider
‪routePathDataProvider()
Definition: VariableProcessorTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\$subject
‪VariableProcessor $subject
Definition: VariableProcessorTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\specialKeysDataProvider
‪specialKeysDataProvider()
Definition: VariableProcessorTest.php:337
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\parametersAreProcessed
‪parametersAreProcessed(array $arguments, array $deflatedParameters)
Definition: VariableProcessorTest.php:193
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest
Definition: VariableProcessorTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\isRoutePathProcessed
‪isRoutePathProcessed(?string $namespace, array $arguments, string $inflatedRoutePath, string $deflatedRoutePath)
Definition: VariableProcessorTest.php:149
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\VariableProcessorTest\setUp
‪setUp()
Definition: VariableProcessorTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer
Definition: VariableProcessorTest.php:18