Commit b298745b authored by Anja Leichsenring's avatar Anja Leichsenring Committed by Oliver Hader
Browse files

[TASK] Refactor PostProcessorTest to use Prophecy

In order to get rid of the mocking of the system under test, the
tests of ext:form PostProcessorTest are refactored to use
Prophecy. This step precedes the addition of other tests for
the class.

Change-Id: I1a2e9c5305c070f291b549965360abcfb8a695d0
Resolves: #69407
Releases: master
Reviewed-on: http://review.typo3.org/42921


Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent 84f5e339
......@@ -55,7 +55,7 @@ class PostProcessor {
public function process() {
$html = '';
if (is_array($this->typoScript)) {
$keys = $this->sortTypoScriptKeyList();
$keys = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($this->typoScript);
$layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoScript);
foreach ($keys as $key) {
......@@ -90,14 +90,4 @@ class PostProcessor {
return $html;
}
/**
* Wrapper method for \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList
* (makes unit testing possible)
*
* @return array
*/
public function sortTypoScriptKeyList() {
return \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($this->typoScript);
}
}
......@@ -13,41 +13,84 @@ namespace TYPO3\CMS\Form\Tests\Unit\PostProcess;
*
* The TYPO3 project - inspiring people to share!
*/
use Prophecy\Argument;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory;
use TYPO3\CMS\Form\Domain\Model\Form;
use TYPO3\CMS\Form\Layout;
use TYPO3\CMS\Form\PostProcess\PostProcessor;
use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithFormPrefixFixture;
use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutFormPrefixFixture;
use TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutInterfaceFixture;
/**
* Testcase for PostProcessor
*/
class PostProcessorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
class PostProcessorTest extends UnitTestCase {
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Form\PostProcess\PostProcessor
* @var array A backup of registered singleton instances
*/
public $subject;
protected $singletonInstances = array();
/**
* @var Form
*/
protected $formProphecy;
/**
* @var Layout
*/
protected $typoScriptLayoutProphecy;
/**
* @var TypoScriptFactory
*/
protected $typoScriptFactoryProphecy;
/**
* Set up
*/
protected function setUp() {
$form = $this->getMock(\TYPO3\CMS\Form\Domain\Model\Form::class, array(), array(), '', FALSE);
$this->subject = $this->getMock(
\TYPO3\CMS\Form\PostProcess\PostProcessor::class,
array('sortTypoScriptKeyList'),
array($form, array())
);
$this->singletonInstances = GeneralUtility::getSingletonInstances();
$this->formProphecy = $this->prophesize(Form::class);
$this->typoScriptFactoryProphecy = $this->prophesize(TypoScriptFactory::class);
$this->typoScriptFactoryProphecy->getLayoutFromTypoScript(Argument::any())->willReturn(array());
GeneralUtility::setSingletonInstance(TypoScriptFactory::class, $this->typoScriptFactoryProphecy->reveal());
$this->typoScriptLayoutProphecy = $this->prophesize(Layout::class);
$templateServiceProphecy = $this->prophesize(TemplateService::class);
$templateServiceProphecy->sortedKeyList(Argument::any())->willReturn(array(10, 20));
GeneralUtility::addInstance(TemplateService::class, $templateServiceProphecy->reveal());
}
/**
* Tear down the tests
*/
protected function tearDown() {
GeneralUtility::resetSingletonInstances($this->singletonInstances);
parent::tearDown();
}
/**
* @test
*/
public function processFindsClassSpecifiedByTypoScriptWithoutFormPrefix() {
$typoScript = array(
10 => $this->getUniqueId('postprocess'),
20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutFormPrefixFixture::class
20 => PostProcessorWithoutFormPrefixFixture::class
);
$this->subject->typoScript = $typoScript;
$this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
$returnValue = $this->subject->process();
$this->assertEquals('processedWithoutPrefix', $returnValue);
$subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
$this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
$this->assertEquals('processedWithoutPrefix', $subject->process());
}
/**
......@@ -56,12 +99,13 @@ class PostProcessorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
public function processFindsClassSpecifiedByTypoScriptWithFormPrefix() {
$typoScript = array(
10 => $this->getUniqueId('postprocess'),
20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithFormPrefixFixture::class
20 => PostProcessorWithFormPrefixFixture::class
);
$this->subject->typoScript = $typoScript;
$this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
$returnValue = $this->subject->process();
$this->assertEquals('processedWithPrefix', $returnValue);
$subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
$this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
$this->assertEquals('processedWithPrefix', $subject->process());
}
/**
......@@ -70,12 +114,12 @@ class PostProcessorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() {
$typoScript = array(
10 => $this->getUniqueId('postprocess'),
20 => \TYPO3\CMS\Form\Tests\Unit\Fixtures\PostProcessorWithoutInterfaceFixture::class
20 => PostProcessorWithoutInterfaceFixture::class
);
$this->subject->typoScript = $typoScript;
$this->subject->expects($this->once())->method('sortTypoScriptKeyList')->will($this->returnValue(array(10, 20)));
$returnValue = $this->subject->process();
$this->assertEquals('', $returnValue);
}
$subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
$this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
$this->assertEquals('', $subject->process());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment