[TASK] Use name-resolution instead of strings where possible: 5
[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 * Testcase for PostProcessor
18 */
19 class PostProcessorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
20
21 /**
22 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Form\PostProcess\PostProcessor
23 */
24 public $fixture;
25
26 /**
27 * Set up
28 */
29 public function setUp() {
30 $form = $this->getMock(\TYPO3\CMS\Form\Domain\Model\Form::class, array(), array(), '', FALSE);
31 $this->fixture = $this->getMock(
32 \TYPO3\CMS\Form\PostProcess\PostProcessor::class,
33 array('sortTypoScriptKeyList'),
34 array($form, array())
35 );
36 }
37
38 /**
39 * @test
40 */
41 public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
42 $classNameWithoutPrefix = uniqid('postprocess');
43 eval(
44 'namespace TYPO3\CMS\Form\PostProcess;' .
45 'class ' . $classNameWithoutPrefix . 'PostProcessor implements PostProcessorInterface {' .
46 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
47 ' }' .
48 ' public function process() {' .
49 ' return \'processedWithoutPrefix\';' .
50 ' }' .
51 '}'
52 );
53 $typoScript = array(
54 10 => uniqid('postprocess'),
55 20 => $classNameWithoutPrefix
56 );
57 $this->fixture->typoScript = $typoScript;
58 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
59 $returnValue = $this->fixture->process();
60 $this->assertEquals('processedWithoutPrefix', $returnValue);
61 }
62
63 /**
64 * @test
65 */
66 public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
67 $classNameWithPrefix = uniqid('postprocess');
68 eval(
69 'namespace TYPO3\CMS\Form\PostProcess;' .
70 'class ' . $classNameWithPrefix . 'PostProcessor implements PostProcessorInterface {' .
71 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
72 ' }' .
73 ' public function process() {' .
74 ' return \'processedWithPrefix\';' .
75 ' }' .
76 '}'
77 );
78 $typoScript = array(
79 10 => uniqid('postprocess'),
80 20 => $classNameWithPrefix
81 );
82 $this->fixture->typoScript = $typoScript;
83 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
84 $returnValue = $this->fixture->process();
85 $this->assertEquals('processedWithPrefix', $returnValue);
86 }
87
88 /**
89 * @test
90 */
91 public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
92 $classNameWithoutInterface = uniqid('postprocess');
93 eval(
94 'namespace TYPO3\CMS\Form\PostProcess;' .
95 'class ' . $classNameWithoutInterface . 'PostProcessor {' .
96 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
97 ' }' .
98 ' public function process() {' .
99 ' return \'withoutInterface\';' .
100 ' }' .
101 '}'
102 );
103 $typoScript = array(
104 10 => uniqid('postprocess'),
105 20 => $classNameWithoutInterface
106 );
107 $this->fixture->typoScript = $typoScript;
108 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
109 $returnValue = $this->fixture->process();
110 $this->assertEquals('', $returnValue);
111 }
112
113 }