[TASK] Refactor PostProcessorTest to use Prophecy
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / PostProcess / PostProcessorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\PostProcess;
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;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
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
25 /**
26 * Testcase for PostProcessor
27 */
28 class PostProcessorTest extends UnitTestCase {
29
30 /**
31 * @var array A backup of registered singleton instances
32 */
33 protected $singletonInstances = array();
34
35 /**
36 * @var Form
37 */
38 protected $formProphecy;
39
40 /**
41 * @var Layout
42 */
43 protected $typoScriptLayoutProphecy;
44
45 /**
46 * @var TypoScriptFactory
47 */
48 protected $typoScriptFactoryProphecy;
49
50 /**
51 * Set up
52 */
53 protected function setUp() {
54 $this->singletonInstances = GeneralUtility::getSingletonInstances();
55
56 $this->formProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Domain\\Model\\Form');
57
58 $this->typoScriptFactoryProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
59 $this->typoScriptFactoryProphecy->getLayoutFromTypoScript(Argument::any())->willReturn(array());
60 GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory', $this->typoScriptFactoryProphecy->reveal());
61
62 $this->typoScriptLayoutProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Layout');
63
64 $templateServiceProphecy = $this->prophesize('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
65 $templateServiceProphecy->sortedKeyList(Argument::any())->willReturn(array(10, 20));
66 GeneralUtility::addInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', $templateServiceProphecy->reveal());
67 }
68
69 /**
70 * Tear down the tests
71 */
72 protected function tearDown() {
73 GeneralUtility::resetSingletonInstances($this->singletonInstances);
74 parent::tearDown();
75 }
76
77 /**
78 * @test
79 */
80 public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
81 $typoScript = array(
82 10 => $this->getUniqueId('postprocess'),
83 20 => 'TYPO3\\CMS\\Form\\Tests\\Unit\\Fixtures\\PostProcessorWithoutFormPrefixFixture'
84 );
85
86 $subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
87 $this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
88
89 $this->assertEquals('processedWithoutPrefix', $subject->process());
90 }
91
92 /**
93 * @test
94 */
95 public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
96 $typoScript = array(
97 10 => $this->getUniqueId('postprocess'),
98 20 => 'TYPO3\\CMS\\Form\\Tests\\Unit\\Fixtures\\PostProcessorWithFormPrefixFixture'
99 );
100
101 $subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
102 $this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
103
104 $this->assertEquals('processedWithPrefix', $subject->process());
105 }
106
107 /**
108 * @test
109 */
110 public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
111 $typoScript = array(
112 10 => $this->getUniqueId('postprocess'),
113 20 => 'TYPO3\\CMS\\Form\\Tests\\Unit\\Fixtures\\PostProcessorWithoutInterfaceFixture'
114 );
115
116 $subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
117 $this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
118
119 $this->assertEquals('', $subject->process());
120 }
121 }