‪TYPO3CMS  9.5
FormFrontendControllerTest.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 
17 use Prophecy\Argument;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪FormFrontendControllerTest extends UnitTestCase
33 {
34  public function ‪setUp()
35  {
36  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
37  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
38  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
39  $cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheFrontendProphecy->reveal());
40  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
41  $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
42  }
43 
44  public function ‪tearDown()
45  {
46  GeneralUtility::purgeInstances();
47  parent::tearDown();
48  }
49 
54  {
55  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
56  'dummy'
57  ], [], '', false);
58 
59  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
60 
61  $objectManagerMock = $this->createMock(ObjectManager::class);
62  $objectManagerMock
63  ->expects($this->any())
64  ->method('get')
65  ->with(ConfigurationService::class)
66  ->willReturn($configurationServiceProphecy->reveal());
67 
68  $sheetIdentifier = md5(
69  implode('', [
70  '1:/foo',
71  'standard',
72  'ext-form-identifier',
73  'EmailToReceiver'
74  ])
75  );
76 
77  $flexFormTools = new ‪FlexFormTools;
78  $contentObject = new \stdClass();
79  $contentObject->data = [
80  'pi_flexform' => $flexFormTools->flexArray2Xml([
81  'data' => [
82  $sheetIdentifier => [
83  'lDEF' => [
84  'settings.finishers.EmailToReceiver.subject' => ['vDEF' => 'Mesage Subject overridden'],
85  'settings.finishers.EmailToReceiver.recipientAddress' => ['vDEF' => 'your.company@example.com overridden'],
86  'settings.finishers.EmailToReceiver.format' => ['vDEF' => 'html overridden'],
87  ],
88  ],
89  ],
90  ]),
91  ];
92 
93  $frontendConfigurationManager = $this->createMock(FrontendConfigurationManager::class);
94  $frontendConfigurationManager
95  ->expects($this->any())
96  ->method('getContentObject')
97  ->willReturn($contentObject);
98 
99  $mockController->_set('configurationManager', $frontendConfigurationManager);
100  $mockController->_set('objectManager', $objectManagerMock);
101 
102  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
103  'finishersDefinition' => [
104  'EmailToReceiver' => [
105  'FormEngine' => [
106  'elements' => [
107  'subject' => [],
108  'recipientAddress' => [],
109  'format' => [],
110  ],
111  ],
112  ],
113  ],
114  ]);
115 
116  $mockController->_set('settings', [
117  'overrideFinishers' => 0,
118  ]);
119 
120  $input = [
121  'identifier' => 'ext-form-identifier',
122  'persistenceIdentifier' => '1:/foo',
123  'prototypeName' => 'standard',
124  'finishers' => [
125  0 => [
126  'identifier' => 'EmailToReceiver',
127  'options' => [
128  'subject' => 'Mesage Subject',
129  'recipientAddress' => 'your.company@example.com',
130  'format' => 'html',
131  ],
132  ],
133  ],
134  ];
135 
136  $expected = [
137  'identifier' => 'ext-form-identifier',
138  'persistenceIdentifier' => '1:/foo',
139  'prototypeName' => 'standard',
140  'finishers' => [
141  0 => [
142  'identifier' => 'EmailToReceiver',
143  'options' => [
144  'subject' => 'Mesage Subject',
145  'recipientAddress' => 'your.company@example.com',
146  'format' => 'html',
147  ],
148  ],
149  ],
150  ];
151 
152  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
153  }
154 
159  {
160  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
161  'dummy'
162  ], [], '', false);
163 
164  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
165 
166  $objectManagerMock = $this->createMock(ObjectManager::class);
167  $objectManagerMock
168  ->expects($this->any())
169  ->method('get')
170  ->with(ConfigurationService::class)
171  ->willReturn($configurationServiceProphecy->reveal());
172 
173  $sheetIdentifier = md5(
174  implode('', [
175  '1:/foo',
176  'standard',
177  'ext-form-identifier',
178  'EmailToReceiver'
179  ])
180  );
181 
182  $flexFormTools = new ‪FlexFormTools;
183  $contentObject = new \stdClass();
184  $contentObject->data = [
185  'pi_flexform' => $flexFormTools->flexArray2Xml([
186  'data' => [
187  $sheetIdentifier => [
188  'lDEF' => [
189  'settings.finishers.EmailToReceiver.subject' => ['vDEF' => 'Mesage Subject overridden'],
190  'settings.finishers.EmailToReceiver.recipientAddress' => ['vDEF' => 'your.company@example.com overridden'],
191  'settings.finishers.EmailToReceiver.format' => ['vDEF' => 'html overridden'],
192  ],
193  ],
194  ],
195  ]),
196  ];
197 
198  $frontendConfigurationManager = $this->createMock(FrontendConfigurationManager::class);
199  $frontendConfigurationManager
200  ->expects($this->any())
201  ->method('getContentObject')
202  ->willReturn($contentObject);
203 
204  $mockController->_set('configurationManager', $frontendConfigurationManager);
205  $mockController->_set('objectManager', $objectManagerMock);
206 
207  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
208  'finishersDefinition' => [
209  'EmailToReceiver' => [
210  'FormEngine' => [
211  'elements' => [
212  'subject' => ['config' => ['type' => 'input']],
213  'recipientAddress' => ['config' => ['type' => 'input']],
214  'format' => ['config' => ['type' => 'input']],
215  ],
216  ],
217  ],
218  ],
219  ]);
220 
221  $mockController->_set('settings', [
222  'overrideFinishers' => 1,
223  ]);
224 
225  $input = [
226  'persistenceIdentifier' => '1:/foo',
227  'identifier' => 'ext-form-identifier',
228  'prototypeName' => 'standard',
229  'finishers' => [
230  0 => [
231  'identifier' => 'EmailToReceiver',
232  'options' => [
233  'subject' => 'Mesage Subject',
234  'recipientAddress' => 'your.company@example.com',
235  'format' => 'html',
236  ],
237  ],
238  ],
239  ];
240 
241  $expected = [
242  'persistenceIdentifier' => '1:/foo',
243  'identifier' => 'ext-form-identifier',
244  'prototypeName' => 'standard',
245  'finishers' => [
246  0 => [
247  'identifier' => 'EmailToReceiver',
248  'options' => [
249  'subject' => 'Mesage Subject overridden',
250  'recipientAddress' => 'your.company@example.com overridden',
251  'format' => 'html overridden',
252  ],
253  ],
254  ],
255  ];
256 
257  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
258  }
259 
264  {
265  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
266  'dummy'
267  ], [], '', false);
268 
269  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
270 
271  $objectManagerMock = $this->createMock(ObjectManager::class);
272  $objectManagerMock
273  ->expects($this->any())
274  ->method('get')
275  ->with(ConfigurationService::class)
276  ->willReturn($configurationServiceProphecy->reveal());
277 
278  $sheetIdentifier = md5(
279  implode('', [
280  '1:/foo',
281  'standard',
282  'ext-form-identifier',
283  'EmailToReceiver'
284  ])
285  );
286 
287  $flexFormTools = new ‪FlexFormTools;
288  $contentObject = new \stdClass();
289  $contentObject->data = [
290  'pi_flexform' => $flexFormTools->flexArray2Xml([
291  'data' => [
292  $sheetIdentifier => [
293  'lDEF' => [
294  'settings.finishers.EmailToReceiver.subject' => ['vDEF' => 'Mesage Subject overridden'],
295  'settings.finishers.EmailToReceiver.recipientAddress' => ['vDEF' => 'your.company@example.com overridden'],
296  'settings.finishers.EmailToReceiver.format' => ['vDEF' => 'html overridden'],
297  ],
298  ],
299  ],
300  ]),
301  ];
302 
303  $frontendConfigurationManager = $this->createMock(FrontendConfigurationManager::class);
304  $frontendConfigurationManager
305  ->expects($this->any())
306  ->method('getContentObject')
307  ->willReturn($contentObject);
308 
309  $mockController->_set('configurationManager', $frontendConfigurationManager);
310  $mockController->_set('objectManager', $objectManagerMock);
311 
312  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
313  'finishersDefinition' => [
314  'EmailToReceiver' => [
315  'FormEngine' => [
316  'elements' => [
317  'subject' => ['config' => ['type' => 'input']],
318  'recipientAddress' => ['config' => ['type' => 'input']],
319  ],
320  ],
321  ],
322  ],
323  ]);
324 
325  $mockController->_set('settings', [
326  'overrideFinishers' => 1,
327  'finishers' => [
328  'EmailToReceiver' => [
329  'subject' => 'Mesage Subject overridden',
330  'recipientAddress' => 'your.company@example.com overridden',
331  'format' => 'html overridden',
332  ],
333  ],
334  ]);
335 
336  $input = [
337  'persistenceIdentifier' => '1:/foo',
338  'identifier' => 'ext-form-identifier',
339  'prototypeName' => 'standard',
340  'finishers' => [
341  0 => [
342  'identifier' => 'EmailToReceiver',
343  'options' => [
344  'subject' => 'Mesage Subject',
345  'recipientAddress' => 'your.company@example.com',
346  'format' => 'html',
347  ],
348  ],
349  ],
350  ];
351 
352  $expected = [
353  'persistenceIdentifier' => '1:/foo',
354  'identifier' => 'ext-form-identifier',
355  'prototypeName' => 'standard',
356  'finishers' => [
357  0 => [
358  'identifier' => 'EmailToReceiver',
359  'options' => [
360  'subject' => 'Mesage Subject overridden',
361  'recipientAddress' => 'your.company@example.com overridden',
362  'format' => 'html',
363  ],
364  ],
365  ],
366  ];
367 
368  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
369  }
370 
375  {
376  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
377  'dummy'
378  ], [], '', false);
379 
380  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
381 
382  $objectManagerMock = $this->createMock(ObjectManager::class);
383  $objectManagerMock
384  ->expects($this->any())
385  ->method('get')
386  ->with(ConfigurationService::class)
387  ->willReturn($configurationServiceProphecy->reveal());
388 
389  $sheetIdentifier = md5(
390  implode('', [
391  '1:/foo',
392  'standard',
393  'ext-form-identifier',
394  'EmailToReceiver'
395  ])
396  );
397 
398  $anotherSheetIdentifier = md5(
399  implode('', [
400  '1:/foobar',
401  'standard',
402  'another-ext-form-identifier',
403  'EmailToReceiver'
404  ])
405  );
406 
407  $flexFormTools = new ‪FlexFormTools;
408  $contentObject = new \stdClass();
409  $contentObject->data = [
410  'pi_flexform' => $flexFormTools->flexArray2Xml([
411  'data' => [
412  $sheetIdentifier => [
413  'lDEF' => [
414  'settings.finishers.EmailToReceiver.subject' => ['vDEF' => 'Mesage Subject overridden 1'],
415  'settings.finishers.EmailToReceiver.recipientAddress' => ['vDEF' => 'your.company@example.com overridden 1'],
416  'settings.finishers.EmailToReceiver.format' => ['vDEF' => 'html overridden 1'],
417  ],
418  ],
419  $anotherSheetIdentifier => [
420  'lDEF' => [
421  'settings.finishers.EmailToReceiver.subject' => ['vDEF' => 'Mesage Subject overridden 2'],
422  'settings.finishers.EmailToReceiver.recipientAddress' => ['vDEF' => 'your.company@example.com overridden 2'],
423  'settings.finishers.EmailToReceiver.format' => ['vDEF' => 'html overridden 2'],
424  ],
425  ],
426  ],
427  ]),
428  ];
429 
430  $frontendConfigurationManager = $this->createMock(FrontendConfigurationManager::class);
431  $frontendConfigurationManager
432  ->expects($this->any())
433  ->method('getContentObject')
434  ->willReturn($contentObject);
435 
436  $mockController->_set('configurationManager', $frontendConfigurationManager);
437  $mockController->_set('objectManager', $objectManagerMock);
438 
439  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
440  'finishersDefinition' => [
441  'EmailToReceiver' => [
442  'FormEngine' => [
443  'elements' => [
444  'subject' => ['config' => ['type' => 'input']],
445  'recipientAddress' => ['config' => ['type' => 'input']],
446  'format' => ['config' => ['type' => 'input']],
447  ],
448  ],
449  ],
450  ],
451  ]);
452 
453  $mockController->_set('settings', [
454  'overrideFinishers' => 1,
455  ]);
456 
457  $input = [
458  'persistenceIdentifier' => '1:/foo',
459  'identifier' => 'ext-form-identifier',
460  'prototypeName' => 'standard',
461  'finishers' => [
462  0 => [
463  'identifier' => 'EmailToReceiver',
464  'options' => [
465  'subject' => 'Mesage Subject',
466  'recipientAddress' => 'your.company@example.com',
467  'format' => 'html',
468  ],
469  ],
470  ],
471  ];
472 
473  $expected = [
474  'persistenceIdentifier' => '1:/foo',
475  'identifier' => 'ext-form-identifier',
476  'prototypeName' => 'standard',
477  'finishers' => [
478  0 => [
479  'identifier' => 'EmailToReceiver',
480  'options' => [
481  'subject' => 'Mesage Subject overridden 1',
482  'recipientAddress' => 'your.company@example.com overridden 1',
483  'format' => 'html overridden 1',
484  ],
485  ],
486  ],
487  ];
488 
489  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
490  }
491 
496  {
497  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
498  'dummy'
499  ], [], '', false);
500 
501  $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
502 
503  $objectManagerMock = $this->createMock(ObjectManager::class);
504  $objectManagerMock
505  ->expects($this->any())
506  ->method('get')
507  ->with(TypoScriptService::class)
508  ->willReturn($typoScriptServiceProphecy->reveal());
509 
510  $mockController->_set('objectManager', $objectManagerMock);
511 
512  $typoScriptServiceProphecy
513  ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
514  ->willReturnArgument(0);
515 
516  $mockController->_set('settings', [
517  'formDefinitionOverrides' => [
518  ],
519  ]);
520 
521  $input = [
522  'identifier' => 'ext-form-identifier',
523  'prototypeName' => 'standard',
524  'label' => 'Label',
525  'renderables' => [
526  0 => [
527  'identifier' => 'page-1',
528  'type' => 'Page',
529  'label' => 'Label',
530  'renderables' => [
531  0 => [
532  'identifier' => 'text-1',
533  'type' => 'Text',
534  'label' => 'Label',
535  ],
536  ],
537  ],
538  ],
539  ];
540 
541  $expected = [
542  'identifier' => 'ext-form-identifier',
543  'prototypeName' => 'standard',
544  'label' => 'Label',
545  'renderables' => [
546  0 => [
547  'identifier' => 'page-1',
548  'type' => 'Page',
549  'label' => 'Label',
550  'renderables' => [
551  0 => [
552  'identifier' => 'text-1',
553  'type' => 'Text',
554  'label' => 'Label',
555  ],
556  ],
557  ],
558  ],
559  ];
560 
561  $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
562  }
563 
568  {
569  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
570  'dummy'
571  ], [], '', false);
572 
573  $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
574 
575  $objectManagerMock = $this->createMock(ObjectManager::class);
576  $objectManagerMock
577  ->expects($this->any())
578  ->method('get')
579  ->with(TypoScriptService::class)
580  ->willReturn($typoScriptServiceProphecy->reveal());
581 
582  $mockController->_set('objectManager', $objectManagerMock);
583 
584  $typoScriptServiceProphecy
585  ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
586  ->willReturnArgument(0);
587 
588  $mockController->_set('settings', [
589  'formDefinitionOverrides' => [
590  'ext-form-identifier' => [
591  'label' => 'Label override',
592  'renderables' => [
593  0 => [
594  'renderables' => [
595  0 => [
596  'label' => 'Label override',
597  ],
598  ],
599  ],
600  ],
601  ],
602  ],
603  ]);
604 
605  $input = [
606  'identifier' => 'ext-form-identifier',
607  'prototypeName' => 'standard',
608  'label' => 'Label',
609  'renderables' => [
610  0 => [
611  'identifier' => 'page-1',
612  'type' => 'Page',
613  'label' => 'Label',
614  'renderables' => [
615  0 => [
616  'identifier' => 'text-1',
617  'type' => 'Text',
618  'label' => 'Label',
619  ],
620  ],
621  ],
622  ],
623  ];
624 
625  $expected = [
626  'identifier' => 'ext-form-identifier',
627  'prototypeName' => 'standard',
628  'label' => 'Label override',
629  'renderables' => [
630  0 => [
631  'identifier' => 'page-1',
632  'type' => 'Page',
633  'label' => 'Label',
634  'renderables' => [
635  0 => [
636  'identifier' => 'text-1',
637  'type' => 'Text',
638  'label' => 'Label override',
639  ],
640  ],
641  ],
642  ],
643  ];
644 
645  $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
646  }
647 }
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\setUp
‪setUp()
Definition: FormFrontendControllerTest.php:34
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByFlexFormSettingsReturnsNotOverriddenConfigurationKeyIfFlexformOverridesAreNotRepresentedInFormEngineConfiguration
‪overrideByFlexFormSettingsReturnsNotOverriddenConfigurationKeyIfFlexformOverridesAreNotRepresentedInFormEngineConfiguration()
Definition: FormFrontendControllerTest.php:263
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByTypoScriptSettingsReturnsOverriddenConfigurationIfTypoScriptOverridesExists
‪overrideByTypoScriptSettingsReturnsOverriddenConfigurationIfTypoScriptOverridesExists()
Definition: FormFrontendControllerTest.php:567
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
Definition: FrontendConfigurationManager.php:27
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByFlexFormSettingsReturnsOverriddenConfigurationWhileMultipleSheetsExists
‪overrideByFlexFormSettingsReturnsOverriddenConfigurationWhileMultipleSheetsExists()
Definition: FormFrontendControllerTest.php:374
‪TYPO3\CMS\Form\Controller\FormFrontendController
Definition: FormFrontendController.php:37
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByTypoScriptSettingsReturnsNotOverriddenConfigurationIfNoTypoScriptOverridesExists
‪overrideByTypoScriptSettingsReturnsNotOverriddenConfigurationIfNoTypoScriptOverridesExists()
Definition: FormFrontendControllerTest.php:495
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:36
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\tearDown
‪tearDown()
Definition: FormFrontendControllerTest.php:44
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByFlexFormSettingsReturnsOverriddenConfigurationIfFlexformOverridesEnabled
‪overrideByFlexFormSettingsReturnsOverriddenConfigurationIfFlexformOverridesEnabled()
Definition: FormFrontendControllerTest.php:158
‪TYPO3\CMS\Form\Tests\Unit\Controller
Definition: AbstractBackendControllerTest.php:2
‪TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService
Definition: TypoScriptService.php:26
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService
Definition: ConfigurationService.php:49
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest\overrideByFlexFormSettingsReturnsNoOverriddenConfigurationIfFlexformOverridesDisabled
‪overrideByFlexFormSettingsReturnsNoOverriddenConfigurationIfFlexformOverridesDisabled()
Definition: FormFrontendControllerTest.php:53
‪TYPO3\CMS\Form\Tests\Unit\Controller\FormFrontendControllerTest
Definition: FormFrontendControllerTest.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25