‪TYPO3CMS  11.5
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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪TcaFlexPrepareTest extends UnitTestCase
32 {
33  use ProphecyTrait;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  // Suppress cache foo in xml helpers of GeneralUtility
39  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
40  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
41  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
42  $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
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 
101  public function ‪addDataSetsParsedDataStructureArray(): void
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  <TCEforms>
125  <label>aFlexFieldLabel</label>
126  <config>
127  <type>input</type>
128  </config>
129  </TCEforms>
130  </aFlexField>
131  </el>
132  </ROOT>
133  </T3DataStructure>
134  ',
135  ],
136  ],
137  ],
138  ],
139  ],
140  ];
141 
142  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
143 
144  $expected = $input;
145  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
146  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
147  $expected['processedTca']['columns']['aField']['config']['ds'] = [
148  'sheets' => [
149  'sDEF' => [
150  'ROOT' => [
151  'type' => 'array',
152  'el' => [
153  'aFlexField' => [
154  'label' => 'aFlexFieldLabel',
155  'config' => [
156  'type' => 'input',
157  ],
158  ],
159  ],
160  ],
161  ],
162  ],
163  'meta' => [],
164  ];
165 
166  self::assertEquals($expected, (new TcaFlexPrepare())->addData($input));
167  }
168 
173  {
174  $input = [
175  'systemLanguageRows' => [],
176  'tableName' => 'aTableName',
177  'databaseRow' => [
178  'aField' => [
179  'data' => [],
180  'meta' => [],
181  ],
182  ],
183  'processedTca' => [
184  'columns' => [
185  'aField' => [
186  'config' => [
187  'type' => 'flex',
188  'ds' => [
189  'default' => '
190  <T3DataStructure>
191  <sheets>
192  <sDEF>
193  <ROOT>
194  <TCEforms>
195  <sheetTitle>aTitle</sheetTitle>
196  </TCEforms>
197  <type>array</type>
198  <el>
199  <aFlexField>
200  <TCEforms>
201  <label>aFlexFieldLabel</label>
202  <config>
203  <type>input</type>
204  </config>
205  </TCEforms>
206  </aFlexField>
207  </el>
208  </ROOT>
209  </sDEF>
210  </sheets>
211  </T3DataStructure>
212  ',
213  ],
214  ],
215  ],
216  ],
217  ],
218  ];
219 
220  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
221 
222  $expected = $input;
223  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
224  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
225  $expected['processedTca']['columns']['aField']['config']['ds'] = [
226  'sheets' => [
227  'sDEF' => [
228  'ROOT' => [
229  'type' => 'array',
230  'el' => [
231  'aFlexField' => [
232  'label' => 'aFlexFieldLabel',
233  'config' => [
234  'type' => 'input',
235  ],
236  ],
237  ],
238  'sheetTitle' => 'aTitle',
239  ],
240  ],
241  ],
242  'meta' => [],
243  ];
244 
245  self::assertEquals($expected, (new TcaFlexPrepare())->addData($input));
246  }
247 
252  {
253  $input = [
254  'databaseRow' => [],
255  'tableName' => 'aTableName',
256  'systemLanguageRows' => [],
257  'processedTca' => [
258  'columns' => [
259  'aField' => [
260  'config' => [
261  'type' => 'flex',
262  'ds' => [
263  'default' => '
264  <T3DataStructure>
265  <ROOT></ROOT>
266  </T3DataStructure>
267  ',
268  ],
269  ],
270  ],
271  ],
272  ],
273  ];
274 
275  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
276 
277  $expected = $input;
278  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
279  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
280  $expected['processedTca']['columns']['aField']['config']['ds'] = [
281  'ROOT' => '',
282  'meta' => [],
283  ];
284  $expected['databaseRow']['aField'] = [
285  'data' => [],
286  'meta' => [],
287  ];
288 
289  self::assertEquals($expected, (new TcaFlexPrepare())->addData($input));
290  }
291 
296  {
297  $input = [
298  'systemLanguageRows' => [],
299  'tableName' => 'aTableName',
300  'databaseRow' => [
301  'aField' => [
302  'data' => [],
303  'meta' => [],
304  ],
305  ],
306  'processedTca' => [
307  'columns' => [
308  'aField' => [
309  'config' => [
310  'type' => 'flex',
311  'ds' => [
312  'default' => '
313  <T3DataStructure>
314  <sheets>
315  <sTree>
316  <ROOT>
317  <type>array</type>
318  <TCEforms>
319  <sheetTitle>selectTree</sheetTitle>
320  </TCEforms>
321  <el>
322  <select_tree_1>
323  <TCEforms>
324  <label>select_tree_1</label>
325  <description>select_tree_1 description</description>
326  <config>
327  <type>select</type>
328  <renderType>selectTree</renderType>
329  </config>
330  </TCEforms>
331  </select_tree_1>
332  </el>
333  </ROOT>
334  </sTree>
335  <sSection>
336  <ROOT>
337  <type>array</type>
338  <TCEforms>
339  <sheetTitle>section</sheetTitle>
340  </TCEforms>
341  <el>
342  <section_1>
343  <title>section_1</title>
344  <type>array</type>
345  <section>1</section>
346  <el>
347  <container_1>
348  <type>array</type>
349  <title>container_1</title>
350  <el>
351  <select_tree_2>
352  <TCEforms>
353  <label>select_tree_2</label>
354  <description>select_tree_2 description</description>
355  <config>
356  <type>select</type>
357  <renderType>selectTree</renderType>
358  </config>
359  </TCEforms>
360  </select_tree_2>
361  </el>
362  </container_1>
363  </el>
364  </section_1>
365  </el>
366  </ROOT>
367  </sSection>
368  </sheets>
369  </T3DataStructure>
370  ',
371  ],
372  ],
373  ],
374  ],
375  ],
376  ];
377 
378  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
379 
380  $expected = $input;
381  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
382  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
383 
384  $expected['processedTca']['columns']['aField']['config']['ds'] = [
385  'sheets' => [
386  'sSection' => [
387  'ROOT' => [
388  'type' => 'array',
389  'sheetTitle' => 'section',
390  'el' => [
391  'section_1' => [
392  'title' => 'section_1',
393  'type' => 'array',
394  'section' => '1',
395  'el' => [
396  'container_1' => [
397  'type' => 'array',
398  'title' => 'container_1',
399  'el' => [
400  'select_tree_2' => [
401  'label' => 'select_tree_2',
402  'description' => 'select_tree_2 description',
403  'config' => [
404  'type' => 'select',
405  'renderType' => 'selectTree',
406  ],
407  ],
408  ],
409  ],
410  ],
411  ],
412  ],
413  ],
414  ],
415  'sTree' => [
416  'ROOT' => [
417  'type' => 'array',
418  'sheetTitle' => 'selectTree',
419  'el' => [
420  'select_tree_1' => [
421  'label' => 'select_tree_1',
422  'description' => 'select_tree_1 description',
423  'config' => [
424  'type' => 'select',
425  'renderType' => 'selectTree',
426  ],
427  ],
428  ],
429  ],
430  ],
431  ],
432  'meta' => [],
433  ];
434 
435  self::assertEquals($expected, (new TcaFlexPrepare())->addData($input));
436  }
437 
445  public function ‪addDataMigratesResolvedFlexformTca(): void
446  {
447  $columnConfig = [
448  'label' => 'select_section_1',
449  'description' => 'select_section_1 description',
450  'config' => [
451  'type' => 'select',
452  ],
453  ];
454 
455  $input = [
456  'systemLanguageRows' => [],
457  'tableName' => 'aTableName',
458  'databaseRow' => [
459  'aField' => [
460  'data' => [],
461  'meta' => [],
462  ],
463  ],
464  'processedTca' => [
465  'columns' => [
466  'aField' => [
467  'config' => [
468  'type' => 'flex',
469  'ds' => [
470  'sheets' => [
471  'sSection' => [
472  'ROOT' => [
473  'type' => 'array',
474  'el' => [
475  'section_1' => [
476  'section' => 1,
477  'type' => 'array',
478  'el' => [
479  'container_1' => [
480  'type' => 'array',
481  'el' => [
482  'select_section_1' => [
483  'TCEforms' => $columnConfig,
484  ],
485  ],
486  ],
487  ],
488  ],
489  ],
490  ],
491  ],
492  ],
493  ],
494  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
495  ],
496  ],
497  ],
498  ],
499  ];
500 
501  $expected = $input;
502  $expected['processedTca']['columns']['aField']['config']['ds']['meta'] = [];
503  $expected['processedTca']['columns']['aField']['config']['ds']
504  ['sheets']['sSection']['ROOT']['el']
505  ['section_1']['el']
506  ['container_1']['el']
507  ['select_section_1'] = $columnConfig;
508 
509  self::assertEquals($expected, (new TcaFlexPrepare())->addData($input));
510  }
511 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest
Definition: TcaFlexPrepareTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArray
‪addDataSetsParsedDataStructureArray()
Definition: TcaFlexPrepareTest.php:100
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\setUp
‪setUp()
Definition: TcaFlexPrepareTest.php:34
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataKeepsExistingDataStructure
‪addDataKeepsExistingDataStructure()
Definition: TcaFlexPrepareTest.php:53
‪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\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\tearDown
‪tearDown()
Definition: TcaFlexPrepareTest.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataInitializesDatabaseRowValueIfNoDataStringIsGiven
‪addDataInitializesDatabaseRowValueIfNoDataStringIsGiven()
Definition: TcaFlexPrepareTest.php:250
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataMigratesResolvedFlexformTca
‪addDataMigratesResolvedFlexformTca()
Definition: TcaFlexPrepareTest.php:444
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayRecursive
‪addDataSetsParsedDataStructureArrayRecursive()
Definition: TcaFlexPrepareTest.php:294
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayWithSheets
‪addDataSetsParsedDataStructureArrayWithSheets()
Definition: TcaFlexPrepareTest.php:171