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