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