‪TYPO3CMS  10.4
TcaFlexPrepareTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪TcaFlexPrepareTest extends UnitTestCase
30 {
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  // Suppress cache foo in xml helpers of GeneralUtility
36  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
37  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
38  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
39  $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
40  }
41 
42  protected function ‪tearDown(): void
43  {
44  GeneralUtility::purgeInstances();
45  parent::tearDown();
46  }
47 
52  {
53  $input = [
54  'systemLanguageRows' => [],
55  'tableName' => 'aTableName',
56  'databaseRow' => [
57  'aField' => [
58  'data' => [],
59  'meta' => [],
60  ],
61  ],
62  'processedTca' => [
63  'columns' => [
64  'aField' => [
65  'config' => [
66  'type' => 'flex',
67  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
68  'ds' => [
69  'sheets' => [
70  'sDEF' => [
71  'ROOT' => [
72  'type' => 'array',
73  'el' => [
74  'aFlexField' => [
75  'label' => 'aFlexFieldLabel',
76  'config' => [
77  'type' => 'input',
78  ],
79  ],
80  ],
81  ],
82  ],
83  ],
84  'meta' => [],
85  ],
86  ],
87  ],
88  ],
89  ],
90  ];
91  $expected = $input;
92  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
93  }
94 
99  {
100  $input = [
101  'systemLanguageRows' => [],
102  'tableName' => 'aTableName',
103  'databaseRow' => [
104  'aField' => [
105  'data' => [],
106  'meta' => [],
107  ],
108  ],
109  'processedTca' => [
110  'columns' => [
111  'aField' => [
112  'config' => [
113  'type' => 'flex',
114  'ds' => [
115  'default' => '
116  <T3DataStructure>
117  <ROOT>
118  <type>array</type>
119  <el>
120  <aFlexField>
121  <TCEforms>
122  <label>aFlexFieldLabel</label>
123  <config>
124  <type>input</type>
125  </config>
126  </TCEforms>
127  </aFlexField>
128  </el>
129  </ROOT>
130  </T3DataStructure>
131  ',
132  ],
133  ],
134  ],
135  ],
136  ],
137  ];
138 
139  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
140 
141  $expected = $input;
142  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
143  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
144  $expected['processedTca']['columns']['aField']['config']['ds'] = [
145  'sheets' => [
146  'sDEF' => [
147  'ROOT' => [
148  'type' => 'array',
149  'el' => [
150  'aFlexField' => [
151  'label' => 'aFlexFieldLabel',
152  'config' => [
153  'type' => 'input',
154  ],
155  ],
156  ],
157  ],
158  ],
159  ],
160  'meta' => [],
161  ];
162 
163  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
164  }
165 
170  {
171  $input = [
172  'systemLanguageRows' => [],
173  'tableName' => 'aTableName',
174  'databaseRow' => [
175  'aField' => [
176  'data' => [],
177  'meta' => [],
178  ],
179  ],
180  'processedTca' => [
181  'columns' => [
182  'aField' => [
183  'config' => [
184  'type' => 'flex',
185  'ds' => [
186  'default' => '
187  <T3DataStructure>
188  <sheets>
189  <sDEF>
190  <ROOT>
191  <TCEforms>
192  <sheetTitle>aTitle</sheetTitle>
193  </TCEforms>
194  <type>array</type>
195  <el>
196  <aFlexField>
197  <TCEforms>
198  <label>aFlexFieldLabel</label>
199  <config>
200  <type>input</type>
201  </config>
202  </TCEforms>
203  </aFlexField>
204  </el>
205  </ROOT>
206  </sDEF>
207  </sheets>
208  </T3DataStructure>
209  ',
210  ],
211  ],
212  ],
213  ],
214  ],
215  ];
216 
217  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
218 
219  $expected = $input;
220  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
221  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
222  $expected['processedTca']['columns']['aField']['config']['ds'] = [
223  'sheets' => [
224  'sDEF' => [
225  'ROOT' => [
226  'type' => 'array',
227  'el' => [
228  'aFlexField' => [
229  'label' => 'aFlexFieldLabel',
230  'config' => [
231  'type' => 'input',
232  ],
233  ],
234  ],
235  'sheetTitle' => 'aTitle',
236  ],
237  ],
238  ],
239  'meta' => [],
240  ];
241 
242  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
243  }
244 
249  {
250  $input = [
251  'databaseRow' => [],
252  'tableName' => 'aTableName',
253  'systemLanguageRows' => [],
254  'processedTca' => [
255  'columns' => [
256  'aField' => [
257  'config' => [
258  'type' => 'flex',
259  'ds' => [
260  'default' => '
261  <T3DataStructure>
262  <ROOT></ROOT>
263  </T3DataStructure>
264  ',
265  ],
266  ],
267  ],
268  ],
269  ],
270  ];
271 
272  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
273 
274  $expected = $input;
275  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
276  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
277  $expected['processedTca']['columns']['aField']['config']['ds'] = [
278  'ROOT' => '',
279  'meta' => [],
280  ];
281  $expected['databaseRow']['aField'] = [
282  'data' => [],
283  'meta' => []
284  ];
285 
286  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
287  }
288 
293  {
294  $input = [
295  'systemLanguageRows' => [],
296  'tableName' => 'aTableName',
297  'databaseRow' => [
298  'aField' => [
299  'data' => [],
300  'meta' => [],
301  ],
302  ],
303  'processedTca' => [
304  'columns' => [
305  'aField' => [
306  'config' => [
307  'type' => 'flex',
308  'ds' => [
309  'default' => '
310  <T3DataStructure>
311  <sheets>
312  <sTree>
313  <ROOT>
314  <type>array</type>
315  <TCEforms>
316  <sheetTitle>selectTree</sheetTitle>
317  </TCEforms>
318  <el>
319  <select_tree_1>
320  <TCEforms>
321  <label>select_tree_1</label>
322  <description>select_tree_1 description</description>
323  <config>
324  <type>select</type>
325  <renderType>selectTree</renderType>
326  </config>
327  </TCEforms>
328  </select_tree_1>
329  </el>
330  </ROOT>
331  </sTree>
332  <sSection>
333  <ROOT>
334  <type>array</type>
335  <TCEforms>
336  <sheetTitle>section</sheetTitle>
337  </TCEforms>
338  <el>
339  <section_1>
340  <title>section_1</title>
341  <type>array</type>
342  <section>1</section>
343  <el>
344  <container_1>
345  <type>array</type>
346  <title>container_1</title>
347  <el>
348  <select_tree_2>
349  <TCEforms>
350  <label>select_tree_2</label>
351  <description>select_tree_2 description</description>
352  <config>
353  <type>select</type>
354  <renderType>selectTree</renderType>
355  </config>
356  </TCEforms>
357  </select_tree_2>
358  </el>
359  </container_1>
360  </el>
361  </section_1>
362  </el>
363  </ROOT>
364  </sSection>
365  </sheets>
366  </T3DataStructure>
367  ',
368  ],
369  ],
370  ],
371  ],
372  ],
373  ];
374 
375  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
376 
377  $expected = $input;
378  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
379  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
380 
381  $expected['processedTca']['columns']['aField']['config']['ds'] = [
382  'sheets' => [
383  'sSection' => [
384  'ROOT' => [
385  'type' => 'array',
386  'sheetTitle' => 'section',
387  'el' => [
388  'section_1' => [
389  'title' => 'section_1',
390  'type' => 'array',
391  'section' => '1',
392  'el' => [
393  'container_1' => [
394  'type' => 'array',
395  'title' => 'container_1',
396  'el' => [
397  'select_tree_2' => [
398  'label' => 'select_tree_2',
399  'description' => 'select_tree_2 description',
400  'config' => [
401  'type' => 'select',
402  'renderType' => 'selectTree'
403  ]
404  ]
405  ]
406  ]
407  ]
408  ]
409  ],
410  ],
411  ],
412  'sTree' => [
413  'ROOT' => [
414  'type' => 'array',
415  'sheetTitle' => 'selectTree',
416  'el' => [
417  'select_tree_1' => [
418  'label' => 'select_tree_1',
419  'description' => 'select_tree_1 description',
420  'config' => [
421  'type' => 'select',
422  'renderType' => 'selectTree'
423  ]
424  ]
425  ]
426  ]
427  ],
428  ],
429  'meta' => [],
430  ];
431 
432  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
433  }
434 
443  {
444  $columnConfig = [
445  'label' => 'select_section_1',
446  'description' => 'select_section_1 description',
447  'config' => [
448  'type' => 'select'
449  ]
450  ];
451 
452  $input = [
453  'systemLanguageRows' => [],
454  'tableName' => 'aTableName',
455  'databaseRow' => [
456  'aField' => [
457  'data' => [],
458  'meta' => [],
459  ],
460  ],
461  'processedTca' => [
462  'columns' => [
463  'aField' => [
464  'config' => [
465  'type' => 'flex',
466  'ds' => [
467  'sheets' => [
468  'sSection' => [
469  'ROOT' => [
470  'type' => 'array',
471  'el' => [
472  'section_1' => [
473  'section' => 1,
474  'type' => 'array',
475  'el' => [
476  'container_1' => [
477  'type' => 'array',
478  'el' => [
479  'select_section_1' => [
480  'TCEforms' => $columnConfig
481  ]
482  ]
483  ]
484  ]
485  ]
486  ]
487  ]
488  ]
489  ]
490  ],
491  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}'
492  ],
493  ],
494  ],
495  ],
496  ];
497 
498  $expected = $input;
499  $expected['processedTca']['columns']['aField']['config']['ds']['meta'] = [];
500  $expected['processedTca']['columns']['aField']['config']['ds']
501  ['sheets']['sSection']['ROOT']['el']
502  ['section_1']['el']
503  ['container_1']['el']
504  ['select_section_1'] = $columnConfig;
505 
506  self::assertEquals($expected, (new ‪TcaFlexPrepare())->addData($input));
507  }
508 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:35
‪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:98
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\setUp
‪setUp()
Definition: TcaFlexPrepareTest.php:31
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataKeepsExistingDataStructure
‪addDataKeepsExistingDataStructure()
Definition: TcaFlexPrepareTest.php:51
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\tearDown
‪tearDown()
Definition: TcaFlexPrepareTest.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataInitializesDatabaseRowValueIfNoDataStringIsGiven
‪addDataInitializesDatabaseRowValueIfNoDataStringIsGiven()
Definition: TcaFlexPrepareTest.php:248
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataMigratesResolvedFlexformTca
‪addDataMigratesResolvedFlexformTca()
Definition: TcaFlexPrepareTest.php:442
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayRecursive
‪addDataSetsParsedDataStructureArrayRecursive()
Definition: TcaFlexPrepareTest.php:292
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayWithSheets
‪addDataSetsParsedDataStructureArrayWithSheets()
Definition: TcaFlexPrepareTest.php:169