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