‪TYPO3CMS  11.5
TypoScriptServiceTest.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 
26 class ‪TypoScriptServiceTest extends UnitTestCase
27 {
33  {
34  return [
35  'simple typoscript array' => [
36  'typoScriptSettings' => [
37  '10.' => [
38  'value' => 'Hello World!',
39  'foo.' => [
40  'bar' => 5,
41  ],
42  ],
43  '10' => 'TEXT',
44  ],
45  'expectedSettings' => [
46  '10' => [
47  'value' => 'Hello World!',
48  'foo' => [
49  'bar' => 5,
50  ],
51  '_typoScriptNodeValue' => 'TEXT',
52  ],
53  ],
54  ],
55  'typoscript with intermediate dots' => [
56  'typoScriptSettings' => [
57  '10.' => [
58  'value' => 'Hello World!',
59  'foo.' => [
60  'bar' => 5,
61  ],
62  ],
63  '10' => 'TEXT',
64  ],
65  'expectedSettings' => [
66  '10' => [
67  'value' => 'Hello World!',
68  'foo' => [
69  'bar' => 5,
70  ],
71  '_typoScriptNodeValue' => 'TEXT',
72  ],
73  ],
74  ],
75  'typoscript array with changed order' => [
76  'typoScriptSettings' => [
77  '10' => 'TEXT',
78  '10.' => [
79  'value' => 'Hello World!',
80  'foo.' => [
81  'bar' => 5,
82  ],
83  ],
84  ],
85  'expectedSettings' => [
86  '10' => [
87  'value' => 'Hello World!',
88  'foo' => [
89  'bar' => 5,
90  ],
91  '_typoScriptNodeValue' => 'TEXT',
92  ],
93  ],
94  ],
95  'nested typoscript array' => [
96  'typoScriptSettings' => [
97  '10' => 'COA',
98  '10.' => [
99  '10' => 'TEXT',
100  '10.' => [
101  'value' => 'Hello World!',
102  'foo.' => [
103  'bar' => 5,
104  ],
105  ],
106  '20' => 'COA',
107  '20.' => [
108  '10' => 'TEXT',
109  '10.' => [
110  'value' => 'Test',
111  'wrap' => '[|]',
112  ],
113  '20' => 'TEXT',
114  '20.' => [
115  'value' => 'Test',
116  'wrap' => '[|]',
117  ],
118  ],
119  '30' => 'custom',
120  ],
121  ],
122  'expectedSettings' => [
123  '10' => [
124  '10' => [
125  'value' => 'Hello World!',
126  'foo' => [
127  'bar' => 5,
128  ],
129  '_typoScriptNodeValue' => 'TEXT',
130  ],
131  '20' => [
132  '10' => [
133  'value' => 'Test',
134  'wrap' => '[|]',
135  '_typoScriptNodeValue' => 'TEXT',
136  ],
137  '20' => [
138  'value' => 'Test',
139  'wrap' => '[|]',
140  '_typoScriptNodeValue' => 'TEXT',
141  ],
142  '_typoScriptNodeValue' => 'COA',
143  ],
144  '30' => 'custom',
145  '_typoScriptNodeValue' => 'COA',
146  ],
147  ],
148  ],
149  ];
150  }
151 
159  $typoScriptSettings,
160  $expectedSettings
161  ): void {
162  $typoScriptService = new ‪TypoScriptService();
163  $processedSettings = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptSettings);
164  self::assertEquals($expectedSettings, $processedSettings);
165  }
166 
173  {
174  return [
175  'simple typoscript' => [
176  'extbaseTS' => [
177  '10' => [
178  'value' => 'Hallo',
179  '_typoScriptNodeValue' => 'TEXT',
180  ],
181  ],
182  'classic' => [
183  '10' => 'TEXT',
184  '10.' => [
185  'value' => 'Hallo',
186  ],
187  ],
188  ],
189  'typoscript with null value' => [
190  'extbaseTS' => [
191  '10' => [
192  'value' => 'Hallo',
193  '_typoScriptNodeValue' => 'TEXT',
194  ],
195  '20' => null,
196  ],
197  'classic' => [
198  '10' => 'TEXT',
199  '10.' => [
200  'value' => 'Hallo',
201  ],
202  '20' => '',
203  ],
204  ],
205  'ts with dots in key' => [
206  'extbaseTS' => [
207  '1.0' => [
208  'value' => 'Hallo',
209  '_typoScriptNodeValue' => 'TEXT',
210  ],
211  ],
212  'classic' => [
213  '1.0' => 'TEXT',
214  '1.0.' => [
215  'value' => 'Hallo',
216  ],
217  ],
218  ],
219  'ts with backslashes in key' => [
220  'extbaseTS' => [
221  '1\\0\\' => [
222  'value' => 'Hallo',
223  '_typoScriptNodeValue' => 'TEXT',
224  ],
225  ],
226  'classic' => [
227  '1\\0\\' => 'TEXT',
228  '1\\0\\.' => [
229  'value' => 'Hallo',
230  ],
231  ],
232  ],
233  'bigger typoscript' => [
234  'extbaseTS' => [
235  '10' => [
236  '10' => [
237  'value' => 'Hello World!',
238  'foo' => [
239  'bar' => 5,
240  ],
241  '_typoScriptNodeValue' => 'TEXT',
242  ],
243  '20' => [
244  '10' => [
245  'value' => 'Test',
246  'wrap' => '[|]',
247  '_typoScriptNodeValue' => 'TEXT',
248  ],
249  '20' => [
250  'value' => 'Test',
251  'wrap' => '[|]',
252  '_typoScriptNodeValue' => 'TEXT',
253  ],
254  '_typoScriptNodeValue' => 'COA',
255  ],
256  '_typoScriptNodeValue' => 'COA',
257  ],
258  ],
259  'classic' => [
260  '10' => 'COA',
261  '10.' => [
262  '10' => 'TEXT',
263  '10.' => [
264  'value' => 'Hello World!',
265  'foo.' => [
266  'bar' => 5,
267  ],
268  ],
269  '20' => 'COA',
270  '20.' => [
271  '10' => 'TEXT',
272  '10.' => [
273  'value' => 'Test',
274  'wrap' => '[|]',
275  ],
276  '20' => 'TEXT',
277  '20.' => [
278  'value' => 'Test',
279  'wrap' => '[|]',
280  ],
281  ],
282  ],
283  ],
284  ],
285  ];
286  }
287 
294  public function ‪convertPlainArrayToTypoScriptArray($extbaseTS, $classic): void
295  {
296  $typoScriptService = new ‪TypoScriptService();
297  $converted = $typoScriptService->convertPlainArrayToTypoScriptArray($extbaseTS);
298  self::assertEquals($converted, $classic);
299  }
300 
305  {
306  return [
307  [
308  ['splitConfiguration' => 'a'],
309  3,
310  [
311  0 => ['splitConfiguration' => 'a'],
312  1 => ['splitConfiguration' => 'a'],
313  2 => ['splitConfiguration' => 'a'],
314  ],
315  ],
316  [
317  ['splitConfiguration' => 'a || b || c'],
318  5,
319  [
320  0 => ['splitConfiguration' => 'a'],
321  1 => ['splitConfiguration' => 'b'],
322  2 => ['splitConfiguration' => 'c'],
323  3 => ['splitConfiguration' => 'c'],
324  4 => ['splitConfiguration' => 'c'],
325  ],
326  ],
327  [
328  ['splitConfiguration' => 'a || b |*| c'],
329  5,
330  [
331  0 => ['splitConfiguration' => 'a'],
332  1 => ['splitConfiguration' => 'b'],
333  2 => ['splitConfiguration' => 'c'],
334  3 => ['splitConfiguration' => 'c'],
335  4 => ['splitConfiguration' => 'c'],
336  ],
337  ],
338  [
339  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
340  7,
341  [
342  0 => ['splitConfiguration' => 'a'],
343  1 => ['splitConfiguration' => 'b'],
344  2 => ['splitConfiguration' => 'c'],
345  3 => ['splitConfiguration' => 'c'],
346  4 => ['splitConfiguration' => 'c'],
347  5 => ['splitConfiguration' => 'd'],
348  6 => ['splitConfiguration' => 'e'],
349  ],
350  ],
351  [
352  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
353  4,
354  [
355  0 => ['splitConfiguration' => 'a'],
356  1 => ['splitConfiguration' => 'b'],
357  2 => ['splitConfiguration' => 'd'],
358  3 => ['splitConfiguration' => 'e'],
359  ],
360  ],
361  [
362  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
363  3,
364  [
365  0 => ['splitConfiguration' => 'a'],
366  1 => ['splitConfiguration' => 'd'],
367  2 => ['splitConfiguration' => 'e'],
368  ],
369  ],
370  [
371  ['splitConfiguration' => 'a || b |*||*| c || d'],
372  7,
373  [
374  0 => ['splitConfiguration' => 'a'],
375  1 => ['splitConfiguration' => 'b'],
376  2 => ['splitConfiguration' => 'b'],
377  3 => ['splitConfiguration' => 'b'],
378  4 => ['splitConfiguration' => 'b'],
379  5 => ['splitConfiguration' => 'c'],
380  6 => ['splitConfiguration' => 'd'],
381  ],
382  ],
383  [
384  ['splitConfiguration' => '|*||*| a || b'],
385  7,
386  [
387  0 => ['splitConfiguration' => 'a'],
388  1 => ['splitConfiguration' => 'a'],
389  2 => ['splitConfiguration' => 'a'],
390  3 => ['splitConfiguration' => 'a'],
391  4 => ['splitConfiguration' => 'a'],
392  5 => ['splitConfiguration' => 'a'],
393  6 => ['splitConfiguration' => 'b'],
394  ],
395  ],
396  [
397  ['splitConfiguration' => 'a |*| b || c |*|'],
398  7,
399  [
400  0 => ['splitConfiguration' => 'a'],
401  1 => ['splitConfiguration' => 'b'],
402  2 => ['splitConfiguration' => 'c'],
403  3 => ['splitConfiguration' => 'b'],
404  4 => ['splitConfiguration' => 'c'],
405  5 => ['splitConfiguration' => 'b'],
406  6 => ['splitConfiguration' => 'c'],
407  ],
408  ],
409  ];
410  }
411 
417  public function ‪explodeConfigurationForOptionSplitTest($configuration, $splitCount, $expected): void
418  {
419  $serviceObject = new ‪TypoScriptService();
420  $actual = $serviceObject->explodeConfigurationForOptionSplit($configuration, $splitCount);
421  self::assertSame($expected, $actual);
422  }
423 }
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\convertTypoScriptArrayToPlainArrayTestdata
‪array convertTypoScriptArrayToPlainArrayTestdata()
Definition: TypoScriptServiceTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\convertPlainArrayToTypoScriptArray
‪convertPlainArrayToTypoScriptArray($extbaseTS, $classic)
Definition: TypoScriptServiceTest.php:294
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest
Definition: TypoScriptServiceTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\TypoScript
Definition: ExtendedTemplateServiceTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\convertTypoScriptArrayToPlainArrayRemovesTrailingDotsWithChangedOrderInTheTypoScriptArray
‪convertTypoScriptArrayToPlainArrayRemovesTrailingDotsWithChangedOrderInTheTypoScriptArray( $typoScriptSettings, $expectedSettings)
Definition: TypoScriptServiceTest.php:158
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\convertPlainArrayToTypoScriptArrayTestdata
‪array convertPlainArrayToTypoScriptArrayTestdata()
Definition: TypoScriptServiceTest.php:172
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\explodeConfigurationForOptionSplitTest
‪explodeConfigurationForOptionSplitTest($configuration, $splitCount, $expected)
Definition: TypoScriptServiceTest.php:417
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TypoScriptServiceTest\explodeConfigurationForOptionSplitProvider
‪array explodeConfigurationForOptionSplitProvider()
Definition: TypoScriptServiceTest.php:304