[!!!][TASK] Drop core 6->7 auto TCA migrations
[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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26
27 /**
28 * Test case
29 */
30 class TcaFlexPrepareTest extends UnitTestCase
31 {
32 /**
33 * @var TcaFlexPrepare
34 */
35 protected $subject;
36
37 /**
38 * @var BackendUserAuthentication|ObjectProphecy
39 */
40 protected $backendUserProphecy;
41
42 /**
43 * Set up
44 */
45 protected function setUp()
46 {
47 // Suppress cache foo in xml helpers of GeneralUtility
48 /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */
49 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
50 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
51 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
52 $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
53
54 $this->subject = new TcaFlexPrepare();
55 }
56
57 /**
58 * Tear down
59 */
60 protected function tearDown()
61 {
62 GeneralUtility::purgeInstances();
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>input</type>
98 <renderType>inputDateTime</renderType>
99 <max>42</max>
100 </config>
101 </TCEforms>
102 </aFlexField>
103 </el>
104 </ROOT>
105 </sDEF>
106 </sheets>
107 </T3DataStructure>
108 ',
109 ],
110 ],
111 ],
112 ],
113 ],
114 ];
115
116 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
117
118 $expected = $input;
119 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
120 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
121 $expected['processedTca']['columns']['aField']['config']['ds'] = [
122 'sheets' => [
123 'sDEF' => [
124 'ROOT' => [
125 'type' => 'array',
126 'el' => [
127 'aFlexField' => [
128 'label' => 'aFlexFieldLabel',
129 'config' => [
130 'type' => 'input',
131 'renderType' => 'inputDateTime',
132 ],
133 ],
134 ],
135 ],
136 ],
137 ],
138 'meta' => [],
139 ];
140
141 $this->assertEquals($expected, $this->subject->addData($input));
142 }
143
144 /**
145 * @test
146 */
147 public function addDataMigratesFlexformTcaInContainer()
148 {
149 $input = [
150 'systemLanguageRows' => [],
151 'tableName' => 'aTableName',
152 'databaseRow' => [
153 'aField' => [
154 'data' => [],
155 'meta' => [],
156 ],
157 ],
158 'processedTca' => [
159 'columns' => [
160 'aField' => [
161 'config' => [
162 'type' => 'flex',
163 'ds' => [
164 'default' => '
165 <T3DataStructure>
166 <sheets>
167 <sDEF>
168 <ROOT>
169 <type>array</type>
170 <el>
171 <section_1>
172 <title>section_1</title>
173 <type>array</type>
174 <section>1</section>
175 <el>
176 <aFlexContainer>
177 <type>array</type>
178 <title>aFlexContainerLabel</title>
179 <el>
180 <aFlexField>
181 <TCEforms>
182 <label>aFlexFieldLabel</label>
183 <config>
184 <type>input</type>
185 <renderType>inputDateTime</renderType>
186 <max>42</max>
187 </config>
188 </TCEforms>
189 </aFlexField>
190 </el>
191 </aFlexContainer>
192 </el>
193 </section_1>
194 </el>
195 </ROOT>
196 </sDEF>
197 </sheets>
198 </T3DataStructure>
199 ',
200 ],
201 ],
202 ],
203 ],
204 ],
205 ];
206
207 $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
208
209 $expected = $input;
210 $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
211 = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
212 $expected['processedTca']['columns']['aField']['config']['ds'] = [
213 'sheets' => [
214 'sDEF' => [
215 'ROOT' => [
216 'type' => 'array',
217 'el' => [
218 'section_1' => [
219 'title' => 'section_1',
220 'type' => 'array',
221 'section' => '1',
222 'el' => [
223 'aFlexContainer' => [
224 'type' => 'array',
225 'title' => 'aFlexContainerLabel',
226 'el' => [
227 'aFlexField' => [
228 'label' => 'aFlexFieldLabel',
229 'config' => [
230 'type' => 'input',
231 'renderType' => 'inputDateTime',
232 ],
233 ],
234 ],
235 ],
236 ],
237 ],
238 ],
239 ],
240 ],
241 ],
242 'meta' => [],
243 ];
244
245 $this->assertEquals($expected, $this->subject->addData($input));
246 }
247 }