[TASK] Make sysext/backend/Tests/Unit/ notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / UnitDeprecated / Form / FormDataProvider / TcaFlexPrepareTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider;
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
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
20 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare;
21 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
22 use TYPO3\CMS\Core\Cache\CacheManager;
23 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Test case for TcaFlexPrepare to render the functionality when a TCA migration happened
28 */
29 class TcaFlexPrepareTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
31 /**
32 * @var TcaFlexPrepare
33 */
34 protected $subject;
35
36 /**
37 * @var BackendUserAuthentication|ObjectProphecy
38 */
39 protected $backendUserProphecy;
40
41 /**
42 * @var array A backup of registered singleton instances
43 */
44 protected $singletonInstances = [];
45
46 protected function setUp()
47 {
48 $this->singletonInstances = GeneralUtility::getSingletonInstances();
49
50 // Suppress cache foo in xml helpers of GeneralUtility
51 /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */
52 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
53 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
54 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
55 $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
56
57 $this->subject = new TcaFlexPrepare();
58 }
59
60 protected function tearDown()
61 {
62 GeneralUtility::purgeInstances();
63 GeneralUtility::resetSingletonInstances($this->singletonInstances);
64 parent::tearDown();
65 }
66
67 /**
68 * @test
69 */
70 public function addDataMigratesFlexformTca()
71 {
72 $input = [
73 'systemLanguageRows' => [],
74 'tableName' => 'aTableName',
75 'databaseRow' => [
76 'aField' => [
77 'data' => [],
78 'meta' => [],
79 ],
80 ],
81 'processedTca' => [
82 'columns' => [
83 'aField' => [
84 'config' => [
85 'type' => 'flex',
86 'ds' => [
87 'default' => '
88 <T3DataStructure>
89 <sheets>
90 <sDEF>
91 <ROOT>
92 <type>array</type>
93 <el>
94 <aFlexField>
95 <TCEforms>
96 <label>aFlexFieldLabel</label>
97 <config>
98 <type>text</type>
99 <default>defaultValue</default>
100 <wizards>
101 <t3editor>
102 <type>userFunc</type>
103 <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
104 <title>t3editor</title>
105 <icon>content-table</icon>
106 <module>
107 <name>wizard_table</name>
108 </module>
109 <params>
110 <format>html</format>
111 </params>
112 </t3editor>
113 </wizards>
114 </config>
115 </TCEforms>
116 </aFlexField>
117 </el>
118 </ROOT>
119 </sDEF>
120 </sheets>
121 </T3DataStructure>
122 ',
123 ],
124 ],
125 ],
126 ],
127 ],
128 ];
129
130 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
131
132 $expected = $input;
133 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
134 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
135 $expected['processedTca']['columns']['aField']['config']['ds'] = [
136 'sheets' => [
137 'sDEF' => [
138 'ROOT' => [
139 'type' => 'array',
140 'el' => [
141 'aFlexField' => [
142 'label' => 'aFlexFieldLabel',
143 'config' => [
144 'type' => 'text',
145 'default' => 'defaultValue',
146 'renderType' => 't3editor',
147 'format' => 'html',
148 ],
149 ],
150 ],
151 ],
152 ],
153 ],
154 'meta' => [],
155 ];
156
157 $this->assertEquals($expected, $this->subject->addData($input));
158 }
159
160 /**
161 * @test
162 */
163 public function addDataMigratesFlexformTcaInContainer()
164 {
165 $input = [
166 'systemLanguageRows' => [],
167 'tableName' => 'aTableName',
168 'databaseRow' => [
169 'aField' => [
170 'data' => [],
171 'meta' => [],
172 ],
173 ],
174 'processedTca' => [
175 'columns' => [
176 'aField' => [
177 'config' => [
178 'type' => 'flex',
179 'ds' => [
180 'default' => '
181 <T3DataStructure>
182 <sheets>
183 <sDEF>
184 <ROOT>
185 <type>array</type>
186 <el>
187 <section_1>
188 <title>section_1</title>
189 <type>array</type>
190 <section>1</section>
191 <el>
192 <aFlexContainer>
193 <type>array</type>
194 <title>aFlexContainerLabel</title>
195 <el>
196 <aFlexField>
197 <TCEforms>
198 <label>aFlexFieldLabel</label>
199 <config>
200 <type>text</type>
201 <default>defaultValue</default>
202 <wizards>
203 <t3editor>
204 <type>userFunc</type>
205 <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
206 <title>t3editor</title>
207 <icon>content-table</icon>
208 <module>
209 <name>wizard_table</name>
210 </module>
211 <params>
212 <format>html</format>
213 </params>
214 </t3editor>
215 </wizards>
216 </config>
217 </TCEforms>
218 </aFlexField>
219 </el>
220 </aFlexContainer>
221 </el>
222 </section_1>
223 </el>
224 </ROOT>
225 </sDEF>
226 </sheets>
227 </T3DataStructure>
228 ',
229 ],
230 ],
231 ],
232 ],
233 ],
234 ];
235
236 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
237
238 $expected = $input;
239 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
240 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
241 $expected['processedTca']['columns']['aField']['config']['ds'] = [
242 'sheets' => [
243 'sDEF' => [
244 'ROOT' => [
245 'type' => 'array',
246 'el' => [
247 'section_1' => [
248 'title' => 'section_1',
249 'type' => 'array',
250 'section' => '1',
251 'el' => [
252 'aFlexContainer' => [
253 'type' => 'array',
254 'title' => 'aFlexContainerLabel',
255 'el' => [
256 'aFlexField' => [
257 'label' => 'aFlexFieldLabel',
258 'config' => [
259 'type' => 'text',
260 'default' => 'defaultValue',
261 'renderType' => 't3editor',
262 'format' => 'html',
263 ],
264 ],
265 ],
266 ],
267 ],
268 ],
269 ],
270 ],
271 ],
272 ],
273 'meta' => [],
274 ];
275
276 $this->assertEquals($expected, $this->subject->addData($input));
277 }
278 }