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