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