[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaFlexPrepareTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\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 TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class TcaFlexPrepareTest extends UnitTestCase
24 {
25 /**
26 * @var TcaFlexPrepare
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new TcaFlexPrepare();
33 }
34
35 /**
36 * @test
37 */
38 public function addDataThrowsExceptionIfBothSheetsAndRootDefined()
39 {
40 $input = [
41 'systemLanguageRows' => [],
42 'databaseRow' => [
43 'aField' => [
44 'data' => [],
45 'meta' => [],
46 ],
47 ],
48 'processedTca' => [
49 'columns' => [
50 'aField' => [
51 'config' => [
52 'type' => 'flex',
53 'ds' => [
54 'ROOT' => [],
55 'sheets' => [],
56 ],
57 ],
58 ],
59 ],
60 ],
61 ];
62
63 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1440676540);
64
65 $this->subject->addData($input);
66 }
67
68 /**
69 * @test
70 */
71 public function addDataRemovesTceFormsFromArrayKeys()
72 {
73 $input = [
74 'processedTca' => [
75 'columns' => [
76 'aField' => [
77 'config' => [
78 'type' => 'flex',
79 'ds' => [
80 'sheets' => [
81 'sDEF' => [
82 'ROOT' => [
83 'TCEforms' => [
84 'sheetDescription' => 'aDescription',
85 'displayCond' => 'aDisplayCond',
86 ],
87 'type' => 'array',
88 'el' => [
89 'aFlexField' => [
90 'TCEforms' => [
91 'label' => 'aFlexFieldLabel',
92 'config' => [
93 'type' => 'input',
94 ],
95 ],
96 ],
97 ],
98 ],
99 ],
100 'sOther' => [
101 'ROOT' => [
102 'TCEforms' => [
103 'sheetTitle' => 'anotherTitle',
104 ],
105 'type' => 'array',
106 'el' => [
107 'bFlexField' => [
108 'TCEforms' => [
109 'label' => 'bFlexFieldLabel',
110 'config' => [
111 'type' => 'input',
112 ],
113 ],
114 ],
115 ],
116 ],
117 ],
118 ],
119 ],
120 ],
121 ],
122 ],
123 ],
124 ];
125
126 $expected = $input;
127 $expected['processedTca']['columns']['aField']['config']['ds'] = [
128 'sheets' => [
129 'sDEF' => [
130 'ROOT' => [
131 'type' => 'array',
132 'el' => [
133 'aFlexField' => [
134 'label' => 'aFlexFieldLabel',
135 'config' => [
136 'type' => 'input',
137 ],
138 ],
139 ],
140 'sheetDescription' => 'aDescription',
141 'displayCond' => 'aDisplayCond',
142 ],
143 ],
144 'sOther' => [
145 'ROOT' => [
146 'type' => 'array',
147 'el' => [
148 'bFlexField' => [
149 'label' => 'bFlexFieldLabel',
150 'config' => [
151 'type' => 'input',
152 ],
153 ],
154 ],
155 'sheetTitle' => 'anotherTitle',
156 ],
157 ],
158 ],
159 ];
160
161 $this->assertEquals($expected, $this->subject->addData($input));
162 }
163
164 /**
165 * @test
166 */
167 public function addDataMigratesFlexformTca()
168 {
169 $input = [
170 'processedTca' => [
171 'columns' => [
172 'aField' => [
173 'config' => [
174 'type' => 'flex',
175 'ds' => [
176 'sheets' => [
177 'sDEF' => [
178 'ROOT' => [
179 'type' => 'array',
180 'el' => [
181 'aFlexField' => [
182 'TCEforms' => [
183 'label' => 'aFlexFieldLabel',
184 'config' => [
185 'type' => 'text',
186 'default' => 'defaultValue',
187 'wizards' => [
188 't3editor' => [
189 'type' => 'userFunc',
190 'userFunc' => 'TYPO3\\CMS\\T3editor\\FormWizard->main',
191 'title' => 't3editor',
192 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
193 'module' => [
194 'name' => 'wizard_table',
195 ],
196 'params' => [
197 'format' => 'html',
198 ],
199 ],
200 ],
201 ],
202 ],
203 ],
204 ],
205 ],
206 ],
207 ],
208 ],
209 ],
210 ],
211 ],
212 ],
213 ];
214
215 $expected = $input;
216 $expected['processedTca']['columns']['aField']['config']['ds'] = [
217 'sheets' => [
218 'sDEF' => [
219 'ROOT' => [
220 'type' => 'array',
221 'el' => [
222 'aFlexField' => [
223 'label' => 'aFlexFieldLabel',
224 'config' => [
225 'type' => 'text',
226 'default' => 'defaultValue',
227 'renderType' => 't3editor',
228 'format' => 'html',
229 ],
230 ],
231 ],
232 ],
233 ],
234 ],
235 ];
236
237 $this->assertEquals($expected, $this->subject->addData($input));
238 }
239
240 /**
241 * @test
242 */
243 public function addDataMigratesFlexformTcaInContainer()
244 {
245 $input = [
246 'processedTca' => [
247 'columns' => [
248 'aField' => [
249 'config' => [
250 'type' => 'flex',
251 'ds_pointerField' => 'pointerField',
252 'ds' => [
253 'sheets' => [
254 'sDEF' => [
255 'ROOT' => [
256 'type' => 'array',
257 'el' => [
258 'section_1' => [
259 'title' => 'section_1',
260 'type' => 'array',
261 'section' => '1',
262 'el' => [
263 'aFlexContainer' => [
264 'type' => 'array',
265 'title' => 'aFlexContainerLabel',
266 'el' => [
267 'aFlexField' => [
268 'TCEforms' => [
269 'label' => 'aFlexFieldLabel',
270 'config' => [
271 'type' => 'text',
272 'default' => 'defaultValue',
273 'wizards' => [
274 't3editor' => [
275 'type' => 'userFunc',
276 'userFunc' => 'TYPO3\CMS\T3editor\FormWizard->main',
277 'title' => 't3editor',
278 'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif',
279 'module' => [
280 'name' => 'wizard_table',
281 ],
282 'params' => [
283 'format' => 'html',
284 ],
285 ],
286 ],
287 ],
288 ],
289 ],
290 ],
291 ],
292 ],
293 ],
294 ],
295 ],
296 ],
297 ],
298 ],
299 ],
300 ],
301 ],
302 ],
303 ];
304
305 $expected = $input;
306 $expected['processedTca']['columns']['aField']['config']['ds'] = [
307 'sheets' => [
308 'sDEF' => [
309 'ROOT' => [
310 'type' => 'array',
311 'el' => [
312 'section_1' => [
313 'title' => 'section_1',
314 'type' => 'array',
315 'section' => '1',
316 'el' => [
317 'aFlexContainer' => [
318 'type' => 'array',
319 'title' => 'aFlexContainerLabel',
320 'el' => [
321 'aFlexField' => [
322 'label' => 'aFlexFieldLabel',
323 'config' => [
324 'type' => 'text',
325 'default' => 'defaultValue',
326 'renderType' => 't3editor',
327 'format' => 'html',
328 ],
329 ],
330 ],
331 ],
332 ],
333 ],
334 ],
335 ],
336 ],
337 ],
338 ];
339
340 $this->assertEquals($expected, $this->subject->addData($input));
341 }
342 }