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