[BUGFIX] FormEngine: Keep columns from overruleTypesArray for processing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaColumnsProcessShowitemTest.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\TcaColumnsProcessShowitem;
19
20 /**
21 * Test case
22 */
23 class TcaColumnsProcessShowitemTest extends UnitTestCase
24 {
25 /**
26 * @var TcaColumnsProcessShowitem
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new TcaColumnsProcessShowitem();
33 }
34
35 /**
36 * @test
37 */
38 public function addDataRegistersColumnsFieldReferencedInShowitems()
39 {
40 $input = [
41 'columnsToProcess' => [],
42 'databaseRow' => [],
43 'recordTypeValue' => 'aType',
44 'processedTca' => [
45 'types' => [
46 'aType' => [
47 'showitem' => 'keepMe'
48 ],
49 ],
50 'columns' => [
51 'keepMe' => [
52 'config' => [
53 'type' => 'input',
54 ]
55 ],
56 'aField' => [
57 'config' => [
58 'type' => 'input',
59 ]
60 ]
61 ]
62 ]
63 ];
64
65 $expected = $input;
66 $expected['columnsToProcess'] = ['keepMe'];
67
68 $this->assertSame($expected, $this->subject->addData($input));
69 }
70
71 /**
72 * @test
73 */
74 public function addDataRegistersColumnsFieldReferencedInOverruledShowitems()
75 {
76 $input = [
77 'columnsToProcess' => [],
78 'databaseRow' => [],
79 'recordTypeValue' => 'aType',
80 'overruleTypesArray' => [
81 'aType' => [
82 'showitem' => 'keepMe'
83 ]
84 ],
85 'processedTca' => [
86 'types' => [
87 'aType' => [
88 'showitem' => 'aField'
89 ],
90 ],
91 'columns' => [
92 'keepMe' => [
93 'config' => [
94 'type' => 'input',
95 ]
96 ],
97 'aField' => [
98 'config' => [
99 'type' => 'input',
100 ]
101 ]
102 ]
103 ]
104 ];
105
106 $expected = $input;
107 $expected['columnsToProcess'] = ['keepMe'];
108
109 $this->assertSame($expected, $this->subject->addData($input));
110 }
111
112 /**
113 * @test
114 */
115 public function addDataKeepsColumnsFieldReferencedInPalette()
116 {
117 $input = [
118 'columnsToProcess' => [],
119 'databaseRow' => [],
120 'recordTypeValue' => 'aType',
121 'processedTca' => [
122 'types' => [
123 'aType' => [
124 'showitem' => '--palette--;;aPalette'
125 ],
126 ],
127 'palettes' => [
128 'aPalette' => [
129 'showitem' => 'keepMe',
130 ],
131 ],
132 'columns' => [
133 'keepMe' => [
134 'config' => [
135 'type' => 'input',
136 ]
137 ],
138 'bField' => [
139 'config' => [
140 'type' => 'input',
141 ]
142 ]
143 ]
144 ]
145 ];
146
147 $expected = $input;
148 $expected['columnsToProcess'] = ['keepMe'];
149
150 $this->assertSame($expected, $this->subject->addData($input));
151 }
152
153 /**
154 * @test
155 */
156 public function addDataSkipsColumnsNotReferencedInShowitemOrPalette()
157 {
158 $input = [
159 'databaseRow' => [],
160 'recordTypeValue' => 'aType',
161 'processedTca' => [
162 'types' => [
163 'aType' => [
164 'showitem' => '--palette--;;aPalette, anotherField'
165 ],
166 ],
167 'palettes' => [
168 'aPalette' => [
169 'showitem' => 'aField',
170 ],
171 ],
172 'columns' => [
173 'aField' => [
174 'config' => [
175 'type' => 'input',
176 ]
177 ],
178 'removeMe' => [
179 'config' => [
180 'type' => 'input',
181 ]
182 ],
183 'anotherField' => [
184 'config' => [
185 'type' => 'input',
186 ]
187 ]
188 ]
189 ]
190 ];
191
192 $expected = $input;
193 $expected['columnsToProcess'] = ['aField', 'anotherField'];
194
195 $this->assertSame($expected, $this->subject->addData($input));
196 }
197 }