[BUGFIX] EXT:form tests and unicode fix
[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 * Copyright notice
6 *
7 * (c) 2012 Susanne Moog, <typo3@susannemoog.de>
8 *
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Testcase for PostProcessor
29 *
30 * @author Susanne Moog, <typo3@susannemoog.de>
31 * @package TYPO3
32 * @subpackage form
33 */
34 class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
35
36 /**
37 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Form\PostProcess\PostProcessor
38 */
39 public $fixture;
40
41 /**
42 * Set up
43 */
44 public function setUp() {
45 $form = $this->getMock('TYPO3\\CMS\\Form\\Domain\\Model\\Form', array(), array(), '', FALSE);
46 $this->fixture = $this->getMock(
47 'TYPO3\CMS\Form\PostProcess\PostProcessor',
48 array('sortTypoScriptKeyList'),
49 array($form, array())
50 );
51 }
52
53 /**
54 * @test
55 */
56 public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
57 $classNameWithoutPrefix = uniqid('postprocess');
58 eval(
59 'namespace TYPO3\CMS\Form\PostProcess;' .
60 'class ' . $classNameWithoutPrefix . 'PostProcessor implements PostProcessorInterface {' .
61 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
62 ' }' .
63 ' public function process() {' .
64 ' return \'processedWithoutPrefix\';' .
65 ' }' .
66 '}'
67 );
68 $typoScript = array(
69 10 => uniqid('postprocess'),
70 20 => $classNameWithoutPrefix
71 );
72 $this->fixture->typoScript = $typoScript;
73 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
74 $returnValue = $this->fixture->process();
75 $this->assertEquals('processedWithoutPrefix', $returnValue);
76 }
77
78 /**
79 * @test
80 */
81 public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
82 $classNameWithPrefix = uniqid('postprocess');
83 eval(
84 'namespace TYPO3\CMS\Form\PostProcess;' .
85 'class ' . $classNameWithPrefix . 'PostProcessor implements PostProcessorInterface {' .
86 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
87 ' }' .
88 ' public function process() {' .
89 ' return \'processedWithPrefix\';' .
90 ' }' .
91 '}'
92 );
93 $typoScript = array(
94 10 => uniqid('postprocess'),
95 20 => $classNameWithPrefix
96 );
97 $this->fixture->typoScript = $typoScript;
98 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
99 $returnValue = $this->fixture->process();
100 $this->assertEquals('processedWithPrefix', $returnValue);
101 }
102
103 /**
104 * @test
105 */
106 public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
107 $classNameWithoutInterface = uniqid('postprocess');
108 eval(
109 'namespace TYPO3\CMS\Form\PostProcess;' .
110 'class ' . $classNameWithoutInterface . 'PostProcessor {' .
111 ' public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {' .
112 ' }' .
113 ' public function process() {' .
114 ' return \'withoutInterface\';' .
115 ' }' .
116 '}'
117 );
118 $typoScript = array(
119 10 => uniqid('postprocess'),
120 20 => $classNameWithoutInterface
121 );
122 $this->fixture->typoScript = $typoScript;
123 $this->fixture->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
124 $returnValue = $this->fixture->process();
125 $this->assertEquals('', $returnValue);
126 }
127
128 }
129
130
131 ?>