2 namespace TYPO3\CMS\Form\Tests\Unit\PostProcess
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use Prophecy\Argument
;
17 use TYPO3\CMS\Core\Tests\UnitTestCase
;
18 use TYPO3\CMS\Core\TypoScript\TemplateService
;
19 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 use TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
;
21 use TYPO3\CMS\Form\Domain\Model\Form
;
22 use TYPO3\CMS\Form\Layout
;
23 use TYPO3\CMS\Form\PostProcess\PostProcessor
;
24 use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithFormPrefixFixture
;
25 use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutFormPrefixFixture
;
26 use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutInterfaceFixture
;
29 * Testcase for PostProcessor
31 class PostProcessorTest
extends UnitTestCase
{
34 * @var array A backup of registered singleton instances
36 protected $singletonInstances = array();
41 protected $formProphecy;
46 protected $typoScriptLayoutProphecy;
49 * @var TypoScriptFactory
51 protected $typoScriptFactoryProphecy;
56 protected function setUp() {
57 $this->singletonInstances
= GeneralUtility
::getSingletonInstances();
59 $this->formProphecy
= $this->prophesize(Form
::class);
61 $this->typoScriptFactoryProphecy
= $this->prophesize(TypoScriptFactory
::class);
62 $this->typoScriptFactoryProphecy
->getLayoutFromTypoScript(Argument
::any())->willReturn(array());
63 GeneralUtility
::setSingletonInstance(TypoScriptFactory
::class, $this->typoScriptFactoryProphecy
->reveal());
65 $this->typoScriptLayoutProphecy
= $this->prophesize(Layout
::class);
67 $templateServiceProphecy = $this->prophesize(TemplateService
::class);
68 $templateServiceProphecy->sortedKeyList(Argument
::any())->willReturn(array(10, 20));
69 GeneralUtility
::addInstance(TemplateService
::class, $templateServiceProphecy->reveal());
75 protected function tearDown() {
76 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
83 public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
86 10 => $this->getUniqueId('postprocess'),
87 20 => PostProcessorWithoutFormPrefixFixture
::class
90 $subject = new PostProcessor($this->formProphecy
->reveal(), $typoScript);
91 $this->typoScriptFactoryProphecy
->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy
->reveal());
93 $this->assertEquals('processedWithoutPrefix', $subject->process());
99 public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
101 10 => $this->getUniqueId('postprocess'),
102 20 => PostProcessorWithFormPrefixFixture
::class
105 $subject = new PostProcessor($this->formProphecy
->reveal(), $typoScript);
106 $this->typoScriptFactoryProphecy
->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy
->reveal());
108 $this->assertEquals('processedWithPrefix', $subject->process());
114 public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
116 10 => $this->getUniqueId('postprocess'),
117 20 => PostProcessorWithoutInterfaceFixture
::class
120 $subject = new PostProcessor($this->formProphecy
->reveal(), $typoScript);
121 $this->typoScriptFactoryProphecy
->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy
->reveal());
123 $this->assertEquals('', $subject->process());
129 public function processUsesGlobalLayoutIfNoneIsSet() {
130 $processorConfig = array(
131 'recipientEmail' => 'your@email.com',
132 'senderEmail' => 'your@email.com',
136 'label' => '<div class="global"><labelvalue /></div>',
138 '1' => 'foo', // something senseless on purpose, otherwise dependencies need to be resolved, that come in by static call -> ugly
139 '1.' => $processorConfig
142 $subject = new PostProcessor($this->formProphecy
->reveal(), $typoScript);
143 $this->typoScriptFactoryProphecy
->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy
->reveal());
145 $this->assertEquals('', $subject->process());
151 public function processUsesLocalLayoutIfSet() {
152 $processorConfig = array(
154 'label' => '<div class="local"><labelvalue /></div>',
156 'recipientEmail' => 'your@email.com',
157 'senderEmail' => 'your@email.com',
161 'label' => '<div class="global"><labelvalue /></div>',
164 '1.' => $processorConfig
167 $subject = new PostProcessor($this->formProphecy
->reveal(), $typoScript);
168 $this->typoScriptFactoryProphecy
->setLayoutHandler($processorConfig)->willReturn($this->typoScriptLayoutProphecy
->reveal());
170 $this->assertEquals('', $subject->process());