[BUGFIX] Notice free FormEngine testing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaInlineExpandCollapseStateTest.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\TcaInlineExpandCollapseState;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class TcaInlineExpandCollapseStateTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function addDataAddsInlineStatusForTableUid()
30 {
31 $input = [
32 'command' => 'edit',
33 'tableName' => 'aParentTable',
34 'databaseRow' => [
35 'uid' => 5,
36 ],
37 'isInlineChildExpanded' => false,
38 'inlineParentConfig' => [
39 'foreign_table' => 'aTable',
40 ],
41 'isInlineAjaxOpeningContext' => false,
42 ];
43 $inlineState = [
44 'aParentTable' => [
45 5 => [
46 'aChildTable' => [
47 // Records 23 and 42 are expanded
48 23,
49 42,
50 ],
51 ],
52 ],
53 ];
54 $GLOBALS['BE_USER'] = new \stdClass();
55 $GLOBALS['BE_USER']->uc = [
56 'inlineView' => serialize($inlineState),
57 ];
58 $expected = $input;
59 $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
60 $this->assertSame($expected, (new TcaInlineExpandCollapseState)->addData($input));
61 }
62
63 /**
64 * @test
65 */
66 public function addDataAddsInlineStatusForSecondLevelChild()
67 {
68 $input = [
69 'command' => 'edit',
70 'tableName' => 'bChildTable',
71 'databaseRow' => [
72 'uid' => 13,
73 ],
74 'inlineTopMostParentTableName' => 'aParentTable',
75 'inlineTopMostParentUid' => 5,
76 'isInlineChildExpanded' => false,
77 'inlineParentConfig' => [
78 'foreign_table' => 'aTable',
79 ],
80 'isInlineAjaxOpeningContext' => false,
81 ];
82 $inlineState = [
83 'aParentTable' => [
84 5 => [
85 'aChildTable' => [
86 // Records 23 and 42 are expanded
87 23,
88 42,
89 ],
90 'bChildTable' => [
91 // Records 13 and 66 are expanded
92 13,
93 66,
94 ],
95 ],
96 ],
97 ];
98 $GLOBALS['BE_USER'] = new \stdClass();
99 $GLOBALS['BE_USER']->uc = [
100 'inlineView' => serialize($inlineState),
101 ];
102 $expected = $input;
103 $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
104 $this->assertSame($expected, (new TcaInlineExpandCollapseState)->addData($input));
105 }
106
107 /**
108 * @return array
109 */
110 public function addDataAddsCorrectIsInlineChildExpandedDataProvider()
111 {
112 return [
113 'Inline child is expanded because of state in expandCollapseStateArray' => [
114 [
115 'command' => 'edit',
116 'databaseRow' => [
117 'uid' => 42,
118 ],
119 'recordTypeValue' => 'aType',
120 'processedTca' => [
121 'types' => [
122 'aType' => [
123 'showitem' => 'aField',
124 ],
125 ],
126 'columns' => [
127 'aField' => [
128 'config' => [
129 'type' => 'input',
130 ]
131 ],
132 ],
133 ],
134 'inlineParentConfig' => [
135 'foreign_table' => 'aTable',
136 ],
137 'isInlineChild' => true,
138 'isInlineChildExpanded' => false,
139 'isInlineAjaxOpeningContext' => false,
140 'inlineExpandCollapseStateArray' => [
141 'aTable' => [
142 42,
143 ],
144 ],
145 ],
146 true
147 ],
148 'Inline child is expanded because of ajax opening context' => [
149 [
150 'command' => 'edit',
151 'tableName' => 'aParentTable',
152 'databaseRow' => [
153 'uid' => 42,
154 ],
155 'recordTypeValue' => 'aType',
156 'processedTca' => [
157 'types' => [
158 'aType' => [
159 'showitem' => 'aField',
160 ],
161 ],
162 'columns' => [
163 'aField' => [
164 'config' => [
165 'type' => 'input',
166 ]
167 ],
168 ],
169 ],
170 'inlineParentConfig' => [
171 'foreign_table' => 'aTable',
172 'appearance' => [
173 'collapseAll' => true,
174 ],
175 ],
176 'isInlineChild' => true,
177 'isInlineChildExpanded' => false,
178 'isInlineAjaxOpeningContext' => true,
179 'inlineExpandCollapseStateArray' => [],
180 ],
181 true
182 ],
183 'Inline child is collapsed because of collapseAll' => [
184 [
185 'command' => 'edit',
186 'tableName' => 'aParentTable',
187 'databaseRow' => [
188 'uid' => 42,
189 ],
190 'recordTypeValue' => 'aType',
191 'processedTca' => [
192 'types' => [
193 'aType' => [
194 'showitem' => 'aField',
195 ],
196 ],
197 'columns' => [
198 'aField' => [
199 'config' => [
200 'type' => 'input',
201 ]
202 ],
203 ],
204 ],
205 'inlineParentConfig' => [
206 'foreign_table' => 'aTable',
207 'appearance' => [
208 'collapseAll' => true,
209 ],
210 ],
211 'isInlineChild' => true,
212 'isInlineChildExpanded' => false,
213 'isInlineAjaxOpeningContext' => false,
214 'inlineExpandCollapseStateArray' => [],
215 ],
216 false
217 ],
218 'Inline child is expanded because of expandAll (inverse collapseAll setting)' => [
219 [
220 'command' => 'edit',
221 'tableName' => 'aParentTable',
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' => false,
244 ],
245 ],
246 'isInlineChild' => true,
247 'isInlineChildExpanded' => false,
248 'inlineExpandCollapseStateArray' => [],
249 ],
250 true
251 ],
252 'New inline child is expanded' => [
253 [
254 'command' => 'new',
255 'databaseRow' => [
256 'uid' => 'NEW1234',
257 ],
258 'recordTypeValue' => 'aType',
259 'processedTca' => [
260 'types' => [
261 'aType' => [
262 'showitem' => 'aField',
263 ],
264 ],
265 'columns' => [
266 'aField' => [
267 'config' => [
268 'type' => 'input',
269 ]
270 ],
271 ],
272 ],
273 'inlineParentConfig' => [
274 'foreign_table' => 'aTable',
275 'appearance' => [
276 'collapseAll' => true,
277 ],
278 ],
279 'isInlineChild' => true,
280 'isInlineChildExpanded' => false,
281 'isInlineAjaxOpeningContext' => false,
282 'inlineExpandCollapseStateArray' => [],
283 ],
284 true
285 ],
286 'Inline child marked as expanded stays expanded (e.g. combination child)' => [
287 [
288 'command' => 'edit',
289 'tableName' => 'aParentTable',
290 'databaseRow' => [
291 'uid' => 42,
292 ],
293 'recordTypeValue' => 'aType',
294 'processedTca' => [
295 'types' => [
296 'aType' => [
297 'showitem' => 'aField',
298 ],
299 ],
300 'columns' => [
301 'aField' => [
302 'config' => [
303 'type' => 'input',
304 ]
305 ],
306 ],
307 ],
308 'inlineParentConfig' => [
309 'foreign_table' => 'aTable',
310 'appearance' => [
311 'collapseAll' => true,
312 ],
313 ],
314 'isInlineChild' => true,
315 'isInlineChildExpanded' => true,
316 'inlineExpandCollapseStateArray' => [],
317 ],
318 true
319 ],
320 ];
321 }
322
323 /**
324 * @test
325 * @dataProvider addDataAddsCorrectIsInlineChildExpandedDataProvider
326 *
327 * @param array $input
328 * @param bool $expectedIsInlineChildExpanded
329 */
330 public function addDataAddsCorrectIsInlineChildExpanded(array $input, $expectedIsInlineChildExpanded)
331 {
332 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
333 $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
334
335 $expected = $input;
336 $expected['isInlineChildExpanded'] = $expectedIsInlineChildExpanded;
337 $this->assertSame($expected, (new TcaInlineExpandCollapseState)->addData($input));
338 }
339 }