‪TYPO3CMS  ‪main
TcaFlexPrepareTest.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 Psr\EventDispatcher\EventDispatcherInterface;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪TcaFlexPrepareTest extends UnitTestCase
30 {
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  // Suppress cache foo in xml helpers of GeneralUtility
35  $cacheManagerMock = $this->createMock(CacheManager::class);
36  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerMock);
37  $cacheFrontendMock = $this->createMock(FrontendInterface::class);
38  $cacheManagerMock->method('getCache')->with(self::anything())->willReturn($cacheFrontendMock);
39 
40  $eventDispatcher = new ‪MockEventDispatcher();
41  GeneralUtility::addInstance(EventDispatcherInterface::class, $eventDispatcher);
42  GeneralUtility::addInstance(FlexFormTools::class, new ‪FlexFormTools($eventDispatcher));
43  }
44 
45  protected function ‪tearDown(): void
46  {
47  GeneralUtility::purgeInstances();
48  parent::tearDown();
49  }
50 
54  public function ‪addDataKeepsExistingDataStructure(): void
55  {
56  $input = [
57  'systemLanguageRows' => [],
58  'tableName' => 'aTableName',
59  'databaseRow' => [
60  'aField' => [
61  'data' => [],
62  'meta' => [],
63  ],
64  ],
65  'processedTca' => [
66  'columns' => [
67  'aField' => [
68  'config' => [
69  'type' => 'flex',
70  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
71  'ds' => [
72  'sheets' => [
73  'sDEF' => [
74  'ROOT' => [
75  'type' => 'array',
76  'el' => [
77  'aFlexField' => [
78  'label' => 'aFlexFieldLabel',
79  'config' => [
80  'type' => 'input',
81  ],
82  ],
83  ],
84  ],
85  ],
86  ],
87  'meta' => [],
88  ],
89  ],
90  ],
91  ],
92  ],
93  ];
94  $expected = $input;
95  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
96  }
97 
102  {
103  $input = [
104  'systemLanguageRows' => [],
105  'tableName' => 'aTableName',
106  'databaseRow' => [
107  'aField' => [
108  'data' => [],
109  'meta' => [],
110  ],
111  ],
112  'processedTca' => [
113  'columns' => [
114  'aField' => [
115  'config' => [
116  'type' => 'flex',
117  'ds' => [
118  'default' => '
119  <T3DataStructure>
120  <ROOT>
121  <type>array</type>
122  <el>
123  <aFlexField>
124  <label>aFlexFieldLabel</label>
125  <config>
126  <type>input</type>
127  </config>
128  </aFlexField>
129  </el>
130  </ROOT>
131  </T3DataStructure>
132  ',
133  ],
134  ],
135  ],
136  ],
137  ],
138  ];
139 
140  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
141 
142  $expected = $input;
143  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
144  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
145  $expected['processedTca']['columns']['aField']['config']['ds'] = [
146  'sheets' => [
147  'sDEF' => [
148  'ROOT' => [
149  'type' => 'array',
150  'el' => [
151  'aFlexField' => [
152  'label' => 'aFlexFieldLabel',
153  'config' => [
154  'type' => 'input',
155  ],
156  ],
157  ],
158  ],
159  ],
160  ],
161  'meta' => [],
162  ];
163 
164  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
165  }
166 
171  {
172  $input = [
173  'systemLanguageRows' => [],
174  'tableName' => 'aTableName',
175  'databaseRow' => [
176  'aField' => [
177  'data' => [],
178  'meta' => [],
179  ],
180  ],
181  'processedTca' => [
182  'columns' => [
183  'aField' => [
184  'config' => [
185  'type' => 'flex',
186  'ds' => [
187  'default' => '
188  <T3DataStructure>
189  <sheets>
190  <sDEF>
191  <ROOT>
192  <sheetTitle>aTitle</sheetTitle>
193  <type>array</type>
194  <el>
195  <aFlexField>
196  <label>aFlexFieldLabel</label>
197  <config>
198  <type>input</type>
199  </config>
200  </aFlexField>
201  </el>
202  </ROOT>
203  </sDEF>
204  </sheets>
205  </T3DataStructure>
206  ',
207  ],
208  ],
209  ],
210  ],
211  ],
212  ];
213 
214  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
215 
216  $expected = $input;
217  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
218  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
219  $expected['processedTca']['columns']['aField']['config']['ds'] = [
220  'sheets' => [
221  'sDEF' => [
222  'ROOT' => [
223  'type' => 'array',
224  'el' => [
225  'aFlexField' => [
226  'label' => 'aFlexFieldLabel',
227  'config' => [
228  'type' => 'input',
229  ],
230  ],
231  ],
232  'sheetTitle' => 'aTitle',
233  ],
234  ],
235  ],
236  'meta' => [],
237  ];
238 
239  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
240  }
241 
246  {
247  $input = [
248  'databaseRow' => [],
249  'tableName' => 'aTableName',
250  'systemLanguageRows' => [],
251  'processedTca' => [
252  'columns' => [
253  'aField' => [
254  'config' => [
255  'type' => 'flex',
256  'ds' => [
257  'default' => '
258  <T3DataStructure>
259  <ROOT></ROOT>
260  </T3DataStructure>
261  ',
262  ],
263  ],
264  ],
265  ],
266  ],
267  ];
268 
269  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
270 
271  $expected = $input;
272  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
273  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
274  $expected['processedTca']['columns']['aField']['config']['ds'] = [
275  'ROOT' => '',
276  'meta' => [],
277  ];
278  $expected['databaseRow']['aField'] = [
279  'data' => [],
280  'meta' => [],
281  ];
282 
283  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
284  }
285 
290  {
291  $input = [
292  'systemLanguageRows' => [],
293  'tableName' => 'aTableName',
294  'databaseRow' => [
295  'aField' => [
296  'data' => [],
297  'meta' => [],
298  ],
299  ],
300  'processedTca' => [
301  'columns' => [
302  'aField' => [
303  'config' => [
304  'type' => 'flex',
305  'ds' => [
306  'default' => '
307  <T3DataStructure>
308  <sheets>
309  <sTree>
310  <ROOT>
311  <type>array</type>
312  <sheetTitle>selectTree</sheetTitle>
313  <el>
314  <select_tree_1>
315  <label>select_tree_1</label>
316  <description>select_tree_1 description</description>
317  <config>
318  <type>select</type>
319  <renderType>selectTree</renderType>
320  </config>
321  </select_tree_1>
322  </el>
323  </ROOT>
324  </sTree>
325  <sSection>
326  <ROOT>
327  <type>array</type>
328  <sheetTitle>section</sheetTitle>
329  <el>
330  <section_1>
331  <title>section_1</title>
332  <type>array</type>
333  <section>1</section>
334  <el>
335  <container_1>
336  <type>array</type>
337  <title>container_1</title>
338  <el>
339  <select_tree_2>
340  <label>select_tree_2</label>
341  <description>select_tree_2 description</description>
342  <config>
343  <type>select</type>
344  <renderType>selectTree</renderType>
345  </config>
346  </select_tree_2>
347  </el>
348  </container_1>
349  </el>
350  </section_1>
351  </el>
352  </ROOT>
353  </sSection>
354  </sheets>
355  </T3DataStructure>
356  ',
357  ],
358  ],
359  ],
360  ],
361  ],
362  ];
363 
364  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
365 
366  $expected = $input;
367  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
368  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
369 
370  $expected['processedTca']['columns']['aField']['config']['ds'] = [
371  'sheets' => [
372  'sSection' => [
373  'ROOT' => [
374  'type' => 'array',
375  'sheetTitle' => 'section',
376  'el' => [
377  'section_1' => [
378  'title' => 'section_1',
379  'type' => 'array',
380  'section' => '1',
381  'el' => [
382  'container_1' => [
383  'type' => 'array',
384  'title' => 'container_1',
385  'el' => [
386  'select_tree_2' => [
387  'label' => 'select_tree_2',
388  'description' => 'select_tree_2 description',
389  'config' => [
390  'type' => 'select',
391  'renderType' => 'selectTree',
392  ],
393  ],
394  ],
395  ],
396  ],
397  ],
398  ],
399  ],
400  ],
401  'sTree' => [
402  'ROOT' => [
403  'type' => 'array',
404  'sheetTitle' => 'selectTree',
405  'el' => [
406  'select_tree_1' => [
407  'label' => 'select_tree_1',
408  'description' => 'select_tree_1 description',
409  'config' => [
410  'type' => 'select',
411  'renderType' => 'selectTree',
412  ],
413  ],
414  ],
415  ],
416  ],
417  ],
418  'meta' => [],
419  ];
420 
421  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
422  }
423 
432  {
433  $columnConfig = [
434  'label' => 'select_section_1',
435  'description' => 'select_section_1 description',
436  'config' => [
437  'type' => 'select',
438  ],
439  ];
440 
441  $input = [
442  'systemLanguageRows' => [],
443  'tableName' => 'aTableName',
444  'databaseRow' => [
445  'aField' => [
446  'data' => [],
447  'meta' => [],
448  ],
449  ],
450  'processedTca' => [
451  'columns' => [
452  'aField' => [
453  'config' => [
454  'type' => 'flex',
455  'ds' => [
456  'sheets' => [
457  'sSection' => [
458  'ROOT' => [
459  'type' => 'array',
460  'el' => [
461  'section_1' => [
462  'section' => 1,
463  'type' => 'array',
464  'el' => [
465  'container_1' => [
466  'type' => 'array',
467  'el' => [
468  'select_section_1' => $columnConfig,
469  ],
470  ],
471  ],
472  ],
473  ],
474  ],
475  ],
476  ],
477  ],
478  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
479  ],
480  ],
481  ],
482  ],
483  ];
484 
485  $expected = $input;
486  $expected['processedTca']['columns']['aField']['config']['ds']['meta'] = [];
487  $expected['processedTca']['columns']['aField']['config']['ds']
488  ['sheets']['sSection']['ROOT']['el']
489  ['section_1']['el']
490  ['container_1']['el']
491  ['select_section_1'] = $columnConfig;
492 
493  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
494  }
495 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest
Definition: TcaFlexPrepareTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArray
‪addDataSetsParsedDataStructureArray()
Definition: TcaFlexPrepareTest.php:101
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\setUp
‪setUp()
Definition: TcaFlexPrepareTest.php:31
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:57
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataKeepsExistingDataStructure
‪addDataKeepsExistingDataStructure()
Definition: TcaFlexPrepareTest.php:54
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher
Definition: MockEventDispatcher.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\tearDown
‪tearDown()
Definition: TcaFlexPrepareTest.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataInitializesDatabaseRowValueIfNoDataStringIsGiven
‪addDataInitializesDatabaseRowValueIfNoDataStringIsGiven()
Definition: TcaFlexPrepareTest.php:245
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataMigratesResolvedFlexformTca
‪addDataMigratesResolvedFlexformTca()
Definition: TcaFlexPrepareTest.php:431
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayRecursive
‪addDataSetsParsedDataStructureArrayRecursive()
Definition: TcaFlexPrepareTest.php:289
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayWithSheets
‪addDataSetsParsedDataStructureArrayWithSheets()
Definition: TcaFlexPrepareTest.php:170