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