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