[!!!][TASK] Drop entry point typo3/install/index.php
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / UnitDeprecated / Form / FormDataProvider / DatabaseRowInitializeNewTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider;
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
18 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowInitializeNew;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case for TcaFlexPrepare to render the functionality when a TCA migration happened
23 */
24 class DatabaseRowInitializeNewTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function addDataSetsDefaultDataFromGetIfColumnIsDefinedInTca()
30 {
31 $input = [
32 'command' => 'new',
33 'tableName' => 'aTable',
34 'vanillaUid' => 23,
35 'neighborRow' => null,
36 'inlineChildChildUid' => null,
37 'isInlineChild' => false,
38 'databaseRow' => [],
39 'processedTca' => [
40 'columns' => [
41 'aField' => [],
42 ],
43 ],
44 ];
45 $GLOBALS['_GET'] = [
46 'defVals' => [
47 'aTable' => [
48 'aField' => 'getValue',
49 ],
50 ],
51 ];
52 $expected = [
53 'aField' => 'getValue',
54 'pid' => 23,
55 ];
56 $result = (new DatabaseRowInitializeNew())->addData($input);
57 $this->assertSame($expected, $result['databaseRow']);
58 }
59
60 /**
61 * @test
62 */
63 public function addDataSetsDefaultDataFromPostIfColumnIsDefinedInTca()
64 {
65 $input = [
66 'command' => 'new',
67 'tableName' => 'aTable',
68 'vanillaUid' => 23,
69 'neighborRow' => null,
70 'inlineChildChildUid' => null,
71 'isInlineChild' => false,
72 'databaseRow' => [],
73 'processedTca' => [
74 'columns' => [
75 'aField' => [],
76 ],
77 ],
78 ];
79 $GLOBALS['_POST'] = [
80 'defVals' => [
81 'aTable' => [
82 'aField' => 'postValue',
83 ],
84 ],
85 ];
86 $expected = [
87 'aField' => 'postValue',
88 'pid' => 23,
89 ];
90 $result = (new DatabaseRowInitializeNew())->addData($input);
91 $this->assertSame($expected, $result['databaseRow']);
92 }
93
94 /**
95 * @test
96 */
97 public function addDataSetsPrioritizesDefaultPostOverDefaultGet()
98 {
99 $input = [
100 'command' => 'new',
101 'tableName' => 'aTable',
102 'vanillaUid' => 23,
103 'neighborRow' => null,
104 'inlineChildChildUid' => null,
105 'isInlineChild' => false,
106 'databaseRow' => [],
107 'processedTca' => [
108 'columns' => [
109 'aField' => [],
110 ],
111 ],
112 ];
113 $GLOBALS['_GET'] = [
114 'defVals' => [
115 'aTable' => [
116 'aField' => 'getValue',
117 ],
118 ],
119 ];
120 $GLOBALS['_POST'] = [
121 'defVals' => [
122 'aTable' => [
123 'aField' => 'postValue',
124 ],
125 ],
126 ];
127 $expected = [
128 'aField' => 'postValue',
129 'pid' => 23,
130 ];
131 $result = (new DatabaseRowInitializeNew())->addData($input);
132 $this->assertSame($expected, $result['databaseRow']);
133 }
134
135 /**
136 * @test
137 */
138 public function addDataDoesNotSetDefaultDataFromGetPostIfColumnIsMissingInTca()
139 {
140 $input = [
141 'command' => 'new',
142 'tableName' => 'aTable',
143 'vanillaUid' => 23,
144 'neighborRow' => null,
145 'inlineChildChildUid' => null,
146 'isInlineChild' => false,
147 'databaseRow' => [],
148 'userTsConfig' => [
149 'TCAdefaults.' => [
150 'aTable.' => [
151 'aField' => 'pageTsValue',
152 ],
153 ],
154 ],
155 'processedTca' => [
156 'columns' => [],
157 ],
158 ];
159 $GLOBALS['_GET'] = [
160 'defVals' => [
161 'aTable' => [
162 'aField' => 'getValue',
163 ],
164 ],
165 ];
166 $GLOBALS['_POST'] = [
167 'defVals' => [
168 'aTable' => [
169 'aField' => 'postValue',
170 ],
171 ],
172 ];
173 $expected = [
174 'pid' => 23,
175 ];
176 $result = (new DatabaseRowInitializeNew())->addData($input);
177 $this->assertSame($expected, $result['databaseRow']);
178 }
179
180 /**
181 * @test
182 */
183 public function addDataSetsDefaultDataOverrulingGetPost()
184 {
185 $input = [
186 'command' => 'new',
187 'tableName' => 'aTable',
188 'vanillaUid' => 23,
189 'inlineChildChildUid' => null,
190 'isInlineChild' => false,
191 'databaseRow' => [],
192 'neighborRow' => [
193 'aField' => 'valueFromNeighbor',
194 ],
195 'pageTsConfig' => [
196 'TCAdefaults.' => [
197 'aTable.' => [
198 'aField' => 'pageTsValue',
199 ],
200 ],
201 ],
202 'userTsConfig' => [
203 'TCAdefaults.' => [
204 'aTable.' => [
205 'aField' => 'userTsValue',
206 ],
207 ],
208 ],
209 'processedTca' => [
210 'ctrl' => [
211 'useColumnsForDefaultValues' => 'aField',
212 ],
213 'columns' => [
214 'aField' => [],
215 ],
216 ],
217 ];
218 $GLOBALS['_POST'] = [
219 'defVals' => [
220 'aTable' => [
221 'aField' => 'postValue',
222 ],
223 ],
224 ];
225 $expected = [
226 'aField' => 'postValue',
227 'pid' => 23,
228 ];
229 $result = (new DatabaseRowInitializeNew())->addData($input);
230 $this->assertSame($expected, $result['databaseRow']);
231 }
232 }