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