‪TYPO3CMS  9.5
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 
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪TcaFlexPrepareTest extends UnitTestCase
29 {
30  protected function ‪setUp()
31  {
32  // Suppress cache foo in xml helpers of GeneralUtility
34  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
35  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
36  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
37  $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
38  }
39 
40  protected function ‪tearDown()
41  {
42  GeneralUtility::purgeInstances();
43  parent::tearDown();
44  }
45 
50  {
51  $input = [
52  'systemLanguageRows' => [],
53  'tableName' => 'aTableName',
54  'databaseRow' => [
55  'aField' => [
56  'data' => [],
57  'meta' => [],
58  ],
59  ],
60  'processedTca' => [
61  'columns' => [
62  'aField' => [
63  'config' => [
64  'type' => 'flex',
65  'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}',
66  'ds' => [
67  'sheets' => [
68  'sDEF' => [
69  'ROOT' => [
70  'type' => 'array',
71  'el' => [
72  'aFlexField' => [
73  'label' => 'aFlexFieldLabel',
74  'config' => [
75  'type' => 'input',
76  ],
77  ],
78  ],
79  ],
80  ],
81  ],
82  'meta' => [],
83  ],
84  ],
85  ],
86  ],
87  ],
88  ];
89  $expected = $input;
90  $this->assertEquals($expected, (new ‪TcaFlexPrepare)->addData($input));
91  }
92 
97  {
98  $input = [
99  'systemLanguageRows' => [],
100  'tableName' => 'aTableName',
101  'databaseRow' => [
102  'aField' => [
103  'data' => [],
104  'meta' => [],
105  ],
106  ],
107  'processedTca' => [
108  'columns' => [
109  'aField' => [
110  'config' => [
111  'type' => 'flex',
112  'ds' => [
113  'default' => '
114  <T3DataStructure>
115  <ROOT>
116  <type>array</type>
117  <el>
118  <aFlexField>
119  <TCEforms>
120  <label>aFlexFieldLabel</label>
121  <config>
122  <type>input</type>
123  </config>
124  </TCEforms>
125  </aFlexField>
126  </el>
127  </ROOT>
128  </T3DataStructure>
129  ',
130  ],
131  ],
132  ],
133  ],
134  ],
135  ];
136 
137  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
138 
139  $expected = $input;
140  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
141  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
142  $expected['processedTca']['columns']['aField']['config']['ds'] = [
143  'sheets' => [
144  'sDEF' => [
145  'ROOT' => [
146  'type' => 'array',
147  'el' => [
148  'aFlexField' => [
149  'label' => 'aFlexFieldLabel',
150  'config' => [
151  'type' => 'input',
152  ],
153  ],
154  ],
155  ],
156  ],
157  ],
158  'meta' => [],
159  ];
160 
161  $this->assertEquals($expected, (new ‪TcaFlexPrepare)->addData($input));
162  }
163 
168  {
169  $input = [
170  'systemLanguageRows' => [],
171  'tableName' => 'aTableName',
172  'databaseRow' => [
173  'aField' => [
174  'data' => [],
175  'meta' => [],
176  ],
177  ],
178  'processedTca' => [
179  'columns' => [
180  'aField' => [
181  'config' => [
182  'type' => 'flex',
183  'ds' => [
184  'default' => '
185  <T3DataStructure>
186  <sheets>
187  <sDEF>
188  <ROOT>
189  <TCEforms>
190  <sheetTitle>aTitle</sheetTitle>
191  </TCEforms>
192  <type>array</type>
193  <el>
194  <aFlexField>
195  <TCEforms>
196  <label>aFlexFieldLabel</label>
197  <config>
198  <type>input</type>
199  </config>
200  </TCEforms>
201  </aFlexField>
202  </el>
203  </ROOT>
204  </sDEF>
205  </sheets>
206  </T3DataStructure>
207  ',
208  ],
209  ],
210  ],
211  ],
212  ],
213  ];
214 
215  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
216 
217  $expected = $input;
218  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
219  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
220  $expected['processedTca']['columns']['aField']['config']['ds'] = [
221  'sheets' => [
222  'sDEF' => [
223  'ROOT' => [
224  'type' => 'array',
225  'el' => [
226  'aFlexField' => [
227  'label' => 'aFlexFieldLabel',
228  'config' => [
229  'type' => 'input',
230  ],
231  ],
232  ],
233  'sheetTitle' => 'aTitle',
234  ],
235  ],
236  ],
237  'meta' => [],
238  ];
239 
240  $this->assertEquals($expected, (new ‪TcaFlexPrepare)->addData($input));
241  }
242 
247  {
248  $input = [
249  'databaseRow' => [],
250  'tableName' => 'aTableName',
251  'systemLanguageRows' => [],
252  'processedTca' => [
253  'columns' => [
254  'aField' => [
255  'config' => [
256  'type' => 'flex',
257  'ds' => [
258  'default' => '
259  <T3DataStructure>
260  <ROOT></ROOT>
261  </T3DataStructure>
262  ',
263  ],
264  ],
265  ],
266  ],
267  ],
268  ];
269 
270  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
271 
272  $expected = $input;
273  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
274  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
275  $expected['processedTca']['columns']['aField']['config']['ds'] = [
276  'ROOT' => '',
277  'meta' => [],
278  ];
279  $expected['databaseRow']['aField'] = [
280  'data' => [],
281  'meta' => []
282  ];
283 
284  $this->assertEquals($expected, (new ‪TcaFlexPrepare)->addData($input));
285  }
286 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest
Definition: TcaFlexPrepareTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArray
‪addDataSetsParsedDataStructureArray()
Definition: TcaFlexPrepareTest.php:96
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\setUp
‪setUp()
Definition: TcaFlexPrepareTest.php:30
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataKeepsExistingDataStructure
‪addDataKeepsExistingDataStructure()
Definition: TcaFlexPrepareTest.php:49
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪$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:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataInitializesDatabaseRowValueIfNoDataStringIsGiven
‪addDataInitializesDatabaseRowValueIfNoDataStringIsGiven()
Definition: TcaFlexPrepareTest.php:246
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:3
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaFlexPrepareTest\addDataSetsParsedDataStructureArrayWithSheets
‪addDataSetsParsedDataStructureArrayWithSheets()
Definition: TcaFlexPrepareTest.php:167