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