[BUGFIX] FormEngine inline foreign_selector and foreign_unique
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / InlineOverrrideChildTcaTest.php
1 <?php
2 namespace typo3\sysext\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\Backend\Form\FormDataProvider\InlineOverrideChildTca;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19
20 /**
21 * InlineOverrideChildTca Test file
22 */
23 class InlineOverrrideChildTcaTest extends UnitTestCase
24 {
25
26 /**
27 * @var InlineOverrideChildTca
28 */
29 protected $subject;
30
31 protected function setUp()
32 {
33 $this->subject = new InlineOverrideChildTca();
34 }
35
36 /**
37 * @test
38 */
39 public function addDataOverrulesShowitemByGivenInlineOverruleTypes()
40 {
41 $input = [
42 'inlineParentConfig' => [
43 'foreign_types' => [
44 'aType' => [
45 'showitem' => 'keepMe',
46 ],
47 ],
48 ],
49 'processedTca' => [
50 'types' => [
51 'aType' => [
52 'showitem' => 'keepMe, aField',
53 ],
54 'bType' => [
55 'showitem' => 'keepMe, aField',
56 ],
57 ],
58 ],
59 ];
60
61 $expected = $input;
62 $expected['processedTca']['types']['aType']['showitem'] = 'keepMe';
63
64 $this->assertSame($expected, $this->subject->addData($input));
65 }
66
67 /**
68 * @test
69 */
70 public function addDataAddsTypeShowitemByGivenInlineOverruleTypes()
71 {
72 $input = [
73 'inlineParentConfig' => [
74 'foreign_types' => [
75 'aType' => [
76 'showitem' => 'keepMe',
77 ],
78 'cType' => [
79 'showitem' => 'keepMe',
80 ],
81 ],
82 ],
83 'processedTca' => [
84 'types' => [
85 'aType' => [
86 'showitem' => 'keepMe, aField',
87 ],
88 'bType' => [
89 'showitem' => 'keepMe, aField',
90 ],
91 ],
92 ],
93 ];
94
95 $expected = $input;
96 $expected['processedTca']['types']['aType']['showitem'] = 'keepMe';
97 $expected['processedTca']['types']['cType']['showitem'] = 'keepMe';
98
99 $this->assertSame($expected, $this->subject->addData($input));
100 }
101
102 /**
103 * @test
104 */
105 public function addDataMergesForeignSelectorFieldTcaOverride()
106 {
107 $input = [
108 'inlineParentConfig' => [
109 'foreign_selector' => 'uid_local',
110 'foreign_selector_fieldTcaOverride' => [
111 'label' => 'aDifferentLabel',
112 'config' => [
113 'aGivenSetting' => 'overrideValue',
114 'aNewSetting' => 'anotherNewValue',
115 'appearance' => [
116 'elementBrowserType' => 'file',
117 'elementBrowserAllowed' => 'jpg,png'
118 ],
119 ],
120 ],
121 ],
122 'processedTca' => [
123 'columns' => [
124 'uid_local' => [
125 'label' => 'aLabel',
126 'config' => [
127 'aGivenSetting' => 'aValue',
128 'doNotChangeMe' => 'doNotChangeMe',
129 'appearance' => [
130 'elementBrowserType' => 'db',
131 ],
132 ],
133 ]
134 ],
135 ],
136 ];
137
138 $expected = $input;
139 $expected['processedTca']['columns']['uid_local'] = [
140 'label' => 'aDifferentLabel',
141 'config' => [
142 'aGivenSetting' => 'overrideValue',
143 'doNotChangeMe' => 'doNotChangeMe',
144 'appearance' => [
145 'elementBrowserType' => 'file',
146 'elementBrowserAllowed' => 'jpg,png',
147 ],
148 'aNewSetting' => 'anotherNewValue',
149 ],
150 ];
151
152 $this->assertSame($expected, $this->subject->addData($input));
153 }
154
155 /**
156 * @test
157 */
158 public function addDataSetsDefaultValueForChildRecordColumn()
159 {
160 $GLOBALS['TCA']['aTable']['columns']['aType'] = [];
161 $input = [
162 'inlineParentConfig' => [
163 'foreign_table' => 'aTable',
164 'foreign_record_defaults' => [
165 'aType' => '42',
166 ],
167 ],
168 'processedTca' => [
169 'columns' => [
170 'aType' => [
171 'config' => [],
172 ],
173 ],
174 ],
175 ];
176
177 $expected = $input;
178 $expected['processedTca']['columns']['aType']['config']['default'] = '42';
179
180 $this->assertSame($expected, $this->subject->addData($input));
181 }
182
183 /**
184 * @test
185 */
186 public function addDataIgnoresDefaultValueForRestrictedField()
187 {
188 $GLOBALS['TCA']['aTable']['columns']['pid'] = [];
189 $input = [
190 'inlineParentConfig' => [
191 'foreign_table' => 'aTable',
192 'foreign_record_defaults' => [
193 'pid' => '42',
194 ],
195 ],
196 'processedTca' => [
197 'columns' => [
198 'aType' => [
199 'config' => [],
200 ],
201 ],
202 ],
203 ];
204
205 $expected = $input;
206
207 $this->assertSame($expected, $this->subject->addData($input));
208 }
209 }