‪TYPO3CMS  11.5
FormEditorControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FormEditorControllerTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
39  public function ‪setUp(): void
40  {
41  parent::setUp();
42  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '12345';
43  }
44 
49  {
50  $mockTranslationService = $this->getAccessibleMock(TranslationService::class, ['translate'], [], '', false);
51  GeneralUtility::setSingletonInstance(TranslationService::class, $mockTranslationService);
52  $mockTranslationService
53  ->method('translate')
54  ->willReturnArgument(4);
55 
56  $subject = $this->getAccessibleMock(FormEditorController::class, ['dummy'], [], '', false);
57  $subject->_set('prototypeConfiguration', [
58  'formEditor' => [
59  'formElementGroups' => [
60  'input' => [
61  'label' => 'Basic elements',
62  ],
63  'select' => [
64  'label' => 'Select elements',
65  ],
66  ],
67  ],
68  ]);
69 
70  $input = [
71  'Password' => [
72  'group' => 'input',
73  'groupSorting' => 110,
74  'iconIdentifier' => 'form-password',
75  'label' => 'Password label',
76  ],
77  'Text' => [
78  'group' => 'input',
79  'groupSorting' => 100,
80  'iconIdentifier' => 'form-text',
81  'label' => 'Text label',
82  ],
83  'SingleSelect' => [
84  'group' => 'select',
85  'groupSorting' => 100,
86  'iconIdentifier' => 'form-single-select',
87  'label' => 'Single select label',
88  ],
89  ];
90 
91  $expected = [
92  0 => [
93  'key' => 'input',
94  'elements' => [
95  0 => [
96  'key' => 'Text',
97  'cssKey' => 'text',
98  'label' => 'Text label',
99  'sorting' => 100,
100  'iconIdentifier' => 'form-text',
101  ],
102  1 => [
103  'key' => 'Password',
104  'cssKey' => 'password',
105  'label' => 'Password label',
106  'sorting' => 110,
107  'iconIdentifier' => 'form-password',
108  ],
109  ],
110  'label' => 'Basic elements',
111  ],
112  1 => [
113  'key' => 'select',
114  'elements' => [
115  0 => [
116  'key' => 'SingleSelect',
117  'cssKey' => 'singleselect',
118  'label' => 'Single select label',
119  'sorting' => 100,
120  'iconIdentifier' => 'form-single-select',
121  ],
122  ],
123  'label' => 'Select elements',
124  ],
125  ];
126 
127  self::assertSame($expected, $subject->_call('getInsertRenderablesPanelConfiguration', $input));
128  }
129 
134  {
135  $mockTranslationService = $this->getAccessibleMock(TranslationService::class, ['translateValuesRecursive'], [], '', false);
136  GeneralUtility::setSingletonInstance(TranslationService::class, $mockTranslationService);
137  $mockTranslationService
138  ->method('translateValuesRecursive')
139  ->willReturnArgument(0);
140 
141  $subject = $this->getAccessibleMock(FormEditorController::class, ['dummy'], [], '', false);
142  $subject->_set('prototypeConfiguration', [
143  'formEditor' => [
144  'someOtherValues' => [
145  'horst' => [
146  'key' => 'value',
147  ],
148  'gertrud' => [
149  'key' => 'value',
150  ],
151  ],
152  'formElementPropertyValidatorsDefinition' => [
153  'NotEmpty' => [
154  'key' => 'value',
155  ],
156  ],
157  ],
158  'formElementsDefinition' => [
159  'Form' => [
160  'formEditor' => [
161  'key' => 'value',
162  ],
163  'someOtherValues' => [
164  'horst' => [
165  'key' => 'value',
166  ],
167  'gertrud' => [
168  'key' => 'value',
169  ],
170  ],
171  ],
172  'Text' => [
173  'formEditor' => [
174  'key' => 'value',
175  ],
176  'someOtherValues' => [
177  'horst' => [
178  'key' => 'value',
179  ],
180  'gertrud' => [
181  'key' => 'value',
182  ],
183  ],
184  ],
185  ],
186  'finishersDefinition' => [
187  'Confirmation' => [
188  'formEditor' => [
189  'key' => 'value',
190  ],
191  'someOtherValues' => [
192  'horst' => [
193  'key' => 'value',
194  ],
195  'gertrud' => [
196  'key' => 'value',
197  ],
198  ],
199  ],
200  'EmailToSender' => [
201  'formEditor' => [
202  'key' => 'value',
203  ],
204  'someOtherValues' => [
205  'horst' => [
206  'key' => 'value',
207  ],
208  'gertrud' => [
209  'key' => 'value',
210  ],
211  ],
212  ],
213  ],
214  'someOtherValues' => [
215  'horst' => [
216  'key' => 'value',
217  ],
218  'gertrud' => [
219  'key' => 'value',
220  ],
221  ],
222  ]);
223 
224  $expected = [
225  'formElements' => [
226  'Form' => [
227  'key' => 'value',
228  ],
229  'Text' => [
230  'key' => 'value',
231  ],
232  ],
233  'finishers' => [
234  'Confirmation' => [
235  'key' => 'value',
236  ],
237  'EmailToSender' => [
238  'key' => 'value',
239  ],
240  ],
241  'formElementPropertyValidators' => [
242  'NotEmpty' => [
243  'key' => 'value',
244  ],
245  ],
246  ];
247 
248  self::assertSame($expected, $subject->_call('getFormEditorDefinitions'));
249  }
250 
255  {
256  $this->expectException(RenderingException::class);
257  $this->expectExceptionCode(1480294721);
258 
259  $mockController = $this->getAccessibleMock(FormEditorController::class, [
260  'dummy',
261  ], [], '', false);
262 
263  $mockController->_set('prototypeConfiguration', [
264  'formEditor' => [
265  'formEditorFluidConfiguration' => [
266  'templatePathAndFilename' => '',
267  ],
268  ],
269  ]);
270 
271  $mockController->_call('renderFormEditorTemplates', []);
272  }
273 
278  {
279  $this->expectException(RenderingException::class);
280  $this->expectExceptionCode(1480294721);
281 
282  $mockController = $this->getAccessibleMock(FormEditorController::class, [
283  'dummy',
284  ], [], '', false);
285 
286  $mockController->_set('prototypeConfiguration', [
287  'formEditor' => [
288  'formEditorFluidConfiguration' => [
289  'templatePathAndFilename' => '',
290  'layoutRootPaths' => '',
291  ],
292  ],
293  ]);
294 
295  $mockController->_call('renderFormEditorTemplates', []);
296  }
297 
302  {
303  $this->expectException(RenderingException::class);
304  $this->expectExceptionCode(1480294722);
305 
306  $mockController = $this->getAccessibleMock(FormEditorController::class, [
307  'dummy',
308  ], [], '', false);
309 
310  $mockController->_set('prototypeConfiguration', [
311  'formEditor' => [
312  'formEditorFluidConfiguration' => [
313  'templatePathAndFilename' => '',
314  'layoutRootPaths' => [],
315  ],
316  ],
317  ]);
318 
319  $mockController->_call('renderFormEditorTemplates', []);
320  }
321 
326  {
327  $this->expectException(RenderingException::class);
328  $this->expectExceptionCode(1480294722);
329 
330  $mockController = $this->getAccessibleMock(FormEditorController::class, [
331  'dummy',
332  ], [], '', false);
333 
334  $mockController->_set('prototypeConfiguration', [
335  'formEditor' => [
336  'formEditorFluidConfiguration' => [
337  'templatePathAndFilename' => '',
338  'layoutRootPaths' => [],
339  ],
340  ],
341  ]);
342 
343  $mockController->_call('renderFormEditorTemplates', []);
344  }
345 
350  {
351  $this->expectException(RenderingException::class);
352  $this->expectExceptionCode(1485636499);
353 
354  $mockController = $this->getAccessibleMock(FormEditorController::class, [
355  'dummy',
356  ], [], '', false);
357 
358  $mockController->_set('prototypeConfiguration', [
359  'formEditor' => [
360  'formEditorFluidConfiguration' => [],
361  ],
362  ]);
363 
364  $mockController->_call('renderFormEditorTemplates', []);
365  }
366 
371  {
372  $mockController = $this->getAccessibleMock(FormEditorController::class, [
373  'dummy',
374  ], [], '', false);
375 
376  $input = [
377  0 => [
378  'bar' => 'baz',
379  ],
380  1 => [
381  'type' => 'SOMEELEMENT',
382  'properties' => [
383  'options' => [
384  5 => '5',
385  4 => '4',
386  3 => '3',
387  2 => '2',
388  1 => '1',
389  ],
390  ],
391  ],
392  2 => [
393  0 => [
394  'type' => 'TEST',
395  'properties' => [
396  'options' => [
397  5 => '5',
398  4 => '4',
399  3 => '3',
400  2 => '2',
401  1 => '1',
402  ],
403  ],
404  ],
405  ],
406  ];
407 
408  $multiValueProperties = [
409  'TEST' => [
410  0 => 'properties.options',
411  ],
412  ];
413 
414  $expected = [
415  0 => [
416  'bar' => 'baz',
417  ],
418  1 => [
419  'type' => 'SOMEELEMENT',
420  'properties' => [
421  'options' => [
422  5 => '5',
423  4 => '4',
424  3 => '3',
425  2 => '2',
426  1 => '1',
427  ],
428  ],
429  ],
430  2 => [
431  0 => [
432  'type' => 'TEST',
433  'properties' => [
434  'options' => [
435  ['_label' => '5', '_value' => 5],
436  ['_label' => '4', '_value' => 4],
437  ['_label' => '3', '_value' => 3],
438  ['_label' => '2', '_value' => 2],
439  ['_label' => '1', '_value' => 1],
440  ],
441  ],
442  ],
443  ],
444  ];
445 
446  self::assertSame($expected, $mockController->_call('transformMultiValuePropertiesForFormEditor', $input, 'type', $multiValueProperties));
447  }
448 
452  public function ‪filterEmptyArraysRemovesEmptyArrayKeys(): void
453  {
454  $mockController = $this->getAccessibleMock(FormEditorController::class, [
455  'dummy',
456  ], [], '', false);
457 
458  $input = [
459  'heinz' => 1,
460  'klaus' => [],
461  'sabine' => [
462  'heinz' => '2',
463  'klaus' => [],
464  'horst' => [
465  'heinz' => '',
466  'paul' => [[]],
467  ],
468  ],
469  ];
470 
471  $expected = [
472  'heinz' => 1,
473  'sabine' => [
474  'heinz' => '2',
475  'horst' => [
476  'heinz' => '',
477  ],
478  ],
479  ];
480 
481  self::assertSame($expected, $mockController->_call('filterEmptyArrays', $input));
482  }
483 }
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest
Definition: FormEditorControllerTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\transformMultiValuePropertiesForFormEditorConvertMultiValueDataIntoMetaData
‪transformMultiValuePropertiesForFormEditorConvertMultiValueDataIntoMetaData()
Definition: FormEditorControllerTest.php:369
‪TYPO3\CMS\Form\Controller\FormEditorController
Definition: FormEditorController.php:55
‪TYPO3\CMS\Form\Service\TranslationService
Definition: TranslationService.php:45
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\renderFormEditorTemplatesThrowsExceptionIfTemplatePathAndFilenameNotSet
‪renderFormEditorTemplatesThrowsExceptionIfTemplatePathAndFilenameNotSet()
Definition: FormEditorControllerTest.php:348
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\getFormEditorDefinitionsReturnReducedConfiguration
‪getFormEditorDefinitionsReturnReducedConfiguration()
Definition: FormEditorControllerTest.php:132
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedConfiguration
‪getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedConfiguration()
Definition: FormEditorControllerTest.php:47
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormEditorControllerTest.php:33
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\filterEmptyArraysRemovesEmptyArrayKeys
‪filterEmptyArraysRemovesEmptyArrayKeys()
Definition: FormEditorControllerTest.php:451
‪TYPO3\CMS\Form\Tests\Unit\Controller
Definition: FormEditorControllerTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotSet
‪renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotSet()
Definition: FormEditorControllerTest.php:300
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:29
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotArray
‪renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotArray()
Definition: FormEditorControllerTest.php:276
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotArray
‪renderFormEditorTemplatesThrowsExceptionIfPartialRootPathsNotArray()
Definition: FormEditorControllerTest.php:324
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotSet
‪renderFormEditorTemplatesThrowsExceptionIfLayoutRootPathsNotSet()
Definition: FormEditorControllerTest.php:253
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormEditorControllerTest\setUp
‪setUp()
Definition: FormEditorControllerTest.php:38