[BUGFIX] EXT:form - handle boolean finisher options
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Controller / FormEditorControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Controller;
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\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Object\ObjectManager;
19 use TYPO3\CMS\Form\Controller\FormEditorController;
20 use TYPO3\CMS\Form\Domain\Exception\RenderingException;
21 use TYPO3\CMS\Form\Service\TranslationService;
22
23 /**
24 * Test case
25 */
26 class FormEditorControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28
29 /**
30 * @var array A backup of registered singleton instances
31 */
32 protected $singletonInstances = [];
33
34 /**
35 * Set up
36 */
37 public function setUp()
38 {
39 $this->singletonInstances = GeneralUtility::getSingletonInstances();
40 }
41
42 /**
43 * Tear down
44 */
45 public function tearDown()
46 {
47 GeneralUtility::resetSingletonInstances($this->singletonInstances);
48 parent::tearDown();
49 }
50
51 /**
52 * @test
53 */
54 public function getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedConfiguration()
55 {
56 $mockController = $this->getAccessibleMock(FormEditorController::class, [
57 'dummy'
58 ], [], '', false);
59
60 $objectMangerProphecy = $this->prophesize(ObjectManager::class);
61 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
62
63 $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [
64 'translate'
65 ], [], '', false);
66
67 $mockTranslationService
68 ->expects($this->any())
69 ->method('translate')
70 ->willReturnArgument(4);
71
72 $objectMangerProphecy
73 ->get(TranslationService::class)
74 ->willReturn($mockTranslationService);
75
76 $mockController->_set('prototypeConfiguration', [
77 'formEditor' => [
78 'formElementGroups' => [
79 'input' => [
80 'label' => 'Basic elements',
81 ],
82 'select' => [
83 'label' => 'Select elements',
84 ],
85 ],
86 ],
87 ]);
88
89 $input = [
90 'Password' => [
91 'group' => 'input',
92 'groupSorting' => 110,
93 'iconIdentifier' => 't3-form-icon-password',
94 'label' => 'Password label',
95 ],
96 'Text' => [
97 'group' => 'input',
98 'groupSorting' => 100,
99 'iconIdentifier' => 't3-form-icon-text',
100 'label' => 'Text label',
101 ],
102 'SingleSelect' => [
103 'group' => 'select',
104 'groupSorting' => 100,
105 'iconIdentifier' => 't3-form-icon-single-select',
106 'label' => 'Single select label',
107 ],
108 ];
109
110 $expected = [
111 0 => [
112 'key' => 'input',
113 'elements' => [
114 0 => [
115 'key' => 'Text',
116 'cssKey' => 'text',
117 'label' => 'Text label',
118 'sorting' => 100,
119 'iconIdentifier' => 't3-form-icon-text',
120 ],
121 1 => [
122 'key' => 'Password',
123 'cssKey' => 'password',
124 'label' => 'Password label',
125 'sorting' => 110,
126 'iconIdentifier' => 't3-form-icon-password',
127 ],
128 ],
129 'label' => 'Basic elements',
130 ],
131 1 => [
132 'key' => 'select',
133 'elements' => [
134 0 => [
135 'key' => 'SingleSelect',
136 'cssKey' => 'singleselect',
137 'label' => 'Single select label',
138 'sorting' => 100,
139 'iconIdentifier' => 't3-form-icon-single-select',
140 ],
141 ],
142 'label' => 'Select elements',
143 ],
144 ];
145
146 $this->assertSame($expected, $mockController->_call('getInsertRenderablesPanelConfiguration', $input));
147 }
148
149 /**
150 * @test
151 */
152 public function getFormEditorDefinitionsReturnReducedConfiguration()
153 {
154 $mockController = $this->getAccessibleMock(FormEditorController::class, [
155 'dummy'
156 ], [], '', false);
157
158 $objectMangerProphecy = $this->prophesize(ObjectManager::class);
159 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
160
161 $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [
162 'translateValuesRecursive'
163 ], [], '', false);
164
165 $mockTranslationService
166 ->expects($this->any())
167 ->method('translateValuesRecursive')
168 ->willReturnArgument(0);
169
170 $objectMangerProphecy
171 ->get(TranslationService::class)
172 ->willReturn($mockTranslationService);
173
174 $mockController->_set('prototypeConfiguration', [
175 'formEditor' => [
176 'someOtherValues' => [
177 'horst' => [
178 'key' => 'value',
179 ],
180 'gertrud' => [
181 'key' => 'value',
182 ],
183 ],
184 'formElementPropertyValidatorsDefinition' => [
185 'NotEmpty' => [
186 'key' => 'value',
187 ],
188 ],
189 ],
190 'formElementsDefinition' => [
191 'Form' => [
192 'formEditor' => [
193 'key' => 'value',
194 ],
195 'someOtherValues' => [
196 'horst' => [
197 'key' => 'value',
198 ],
199 'gertrud' => [
200 'key' => 'value',
201 ],
202 ],
203 ],
204 'Text' => [
205 'formEditor' => [
206 'key' => 'value',
207 ],
208 'someOtherValues' => [
209 'horst' => [
210 'key' => 'value',
211 ],
212 'gertrud' => [
213 'key' => 'value',
214 ],
215 ],
216 ],
217 ],
218 'finishersDefinition' => [
219 'Confirmation' => [
220 'formEditor' => [
221 'key' => 'value',
222 ],
223 'someOtherValues' => [
224 'horst' => [
225 'key' => 'value',
226 ],
227 'gertrud' => [
228 'key' => 'value',
229 ],
230 ],
231 ],
232 'EmailToSender' => [
233 'formEditor' => [
234 'key' => 'value',
235 ],
236 'someOtherValues' => [
237 'horst' => [
238 'key' => 'value',
239 ],
240 'gertrud' => [
241 'key' => 'value',
242 ],
243 ],
244 ],
245 ],
246 'someOtherValues' => [
247 'horst' => [
248 'key' => 'value',
249 ],
250 'gertrud' => [
251 'key' => 'value',
252 ],
253 ],
254 ]);
255
256 $expected = [
257 'formElements' => [
258 'Form' => [
259 'key' => 'value',
260 ],
261 'Text' => [
262 'key' => 'value',
263 ],
264 ],
265 'finishers' => [
266 'Confirmation' => [
267 'key' => 'value',
268 ],
269 'EmailToSender' => [
270 'key' => 'value',
271 ],
272 ],
273 'formElementPropertyValidators' => [
274 'NotEmpty' => [
275 'key' => 'value',
276 ],
277 ],
278 ];
279
280 $this->assertSame($expected, $mockController->_call('getFormEditorDefinitions'));
281 }
282
283 /**
284 * @test
285 */
286 public function renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotSet()
287 {
288 $this->expectException(RenderingException::class);
289 $this->expectExceptionCode(1480294721);
290
291 $mockController = $this->getAccessibleMock(FormEditorController::class, [
292 'dummy'
293 ], [], '', false);
294
295 $mockController->_set('prototypeConfiguration', [
296 'formEditor' => [
297 'formEditorFluidConfiguration' => [
298 'templatePathAndFilename' => '',
299 ],
300 ],
301 ]);
302
303 $mockController->_call('renderFormEditorTemplates', []);
304 }
305
306 /**
307 * @test
308 */
309 public function renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotArray()
310 {
311 $this->expectException(RenderingException::class);
312 $this->expectExceptionCode(1480294721);
313
314 $mockController = $this->getAccessibleMock(FormEditorController::class, [
315 'dummy'
316 ], [], '', false);
317
318 $mockController->_set('prototypeConfiguration', [
319 'formEditor' => [
320 'formEditorFluidConfiguration' => [
321 'templatePathAndFilename' => '',
322 'layoutRootPaths' => '',
323 ],
324 ],
325 ]);
326
327 $mockController->_call('renderFormEditorTemplates', []);
328 }
329
330 /**
331 * @test
332 */
333 public function renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotSet()
334 {
335 $this->expectException(RenderingException::class);
336 $this->expectExceptionCode(1480294722);
337
338 $mockController = $this->getAccessibleMock(FormEditorController::class, [
339 'dummy'
340 ], [], '', false);
341
342 $mockController->_set('prototypeConfiguration', [
343 'formEditor' => [
344 'formEditorFluidConfiguration' => [
345 'templatePathAndFilename' => '',
346 'layoutRootPaths' => [],
347 ],
348 ],
349 ]);
350
351 $mockController->_call('renderFormEditorTemplates', []);
352 }
353
354 /**
355 * @test
356 */
357 public function renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotArray()
358 {
359 $this->expectException(RenderingException::class);
360 $this->expectExceptionCode(1480294722);
361
362 $mockController = $this->getAccessibleMock(FormEditorController::class, [
363 'dummy'
364 ], [], '', false);
365
366 $mockController->_set('prototypeConfiguration', [
367 'formEditor' => [
368 'formEditorFluidConfiguration' => [
369 'templatePathAndFilename' => '',
370 'layoutRootPaths' => [],
371 ],
372 ],
373 ]);
374
375 $mockController->_call('renderFormEditorTemplates', []);
376 }
377
378 /**
379 * @test
380 */
381 public function renderFormEditorTemplatesThrowsExceptionIftemplatePathAndFilenameNotSet()
382 {
383 $this->expectException(RenderingException::class);
384 $this->expectExceptionCode(1485636499);
385
386 $mockController = $this->getAccessibleMock(FormEditorController::class, [
387 'dummy'
388 ], [], '', false);
389
390 $mockController->_set('prototypeConfiguration', [
391 'formEditor' => [
392 'formEditorFluidConfiguration' => [],
393 ],
394 ]);
395
396 $mockController->_call('renderFormEditorTemplates', []);
397 }
398 }