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