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