TYPO3 CMS  TYPO3_8-7
TcaFlexPrepareTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
28 class TcaFlexPrepareTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
33  protected $subject;
34 
39 
43  protected $singletonInstances = [];
44 
45  protected function setUp()
46  {
47  $this->singletonInstances = GeneralUtility::getSingletonInstances();
48 
49  // Suppress cache foo in xml helpers of GeneralUtility
51  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
52  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
53  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
54  $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
55 
56  $this->subject = new TcaFlexPrepare();
57  }
58 
59  protected function tearDown()
60  {
62  GeneralUtility::resetSingletonInstances($this->singletonInstances);
63  parent::tearDown();
64  }
65 
70  {
71  $input = [
72  'systemLanguageRows' => [],
73  'tableName' => 'aTableName',
74  'databaseRow' => [
75  'aField' => [
76  'data' => [],
77  'meta' => [],
78  ],
79  ],
80  'processedTca' => [
81  'columns' => [
82  'aField' => [
83  'config' => [
84  'type' => 'flex',
85  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
86  'ds' => [
87  'sheets' => [
88  'sDEF' => [
89  'ROOT' => [
90  'type' => 'array',
91  'el' => [
92  'aFlexField' => [
93  'label' => 'aFlexFieldLabel',
94  'config' => [
95  'type' => 'input',
96  ],
97  ],
98  ],
99  ],
100  ],
101  ],
102  'meta' => [],
103  ],
104  ],
105  ],
106  ],
107  ],
108  ];
109  $expected = $input;
110  $this->assertEquals($expected, $this->subject->addData($input));
111  }
112 
117  {
118  $input = [
119  'systemLanguageRows' => [],
120  'tableName' => 'aTableName',
121  'databaseRow' => [
122  'aField' => [
123  'data' => [],
124  'meta' => [],
125  ],
126  ],
127  'processedTca' => [
128  'columns' => [
129  'aField' => [
130  'config' => [
131  'type' => 'flex',
132  'ds' => [
133  'default' => '
134  <T3DataStructure>
135  <ROOT>
136  <type>array</type>
137  <el>
138  <aFlexField>
139  <TCEforms>
140  <label>aFlexFieldLabel</label>
141  <config>
142  <type>input</type>
143  </config>
144  </TCEforms>
145  </aFlexField>
146  </el>
147  </ROOT>
148  </T3DataStructure>
149  ',
150  ],
151  ],
152  ],
153  ],
154  ],
155  ];
156 
157  $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
158 
159  $expected = $input;
160  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
161  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
162  $expected['processedTca']['columns']['aField']['config']['ds'] = [
163  'sheets' => [
164  'sDEF' => [
165  'ROOT' => [
166  'type' => 'array',
167  'el' => [
168  'aFlexField' => [
169  'label' => 'aFlexFieldLabel',
170  'config' => [
171  'type' => 'input',
172  ],
173  ],
174  ],
175  ],
176  ],
177  ],
178  'meta' => [],
179  ];
180 
181  $this->assertEquals($expected, $this->subject->addData($input));
182  }
183 
188  {
189  $input = [
190  'systemLanguageRows' => [],
191  'tableName' => 'aTableName',
192  'databaseRow' => [
193  'aField' => [
194  'data' => [],
195  'meta' => [],
196  ],
197  ],
198  'processedTca' => [
199  'columns' => [
200  'aField' => [
201  'config' => [
202  'type' => 'flex',
203  'ds' => [
204  'default' => '
205  <T3DataStructure>
206  <sheets>
207  <sDEF>
208  <ROOT>
209  <TCEforms>
210  <sheetTitle>aTitle</sheetTitle>
211  </TCEforms>
212  <type>array</type>
213  <el>
214  <aFlexField>
215  <TCEforms>
216  <label>aFlexFieldLabel</label>
217  <config>
218  <type>input</type>
219  </config>
220  </TCEforms>
221  </aFlexField>
222  </el>
223  </ROOT>
224  </sDEF>
225  </sheets>
226  </T3DataStructure>
227  ',
228  ],
229  ],
230  ],
231  ],
232  ],
233  ];
234 
235  $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
236 
237  $expected = $input;
238  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
239  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
240  $expected['processedTca']['columns']['aField']['config']['ds'] = [
241  'sheets' => [
242  'sDEF' => [
243  'ROOT' => [
244  'type' => 'array',
245  'el' => [
246  'aFlexField' => [
247  'label' => 'aFlexFieldLabel',
248  'config' => [
249  'type' => 'input',
250  ],
251  ],
252  ],
253  'sheetTitle' => 'aTitle',
254  ],
255  ],
256  ],
257  'meta' => [],
258  ];
259 
260  $this->assertEquals($expected, $this->subject->addData($input));
261  }
262 
267  {
268  $input = [
269  'databaseRow' => [],
270  'tableName' => 'aTableName',
271  'systemLanguageRows' => [],
272  'processedTca' => [
273  'columns' => [
274  'aField' => [
275  'config' => [
276  'type' => 'flex',
277  'ds' => [
278  'default' => '
279  <T3DataStructure>
280  <ROOT></ROOT>
281  </T3DataStructure>
282  ',
283  ],
284  ],
285  ],
286  ],
287  ],
288  ];
289 
290  $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
291 
292  $expected = $input;
293  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
294  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
295  $expected['processedTca']['columns']['aField']['config']['ds'] = [
296  'ROOT' => '',
297  'meta' => [],
298  ];
299  $expected['databaseRow']['aField'] = [
300  'data' => [],
301  'meta' => []
302  ];
303 
304  $this->assertEquals($expected, $this->subject->addData($input));
305  }
306 
310  public function addDataMigratesFlexformTca()
311  {
312  $input = [
313  'systemLanguageRows' => [],
314  'tableName' => 'aTableName',
315  'databaseRow' => [
316  'aField' => [
317  'data' => [],
318  'meta' => [],
319  ],
320  ],
321  'processedTca' => [
322  'columns' => [
323  'aField' => [
324  'config' => [
325  'type' => 'flex',
326  'ds' => [
327  'default' => '
328  <T3DataStructure>
329  <sheets>
330  <sDEF>
331  <ROOT>
332  <type>array</type>
333  <el>
334  <aFlexField>
335  <TCEforms>
336  <label>aFlexFieldLabel</label>
337  <config>
338  <type>text</type>
339  <default>defaultValue</default>
340  <wizards>
341  <t3editor>
342  <type>userFunc</type>
343  <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
344  <title>t3editor</title>
345  <icon>content-table</icon>
346  <module>
347  <name>wizard_table</name>
348  </module>
349  <params>
350  <format>html</format>
351  </params>
352  </t3editor>
353  </wizards>
354  </config>
355  </TCEforms>
356  </aFlexField>
357  </el>
358  </ROOT>
359  </sDEF>
360  </sheets>
361  </T3DataStructure>
362  ',
363  ],
364  ],
365  ],
366  ],
367  ],
368  ];
369 
370  $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
371 
372  $expected = $input;
373  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
374  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
375  $expected['processedTca']['columns']['aField']['config']['ds'] = [
376  'sheets' => [
377  'sDEF' => [
378  'ROOT' => [
379  'type' => 'array',
380  'el' => [
381  'aFlexField' => [
382  'label' => 'aFlexFieldLabel',
383  'config' => [
384  'type' => 'text',
385  'default' => 'defaultValue',
386  'renderType' => 't3editor',
387  'format' => 'html',
388  ],
389  ],
390  ],
391  ],
392  ],
393  ],
394  'meta' => [],
395  ];
396 
397  $this->assertEquals($expected, $this->subject->addData($input));
398  }
399 
404  {
405  $input = [
406  'systemLanguageRows' => [],
407  'tableName' => 'aTableName',
408  'databaseRow' => [
409  'aField' => [
410  'data' => [],
411  'meta' => [],
412  ],
413  ],
414  'processedTca' => [
415  'columns' => [
416  'aField' => [
417  'config' => [
418  'type' => 'flex',
419  'ds' => [
420  'default' => '
421  <T3DataStructure>
422  <sheets>
423  <sDEF>
424  <ROOT>
425  <type>array</type>
426  <el>
427  <section_1>
428  <title>section_1</title>
429  <type>array</type>
430  <section>1</section>
431  <el>
432  <aFlexContainer>
433  <type>array</type>
434  <title>aFlexContainerLabel</title>
435  <el>
436  <aFlexField>
437  <TCEforms>
438  <label>aFlexFieldLabel</label>
439  <config>
440  <type>text</type>
441  <default>defaultValue</default>
442  <wizards>
443  <t3editor>
444  <type>userFunc</type>
445  <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
446  <title>t3editor</title>
447  <icon>content-table</icon>
448  <module>
449  <name>wizard_table</name>
450  </module>
451  <params>
452  <format>html</format>
453  </params>
454  </t3editor>
455  </wizards>
456  </config>
457  </TCEforms>
458  </aFlexField>
459  </el>
460  </aFlexContainer>
461  </el>
462  </section_1>
463  </el>
464  </ROOT>
465  </sDEF>
466  </sheets>
467  </T3DataStructure>
468  ',
469  ],
470  ],
471  ],
472  ],
473  ],
474  ];
475 
476  $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
477 
478  $expected = $input;
479  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
480  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
481  $expected['processedTca']['columns']['aField']['config']['ds'] = [
482  'sheets' => [
483  'sDEF' => [
484  'ROOT' => [
485  'type' => 'array',
486  'el' => [
487  'section_1' => [
488  'title' => 'section_1',
489  'type' => 'array',
490  'section' => '1',
491  'el' => [
492  'aFlexContainer' => [
493  'type' => 'array',
494  'title' => 'aFlexContainerLabel',
495  'el' => [
496  'aFlexField' => [
497  'label' => 'aFlexFieldLabel',
498  'config' => [
499  'type' => 'text',
500  'default' => 'defaultValue',
501  'renderType' => 't3editor',
502  'format' => 'html',
503  ],
504  ],
505  ],
506  ],
507  ],
508  ],
509  ],
510  ],
511  ],
512  ],
513  'meta' => [],
514  ];
515 
516  $this->assertEquals($expected, $this->subject->addData($input));
517  }
518 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']