[BUGFIX] Inline children need additional state flags
[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\Core\Tests\UnitTestCase;
18 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineExpandCollapseState;
19
20 /**
21 * Test case
22 */
23 class TcaInlineExpandCollapseStateTest extends UnitTestCase
24 {
25 /**
26 * @var TcaInlineExpandCollapseState
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new TcaInlineExpandCollapseState();
33 }
34
35 /**
36 * @test
37 */
38 public function addDataAddsInlineStatusForTableUid()
39 {
40 $input = [
41 'command' => 'edit',
42 'tableName' => 'aParentTable',
43 'databaseRow' => [
44 'uid' => 5,
45 ],
46 ];
47 $inlineState = [
48 'aParentTable' => [
49 5 => [
50 'aChildTable' => [
51 // Records 23 and 42 are expanded
52 23,
53 42,
54 ],
55 ],
56 ],
57 ];
58 $GLOBALS['BE_USER'] = new \stdClass();
59 $GLOBALS['BE_USER']->uc = [
60 'inlineView' => serialize($inlineState),
61 ];
62 $expected = $input;
63 $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
64 $this->assertSame($expected, $this->subject->addData($input));
65 }
66
67 /**
68 * @test
69 */
70 public function addDataAddsInlineStatusForSecondLevelChild()
71 {
72 $input = [
73 'command' => 'edit',
74 'tableName' => 'bChildTable',
75 'databaseRow' => [
76 'uid' => 13,
77 ],
78 'inlineStructure' => [
79 'stable' => [
80 [
81 'table' => 'aParentTable',
82 'uid' => 5,
83 'field' => 'inline_2',
84 ],
85 ],
86 ],
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' => serialize($inlineState),
107 ];
108 $expected = $input;
109 $expected['inlineExpandCollapseStateArray'] = $inlineState['aParentTable'][5];
110 $this->assertSame($expected, $this->subject->addData($input));
111 }
112 }