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