[TASK] Deprecate BackendUtility::getTCAtypes
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / UnitDeprecated / Utility / BackendUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\UnitDeprecated\Utility;
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\Tests\UnitDeprecated\Utility\Fixtures\BackendUtilityFixture;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Test case
24 */
25 class BackendUtilityTest extends UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNotSet()
31 {
32 $completeConfiguration = [
33 'value' => 'bar',
34 'properties' => [
35 'permissions.' => [
36 'file.' => [
37 'default.' => ['readAction' => '1'],
38 '1.' => ['writeAction' => '1'],
39 '0.' => ['readAction' => '0'],
40 ],
41 ]
42 ]
43 ];
44
45 $GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
46 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
47 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(['value' => null, 'properties' => null]));
48
49 $this->assertSame($completeConfiguration, BackendUtilityFixture::getModTSconfig(42, 'notrelevant'));
50 }
51
52 ///////////////////////////////////////
53 // Tests concerning getTCAtypes
54 ///////////////////////////////////////
55
56 /**
57 * @test
58 */
59 public function getTCAtypesReturnsCorrectValuesDataProvider()
60 {
61 return [
62 'no input' => [
63 '', // table
64 [], // rec
65 '', // useFieldNameAsKey
66 null // expected
67 ],
68 'non-existant table' => [
69 'fooBar', // table
70 [], // rec
71 '', // useFieldNameAsKey
72 null // expected
73 ],
74 'Doktype=1: one simple field' => [
75 'pages',
76 [
77 'uid' => '1',
78 'doktype' => '1'
79 ],
80 false,
81 [
82 0 => [
83 'field' => 'title',
84 'title' => null,
85 'palette' => null,
86 'spec' => [],
87 'origString' => 'title'
88 ]
89 ]
90 ],
91 'non-existant type given: Return for type 1' => [
92 'pages', // table
93 [
94 'uid' => '1',
95 'doktype' => '999'
96 ], // rec
97 '', // useFieldNameAsKey
98 [
99 0 => [
100 'field' => 'title',
101 'title' => null,
102 'palette' => null,
103 'spec' => [],
104 'origString' => 'title'
105 ]
106 ] // expected
107 ],
108 'Doktype=1: one simple field, useFieldNameAsKey=true' => [
109 'pages',
110 [
111 'uid' => '1',
112 'doktype' => '1'
113 ],
114 true,
115 [
116 'title' => [
117 'field' => 'title',
118 'title' => null,
119 'palette' => null,
120 'spec' => [],
121 'origString' => 'title'
122 ]
123 ]
124 ],
125 'Empty showitem Field' => [
126 'test',
127 [
128 'uid' => '1',
129 'fooBar' => '99'
130 ],
131 true,
132 [
133 '' => [
134 'field' => '',
135 'title' => null,
136 'palette' => null,
137 'spec' => [],
138 'origString' => ''
139 ]
140 ]
141 ],
142 'RTE field within a palette' => [
143 'pages',
144 [
145 'uid' => '1',
146 'doktype' => '10',
147 ],
148 false,
149 [
150 0 => [
151 'field' => '--div--',
152 'title' => 'General',
153 'palette' => null,
154 'spec' => [],
155 'origString' => '--div--;General'
156 ],
157 1 => [
158 'field' => '--palette--',
159 'title' => 'Palette',
160 'palette' => '123',
161 'spec' => [],
162 'origString' => '--palette--;Palette;123'
163 ],
164 2 => [
165 'field' => 'title',
166 'title' => null,
167 'palette' => null,
168 'spec' => [],
169 'origString' => 'title'
170 ],
171 3 => [
172 'field' => 'text',
173 'title' => null,
174 'palette' => null,
175 'spec' => [],
176 'origString' => 'text'
177 ],
178 4 => [
179 'field' => 'select',
180 'title' => 'Select field',
181 'palette' => null,
182 'spec' => [],
183 'origString' => 'select;Select field'
184 ]
185 ]
186 ],
187 'RTE field with more settings within a palette' => [
188 'pages',
189 [
190 'uid' => 1,
191 'doktype' => 2
192 ],
193 false,
194 [
195 0 => [
196 'field' => '--div--',
197 'title' => 'General',
198 'palette' => null,
199 'spec' => [],
200 'origString' => '--div--;General'
201 ],
202 1 => [
203 'field' => '--palette--',
204 'title' => 'RTE palette',
205 'palette' => '456',
206 'spec' => [],
207 'origString' => '--palette--;RTE palette;456'
208 ],
209 2 => [
210 'field' => 'text2',
211 'title' => null,
212 'palette' => null,
213 'spec' => [],
214 'origString' => 'text2'
215 ]
216 ]
217 ]
218 ];
219 }
220
221 /**
222 * @test
223 * @dataProvider getTCAtypesReturnsCorrectValuesDataProvider
224 *
225 * @param string $table
226 * @param array $rec
227 * @param bool $useFieldNameAsKey
228 * @param array $expected
229 */
230 public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
231 {
232 $GLOBALS['TCA'] = [
233 'pages' => [
234 'ctrl' => [
235 'type' => 'doktype'
236 ],
237 'columns' => [
238 'title' => [
239 'label' => 'Title test',
240 'config' => [
241 'type' => 'input'
242 ]
243 ],
244 'text' => [
245 'label' => 'RTE Text',
246 'config' => [
247 'type' => 'text',
248 'cols' => 40,
249 'rows' => 5
250 ],
251 ],
252 'text2' => [
253 'label' => 'RTE Text 2',
254 'config' => [
255 'type' => 'text',
256 'cols' => 40,
257 'rows' => 5
258 ],
259 ],
260 'select' => [
261 'label' => 'Select test',
262 'config' => [
263 'items' => [
264 ['Please select', 0],
265 ['Option 1', 1],
266 ['Option 2', 2]
267 ]
268 ],
269 'maxitems' => 1,
270 'renderType' => 'selectSingle'
271 ]
272 ],
273 'types' => [
274 '1' => [
275 'showitem' => 'title'
276 ],
277 '2' => [
278 'showitem' => '--div--;General,--palette--;RTE palette;456'
279 ],
280 '10' => [
281 'showitem' => '--div--;General,--palette--;Palette;123,title'
282 ],
283 '14' => [
284 'showitem' => '--div--;General,title'
285 ]
286 ],
287 'palettes' => [
288 '123' => [
289 'showitem' => 'text,select;Select field'
290 ],
291 '456' => [
292 'showitem' => 'text2'
293 ]
294 ]
295 ],
296 'test' => [
297 'ctrl' => [
298 'type' => 'fooBar'
299 ],
300 'types' => [
301 '99' => [ 'showitem' => '']
302 ]
303 ]
304 ];
305
306 $return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
307 $this->assertSame($expected, $return);
308 }
309 }