[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaTypesShowitemTest.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\TcaTypesShowitem;
18
19 /**
20 * Test case
21 */
22 class TcaTypesShowitemTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @var TcaTypesShowitem
26 */
27 protected $subject;
28
29 protected function setUp()
30 {
31 $this->subject = new TcaTypesShowitem();
32 }
33
34 /**
35 * @test
36 */
37 public function addDataRemovesTypeRelatedFields()
38 {
39 $input = [
40 'databaseRow' => [],
41 'recordTypeValue' => 'aType',
42 'processedTca' => [
43 'types' => [
44 'aType' => [
45 'showitem' => 'foo',
46 'subtype_value_field' => 'bar',
47 'subtypes_excludelist' => [],
48 'subtypes_addlist' => [],
49 'bitmask_value_field' => 'foobar',
50 'bitmask_excludelist_bits' => [],
51 ],
52 ],
53 ],
54 ];
55 $expected = $input;
56 $expected['processedTca']['types']['aType'] = [
57 'showitem' => 'foo',
58 ];
59 $this->assertSame($expected, $this->subject->addData($input));
60 }
61
62 /**
63 * @test
64 */
65 public function addDataInsertsMatchingSubtypeAddListAfterSubtypeValueField()
66 {
67 $input = [
68 'recordTypeValue' => 'aType',
69 'databaseRow' => [
70 'theSubtypeValueField' => 'theSubtypeValue',
71 ],
72 'processedTca' => [
73 'types' => [
74 'aType' => [
75 'showitem' => 'aField,theSubtypeValueField,anotherField',
76 'subtype_value_field' => 'theSubtypeValueField',
77 'subtypes_addlist' => [
78 'theSubtypeValue' => 'additionalField',
79 ],
80 ],
81 ],
82 ],
83 ];
84 $expected = [
85 'recordTypeValue' => 'aType',
86 'databaseRow' => [
87 'theSubtypeValueField' => 'theSubtypeValue',
88 ],
89 'processedTca' => [
90 'types' => [
91 'aType' => [
92 'showitem' => 'aField,theSubtypeValueField,additionalField,anotherField',
93 ],
94 ],
95 ],
96 ];
97 $this->assertSame($expected, $this->subject->addData($input));
98 }
99
100 /**
101 * @test
102 */
103 public function addDataInsertsMatchingSubtypeAddListAfterPaletteWithSubtypeValueField()
104 {
105 $input = [
106 'recordTypeValue' => 'aType',
107 'databaseRow' => [
108 'theSubtypeValueField' => 'theSubtypeValue',
109 ],
110 'processedTca' => [
111 'types' => [
112 'aType' => [
113 'showitem' => 'aField,--palette--;;aPalette,anotherField',
114 'subtype_value_field' => 'theSubtypeValueField',
115 'subtypes_addlist' => [
116 'theSubtypeValue' => 'additionalField',
117 ],
118 ],
119 ],
120 'palettes' => [
121 'aPalette' => [
122 'showitem' => 'foo,theSubtypeValueField,bar',
123 ],
124 ],
125 ],
126 ];
127 $expected = [
128 'recordTypeValue' => 'aType',
129 'databaseRow' => [
130 'theSubtypeValueField' => 'theSubtypeValue',
131 ],
132 'processedTca' => [
133 'types' => [
134 'aType' => [
135 'showitem' => 'aField,--palette--;;aPalette,additionalField,anotherField',
136 ],
137 ],
138 'palettes' => [
139 'aPalette' => [
140 'showitem' => 'foo,theSubtypeValueField,bar',
141 ],
142 ],
143 ],
144 ];
145 $this->assertSame($expected, $this->subject->addData($input));
146 }
147
148 /**
149 * @test
150 */
151 public function addDataRemovesMatchingSubtypeExcludeListItems()
152 {
153 $input = [
154 'recordTypeValue' => 'aType',
155 'databaseRow' => [
156 'theSubtypeValueField' => 'subtypeMatch',
157 ],
158 'processedTca' => [
159 'types' => [
160 'aType' => [
161 'showitem' => 'aField, removeMe, anotherField',
162 'subtype_value_field' => 'theSubtypeValueField',
163 'subtypes_excludelist' => [
164 'subtypeMatch' => 'removeMe',
165 ],
166 ],
167 ],
168 ],
169 ];
170 $expected = [
171 'recordTypeValue' => 'aType',
172 'databaseRow' => [
173 'theSubtypeValueField' => 'subtypeMatch',
174 ],
175 'processedTca' => [
176 'types' => [
177 'aType' => [
178 'showitem' => 'aField,anotherField',
179 ],
180 ],
181 ],
182 ];
183 $this->assertSame($expected, $this->subject->addData($input));
184 }
185
186 /**
187 * @test
188 */
189 public function addDataRemovesMatchingSubtypeExcludeListItemsFromPalettes()
190 {
191 $input = [
192 'recordTypeValue' => 'aType',
193 'databaseRow' => [
194 'theSubtypeValueField' => 'subtypeMatch',
195 ],
196 'processedTca' => [
197 'types' => [
198 'aType' => [
199 'showitem' => '',
200 'subtype_value_field' => 'theSubtypeValueField',
201 'subtypes_excludelist' => [
202 'subtypeMatch' => 'removeMe',
203 ],
204 ],
205 ],
206 'palettes' => [
207 'aPalette' => [
208 'showitem' => 'aField, removeMe, anotherField',
209 ],
210 ],
211 ],
212 ];
213 $expected = [
214 'recordTypeValue' => 'aType',
215 'databaseRow' => [
216 'theSubtypeValueField' => 'subtypeMatch',
217 ],
218 'processedTca' => [
219 'types' => [
220 'aType' => [
221 'showitem' => '',
222 ],
223 ],
224 'palettes' => [
225 'aPalette' => [
226 'showitem' => 'aField,anotherField',
227 ],
228 ],
229 ],
230 ];
231 $this->assertSame($expected, $this->subject->addData($input));
232 }
233
234 /**
235 * @test
236 */
237 public function addDataRemovesMatchingBitmaskExcludeListItems()
238 {
239 $input = [
240 'recordTypeValue' => 'aType',
241 'databaseRow' => [
242 'theSubtypeValueField' => 10, // 1 0 1 0
243 ],
244 'processedTca' => [
245 'types' => [
246 'aType' => [
247 'showitem' => 'aField, removedBy3, anotherField, removedBy2',
248 'bitmask_value_field' => 'theSubtypeValueField',
249 'bitmask_excludelist_bits' => [
250 '-2' => 'removedBy2', // Remove if bit 2 is NOT set
251 '+3' => 'removedBy3', // Remvoe if bit 3 is set
252 ],
253 ],
254 ],
255 ],
256 ];
257 $expected = [
258 'recordTypeValue' => 'aType',
259 'databaseRow' => [
260 'theSubtypeValueField' => 10,
261 ],
262 'processedTca' => [
263 'types' => [
264 'aType' => [
265 'showitem' => 'aField,anotherField',
266 ],
267 ],
268 ],
269 ];
270 $this->assertSame($expected, $this->subject->addData($input));
271 }
272
273 /**
274 * @test
275 */
276 public function addDataRemovesMatchingBitmaskExcludeListItemsFromPalettes()
277 {
278 $input = [
279 'recordTypeValue' => 'aType',
280 'databaseRow' => [
281 'theSubtypeValueField' => 10, // 1 0 1 0
282 ],
283 'processedTca' => [
284 'types' => [
285 'aType' => [
286 'showitem' => '',
287 'bitmask_value_field' => 'theSubtypeValueField',
288 'bitmask_excludelist_bits' => [
289 '-2' => 'removeMe', // Remove if bit 2 is NOT set
290 '+3' => 'removeMe2', // Remvoe if bit 3 is set
291 ],
292 ],
293 ],
294 'palettes' => [
295 'aPalette' => [
296 'showitem' => 'aField, removeMe, anotherField',
297 ],
298 'anotherPalette' => [
299 'showitem' => 'removeMe2',
300 ],
301 ],
302 ],
303 ];
304 $expected = [
305 'recordTypeValue' => 'aType',
306 'databaseRow' => [
307 'theSubtypeValueField' => 10,
308 ],
309 'processedTca' => [
310 'types' => [
311 'aType' => [
312 'showitem' => '',
313 ],
314 ],
315 'palettes' => [
316 'aPalette' => [
317 'showitem' => 'aField,anotherField',
318 ],
319 'anotherPalette' => [
320 'showitem' => '',
321 ],
322 ],
323 ],
324 ];
325 $this->assertSame($expected, $this->subject->addData($input));
326 }
327 }