‪TYPO3CMS  11.5
TcaInlineExpandCollapseStateTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪TcaInlineExpandCollapseStateTest extends UnitTestCase
29 {
30  use ProphecyTrait;
31 
35  public function ‪addDataAddsInlineStatusForTableUid(): void
36  {
37  $input = [
38  'command' => 'edit',
39  'tableName' => 'aParentTable',
40  'databaseRow' => [
41  'uid' => 5,
42  ],
43  'isInlineChildExpanded' => false,
44  'inlineParentConfig' => [
45  'foreign_table' => 'aTable',
46  ],
47  'isInlineAjaxOpeningContext' => false,
48  ];
49  $inlineState = [
50  'aParentTable' => [
51  5 => [
52  'aChildTable' => [
53  // Records 23 and 42 are expanded
54  23,
55  42,
56  ],
57  ],
58  ],
59  ];
60  ‪$GLOBALS['BE_USER'] = new \stdClass();
61  ‪$GLOBALS['BE_USER']->uc = [
62  'inlineView' => json_encode($inlineState),
63  ];
64  $expected = $input;
65  $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
66  self::assertSame($expected, (new ‪TcaInlineExpandCollapseState())->addData($input));
67  }
68 
72  public function ‪addDataAddsInlineStatusForSecondLevelChild(): void
73  {
74  $input = [
75  'command' => 'edit',
76  'tableName' => 'bChildTable',
77  'databaseRow' => [
78  'uid' => 13,
79  ],
80  'inlineTopMostParentTableName' => 'aParentTable',
81  'inlineTopMostParentUid' => 5,
82  'isInlineChildExpanded' => false,
83  'inlineParentConfig' => [
84  'foreign_table' => 'aTable',
85  ],
86  'isInlineAjaxOpeningContext' => false,
87  ];
88  $inlineState = [
89  'aParentTable' => [
90  5 => [
91  'aChildTable' => [
92  // Records 23 and 42 are expanded
93  23,
94  42,
95  ],
96  'bChildTable' => [
97  // Records 13 and 66 are expanded
98  13,
99  66,
100  ],
101  ],
102  ],
103  ];
104  ‪$GLOBALS['BE_USER'] = new \stdClass();
105  ‪$GLOBALS['BE_USER']->uc = [
106  'inlineView' => json_encode($inlineState),
107  ];
108  $expected = $input;
109  $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
110  self::assertSame($expected, (new ‪TcaInlineExpandCollapseState())->addData($input));
111  }
112 
117  {
118  return [
119  'Inline child is expanded because of state in expandCollapseStateArray' => [
120  [
121  'command' => 'edit',
122  'databaseRow' => [
123  'uid' => 42,
124  ],
125  'recordTypeValue' => 'aType',
126  'processedTca' => [
127  'types' => [
128  'aType' => [
129  'showitem' => 'aField',
130  ],
131  ],
132  'columns' => [
133  'aField' => [
134  'config' => [
135  'type' => 'input',
136  ],
137  ],
138  ],
139  ],
140  'inlineParentConfig' => [
141  'foreign_table' => 'aTable',
142  ],
143  'isInlineChild' => true,
144  'isInlineChildExpanded' => false,
145  'isInlineAjaxOpeningContext' => false,
146  'inlineExpandCollapseStateArray' => [
147  'aTable' => [
148  42,
149  ],
150  ],
151  ],
152  true,
153  ],
154  'Inline child is expanded because of ajax opening context' => [
155  [
156  'command' => 'edit',
157  'tableName' => 'aParentTable',
158  'databaseRow' => [
159  'uid' => 42,
160  ],
161  'recordTypeValue' => 'aType',
162  'processedTca' => [
163  'types' => [
164  'aType' => [
165  'showitem' => 'aField',
166  ],
167  ],
168  'columns' => [
169  'aField' => [
170  'config' => [
171  'type' => 'input',
172  ],
173  ],
174  ],
175  ],
176  'inlineParentConfig' => [
177  'foreign_table' => 'aTable',
178  'appearance' => [
179  'collapseAll' => true,
180  ],
181  ],
182  'isInlineChild' => true,
183  'isInlineChildExpanded' => false,
184  'isInlineAjaxOpeningContext' => true,
185  'inlineExpandCollapseStateArray' => [],
186  ],
187  true,
188  ],
189  'Inline child is collapsed because of collapseAll' => [
190  [
191  'command' => 'edit',
192  'tableName' => 'aParentTable',
193  'databaseRow' => [
194  'uid' => 42,
195  ],
196  'recordTypeValue' => 'aType',
197  'processedTca' => [
198  'types' => [
199  'aType' => [
200  'showitem' => 'aField',
201  ],
202  ],
203  'columns' => [
204  'aField' => [
205  'config' => [
206  'type' => 'input',
207  ],
208  ],
209  ],
210  ],
211  'inlineParentConfig' => [
212  'foreign_table' => 'aTable',
213  'appearance' => [
214  'collapseAll' => true,
215  ],
216  ],
217  'isInlineChild' => true,
218  'isInlineChildExpanded' => false,
219  'isInlineAjaxOpeningContext' => false,
220  'inlineExpandCollapseStateArray' => [],
221  ],
222  false,
223  ],
224  'Inline child is expanded because of expandAll (inverse collapseAll setting)' => [
225  [
226  'command' => 'edit',
227  'tableName' => 'aParentTable',
228  'databaseRow' => [
229  'uid' => 42,
230  ],
231  'recordTypeValue' => 'aType',
232  'processedTca' => [
233  'types' => [
234  'aType' => [
235  'showitem' => 'aField',
236  ],
237  ],
238  'columns' => [
239  'aField' => [
240  'config' => [
241  'type' => 'input',
242  ],
243  ],
244  ],
245  ],
246  'inlineParentConfig' => [
247  'foreign_table' => 'aTable',
248  'appearance' => [
249  'collapseAll' => false,
250  ],
251  ],
252  'isInlineChild' => true,
253  'isInlineChildExpanded' => false,
254  'inlineExpandCollapseStateArray' => [],
255  ],
256  true,
257  ],
258  'New inline child is expanded' => [
259  [
260  'command' => 'new',
261  'databaseRow' => [
262  'uid' => 'NEW1234',
263  ],
264  'recordTypeValue' => 'aType',
265  'processedTca' => [
266  'types' => [
267  'aType' => [
268  'showitem' => 'aField',
269  ],
270  ],
271  'columns' => [
272  'aField' => [
273  'config' => [
274  'type' => 'input',
275  ],
276  ],
277  ],
278  ],
279  'inlineParentConfig' => [
280  'foreign_table' => 'aTable',
281  'appearance' => [
282  'collapseAll' => true,
283  ],
284  ],
285  'isInlineChild' => true,
286  'isInlineChildExpanded' => false,
287  'isInlineAjaxOpeningContext' => false,
288  'inlineExpandCollapseStateArray' => [],
289  ],
290  true,
291  ],
292  'Inline child marked as expanded stays expanded (e.g. combination child)' => [
293  [
294  'command' => 'edit',
295  'tableName' => 'aParentTable',
296  'databaseRow' => [
297  'uid' => 42,
298  ],
299  'recordTypeValue' => 'aType',
300  'processedTca' => [
301  'types' => [
302  'aType' => [
303  'showitem' => 'aField',
304  ],
305  ],
306  'columns' => [
307  'aField' => [
308  'config' => [
309  'type' => 'input',
310  ],
311  ],
312  ],
313  ],
314  'inlineParentConfig' => [
315  'foreign_table' => 'aTable',
316  'appearance' => [
317  'collapseAll' => true,
318  ],
319  ],
320  'isInlineChild' => true,
321  'isInlineChildExpanded' => true,
322  'inlineExpandCollapseStateArray' => [],
323  ],
324  true,
325  ],
326  ];
327  }
328 
336  public function ‪addDataAddsCorrectIsInlineChildExpanded(array $input, bool $expectedIsInlineChildExpanded): void
337  {
338  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
339  ‪$GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
340 
341  $expected = $input;
342  $expected['isInlineChildExpanded'] = $expectedIsInlineChildExpanded;
343  self::assertSame($expected, (new ‪TcaInlineExpandCollapseState())->addData($input));
344  }
345 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineExpandCollapseStateTest
Definition: TcaInlineExpandCollapseStateTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineExpandCollapseStateTest\addDataAddsCorrectIsInlineChildExpanded
‪addDataAddsCorrectIsInlineChildExpanded(array $input, bool $expectedIsInlineChildExpanded)
Definition: TcaInlineExpandCollapseStateTest.php:335
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineExpandCollapseStateTest\addDataAddsCorrectIsInlineChildExpandedDataProvider
‪array addDataAddsCorrectIsInlineChildExpandedDataProvider()
Definition: TcaInlineExpandCollapseStateTest.php:115
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineExpandCollapseStateTest\addDataAddsInlineStatusForTableUid
‪addDataAddsInlineStatusForTableUid()
Definition: TcaInlineExpandCollapseStateTest.php:34
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineExpandCollapseStateTest\addDataAddsInlineStatusForSecondLevelChild
‪addDataAddsInlineStatusForSecondLevelChild()
Definition: TcaInlineExpandCollapseStateTest.php:71
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineExpandCollapseState
Definition: TcaInlineExpandCollapseState.php:26