[!!!][TASK] Handle E_NOTICE free unit tests
[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 * Subject is not notice free, disable E_NOTICES
32 */
33 protected static $suppressNotices = true;
34
35 /**
36 * @var TcaFlexPrepare
37 */
38 protected $subject;
39
40 /**
41 * @var BackendUserAuthentication|ObjectProphecy
42 */
43 protected $backendUserProphecy;
44
45 /**
46 * @var array A backup of registered singleton instances
47 */
48 protected $singletonInstances = [];
49
50 protected function setUp()
51 {
52 $this->singletonInstances = GeneralUtility::getSingletonInstances();
53
54 // Suppress cache foo in xml helpers of GeneralUtility
55 /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */
56 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
57 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
58 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
59 $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
60
61 $this->subject = new TcaFlexPrepare();
62 }
63
64 protected function tearDown()
65 {
66 GeneralUtility::purgeInstances();
67 GeneralUtility::resetSingletonInstances($this->singletonInstances);
68 parent::tearDown();
69 }
70
71 /**
72 * @test
73 */
74 public function addDataMigratesFlexformTca()
75 {
76 $input = [
77 'systemLanguageRows' => [],
78 'tableName' => 'aTableName',
79 'databaseRow' => [
80 'aField' => [
81 'data' => [],
82 'meta' => [],
83 ],
84 ],
85 'processedTca' => [
86 'columns' => [
87 'aField' => [
88 'config' => [
89 'type' => 'flex',
90 'ds' => [
91 'default' => '
92 <T3DataStructure>
93 <sheets>
94 <sDEF>
95 <ROOT>
96 <type>array</type>
97 <el>
98 <aFlexField>
99 <TCEforms>
100 <label>aFlexFieldLabel</label>
101 <config>
102 <type>text</type>
103 <default>defaultValue</default>
104 <wizards>
105 <t3editor>
106 <type>userFunc</type>
107 <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
108 <title>t3editor</title>
109 <icon>content-table</icon>
110 <module>
111 <name>wizard_table</name>
112 </module>
113 <params>
114 <format>html</format>
115 </params>
116 </t3editor>
117 </wizards>
118 </config>
119 </TCEforms>
120 </aFlexField>
121 </el>
122 </ROOT>
123 </sDEF>
124 </sheets>
125 </T3DataStructure>
126 ',
127 ],
128 ],
129 ],
130 ],
131 ],
132 ];
133
134 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
135
136 $expected = $input;
137 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
138 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
139 $expected['processedTca']['columns']['aField']['config']['ds'] = [
140 'sheets' => [
141 'sDEF' => [
142 'ROOT' => [
143 'type' => 'array',
144 'el' => [
145 'aFlexField' => [
146 'label' => 'aFlexFieldLabel',
147 'config' => [
148 'type' => 'text',
149 'default' => 'defaultValue',
150 'renderType' => 't3editor',
151 'format' => 'html',
152 ],
153 ],
154 ],
155 ],
156 ],
157 ],
158 'meta' => [],
159 ];
160
161 $this->assertEquals($expected, $this->subject->addData($input));
162 }
163
164 /**
165 * @test
166 */
167 public function addDataMigratesFlexformTcaInContainer()
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 <type>array</type>
190 <el>
191 <section_1>
192 <title>section_1</title>
193 <type>array</type>
194 <section>1</section>
195 <el>
196 <aFlexContainer>
197 <type>array</type>
198 <title>aFlexContainerLabel</title>
199 <el>
200 <aFlexField>
201 <TCEforms>
202 <label>aFlexFieldLabel</label>
203 <config>
204 <type>text</type>
205 <default>defaultValue</default>
206 <wizards>
207 <t3editor>
208 <type>userFunc</type>
209 <userFunc>TYPO3\\CMS\\T3editor\\FormWizard->main</userFunc>
210 <title>t3editor</title>
211 <icon>content-table</icon>
212 <module>
213 <name>wizard_table</name>
214 </module>
215 <params>
216 <format>html</format>
217 </params>
218 </t3editor>
219 </wizards>
220 </config>
221 </TCEforms>
222 </aFlexField>
223 </el>
224 </aFlexContainer>
225 </el>
226 </section_1>
227 </el>
228 </ROOT>
229 </sDEF>
230 </sheets>
231 </T3DataStructure>
232 ',
233 ],
234 ],
235 ],
236 ],
237 ],
238 ];
239
240 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
241
242 $expected = $input;
243 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
244 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
245 $expected['processedTca']['columns']['aField']['config']['ds'] = [
246 'sheets' => [
247 'sDEF' => [
248 'ROOT' => [
249 'type' => 'array',
250 'el' => [
251 'section_1' => [
252 'title' => 'section_1',
253 'type' => 'array',
254 'section' => '1',
255 'el' => [
256 'aFlexContainer' => [
257 'type' => 'array',
258 'title' => 'aFlexContainerLabel',
259 'el' => [
260 'aFlexField' => [
261 'label' => 'aFlexFieldLabel',
262 'config' => [
263 'type' => 'text',
264 'default' => 'defaultValue',
265 'renderType' => 't3editor',
266 'format' => 'html',
267 ],
268 ],
269 ],
270 ],
271 ],
272 ],
273 ],
274 ],
275 ],
276 ],
277 'meta' => [],
278 ];
279
280 $this->assertEquals($expected, $this->subject->addData($input));
281 }
282 }