[BUGFIX] Notice free FormEngine testing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaColumnsProcessShowitemTest.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\TcaColumnsProcessShowitem;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class TcaColumnsProcessShowitemTest extends UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function addDataThrowsExceptionIfTypesHasNoShowitem()
29 {
30 $input = [
31 'recordTypeValue' => 'aType',
32 'tableName' => 'aTable',
33 'processedTca' => [
34 'columns' => [
35 'aField' => [
36 'type' => 'aType',
37 ],
38 ],
39 'types' => [
40 'aType' => [],
41 ],
42 ],
43 ];
44 $this->expectException(\UnexpectedValueException::class);
45 $this->expectExceptionCode(1438614542);
46 (new TcaColumnsProcessShowitem)->addData($input);
47 }
48
49 /**
50 * @test
51 */
52 public function addDataRegistersColumnsFieldReferencedInShowitems()
53 {
54 $input = [
55 'columnsToProcess' => [],
56 'databaseRow' => [],
57 'recordTypeValue' => 'aType',
58 'isInlineChild' => false,
59 'processedTca' => [
60 'types' => [
61 'aType' => [
62 'showitem' => 'keepMe'
63 ],
64 ],
65 'columns' => [
66 'keepMe' => [
67 'config' => [
68 'type' => 'input',
69 ]
70 ],
71 'aField' => [
72 'config' => [
73 'type' => 'input',
74 ]
75 ]
76 ]
77 ]
78 ];
79
80 $expected = $input;
81 $expected['columnsToProcess'] = ['keepMe'];
82
83 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
84 }
85
86 /**
87 * @test
88 */
89 public function addDataKeepsColumnsFieldReferencedInPalette()
90 {
91 $input = [
92 'columnsToProcess' => [],
93 'databaseRow' => [],
94 'recordTypeValue' => 'aType',
95 'isInlineChild' => false,
96 'processedTca' => [
97 'types' => [
98 'aType' => [
99 'showitem' => '--palette--;;aPalette'
100 ],
101 ],
102 'palettes' => [
103 'aPalette' => [
104 'showitem' => 'keepMe',
105 ],
106 ],
107 'columns' => [
108 'keepMe' => [
109 'config' => [
110 'type' => 'input',
111 ]
112 ],
113 'bField' => [
114 'config' => [
115 'type' => 'input',
116 ]
117 ]
118 ]
119 ]
120 ];
121
122 $expected = $input;
123 $expected['columnsToProcess'] = ['keepMe'];
124
125 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
126 }
127
128 /**
129 * @test
130 */
131 public function addDataSkipsColumnsNotReferencedInShowitemOrPalette()
132 {
133 $input = [
134 'databaseRow' => [],
135 'recordTypeValue' => 'aType',
136 'isInlineChild' => false,
137 'processedTca' => [
138 'types' => [
139 'aType' => [
140 'showitem' => '--palette--;;aPalette, anotherField'
141 ],
142 ],
143 'palettes' => [
144 'aPalette' => [
145 'showitem' => 'aField',
146 ],
147 ],
148 'columns' => [
149 'aField' => [
150 'config' => [
151 'type' => 'input',
152 ]
153 ],
154 'removeMe' => [
155 'config' => [
156 'type' => 'input',
157 ]
158 ],
159 'anotherField' => [
160 'config' => [
161 'type' => 'input',
162 ]
163 ]
164 ]
165 ]
166 ];
167
168 $expected = $input;
169 $expected['columnsToProcess'] = ['aField', 'anotherField'];
170
171 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
172 }
173
174 /**
175 * @test
176 */
177 public function addDataSkipsColumnsForCollapsedInlineChild()
178 {
179 $input = [
180 'command' => 'edit',
181 'databaseRow' => [
182 'uid' => 42,
183 ],
184 'recordTypeValue' => 'aType',
185 'processedTca' => [
186 'types' => [
187 'aType' => [
188 'showitem' => 'aField',
189 ],
190 ],
191 'columns' => [
192 'aField' => [
193 'config' => [
194 'type' => 'input',
195 ]
196 ],
197 ],
198 ],
199 'inlineParentConfig' => [
200 'foreign_table' => 'aTable',
201 ],
202 'isInlineChild' => true,
203 'isInlineChildExpanded' => false,
204 'isInlineAjaxOpeningContext' => false,
205 'inlineExpandCollapseStateArray' => [],
206 ];
207 $expected = $input;
208 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
209 }
210
211 /**
212 * @test
213 */
214 public function addDataSkipsColumnsForCollapsedAllInlineChild()
215 {
216 $input = [
217 'command' => 'edit',
218 'databaseRow' => [
219 'uid' => 42,
220 ],
221 'recordTypeValue' => 'aType',
222 'processedTca' => [
223 'types' => [
224 'aType' => [
225 'showitem' => 'aField',
226 ],
227 ],
228 'columns' => [
229 'aField' => [
230 'config' => [
231 'type' => 'input',
232 ]
233 ],
234 ],
235 ],
236 'inlineParentConfig' => [
237 'foreign_table' => 'aTable',
238 'appearance' => [
239 'collapseAll' => true,
240 ],
241 ],
242 'isInlineChild' => true,
243 'isInlineChildExpanded' => false,
244 'isInlineAjaxOpeningContext' => false,
245 'inlineExpandCollapseStateArray' => [
246 'aTable' => [
247 42,
248 ],
249 ],
250 ];
251 $expected = $input;
252 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
253 }
254
255 /**
256 * @test
257 */
258 public function addDataAddsColumnsForExpandedInlineChild()
259 {
260 $input = [
261 'command' => 'edit',
262 'databaseRow' => [
263 'uid' => 42,
264 ],
265 'recordTypeValue' => 'aType',
266 'processedTca' => [
267 'types' => [
268 'aType' => [
269 'showitem' => 'aField',
270 ],
271 ],
272 'columns' => [
273 'aField' => [
274 'config' => [
275 'type' => 'input',
276 ]
277 ],
278 ],
279 ],
280 'inlineParentConfig' => [
281 'foreign_table' => 'aTable',
282 ],
283 'isInlineChild' => true,
284 'isInlineChildExpanded' => true,
285 'isInlineAjaxOpeningContext' => false,
286 'inlineExpandCollapseStateArray' => [
287 'aTable' => [
288 42,
289 ],
290 ],
291 ];
292 $expected = $input;
293 $expected['columnsToProcess'] = ['aField'];
294 $this->assertSame($expected, (new TcaColumnsProcessShowitem)->addData($input));
295 }
296 }