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