49900076516e660dabfa4f15874f438f1729af42
[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 /**
18 * Testcase for PostProcessor
19 */
20 class PostProcessorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Form\PostProcess\PostProcessor
24 */
25 public $subject;
26
27 /**
28 * Set up
29 */
30 protected function setUp() {
31 $form = $this->getMock(\TYPO3\CMS\Form\Domain\Model\Form::class, array(), array(), '', FALSE);
32 $this->subject = $this->getMock(
33 \TYPO3\CMS\Form\PostProcess\PostProcessor::class,
34 array('sortTypoScriptKeyList'),
35 array($form, array())
36 );
37 }
38
39 /**
40 * @test
41 */
42 public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
43 $typoScript = array(
44 10 => $this->getUniqueId('postprocess'),
45 20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutFormPrefixFixture::class
46 );
47 $this->subject->typoScript = $typoScript;
48 $this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
49 $returnValue = $this->subject->process();
50 $this->assertEquals('processedWithoutPrefix', $returnValue);
51 }
52
53 /**
54 * @test
55 */
56 public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
57 $typoScript = array(
58 10 => $this->getUniqueId('postprocess'),
59 20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithFormPrefixFixture::class
60 );
61 $this->subject->typoScript = $typoScript;
62 $this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
63 $returnValue = $this->subject->process();
64 $this->assertEquals('processedWithPrefix', $returnValue);
65 }
66
67 /**
68 * @test
69 */
70 public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
71 $typoScript = array(
72 10 => $this->getUniqueId('postprocess'),
73 20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutInterfaceFixture::class
74 );
75 $this->subject->typoScript = $typoScript;
76 $this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
77 $returnValue = $this->subject->process();
78 $this->assertEquals('', $returnValue);
79 }
80
81 }