TYPO3 CMS  TYPO3_6-2
PostProcessorTest.php
Go to the documentation of this file.
1 <?php
3 
24 
29 
33  protected $singletonInstances = array();
34 
38  protected $formProphecy;
39 
44 
49 
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 
72  protected function tearDown() {
73  GeneralUtility::resetSingletonInstances($this->singletonInstances);
74  parent::tearDown();
75  }
76 
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 
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 
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 
126  $processorConfig = array(
127  'recipientEmail' => 'your@email.com',
128  'senderEmail' => 'your@email.com',
129  );
130  $typoScript = array(
131  'layout.' => array(
132  'label' => '<div class="global"><labelvalue /></div>',
133  ),
134  '1' => 'foo', // something senseless on purpose, otherwise dependencies need to be resolved, that come in by static call -> ugly
135  '1.' => $processorConfig
136  );
137 
138  $subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
139  $this->typoScriptFactoryProphecy->setLayoutHandler($typoScript)->willReturn($this->typoScriptLayoutProphecy->reveal());
140 
141  $this->assertEquals('', $subject->process());
142  }
143 
147  public function processUsesLocalLayoutIfSet() {
148  $processorConfig = array(
149  'layout.' => array(
150  'label' => '<div class="local"><labelvalue /></div>',
151  ),
152  'recipientEmail' => 'your@email.com',
153  'senderEmail' => 'your@email.com',
154  );
155  $typoScript = array(
156  'layout.' => array(
157  'label' => '<div class="global"><labelvalue /></div>',
158  ),
159  '1' => 'foo',
160  '1.' => $processorConfig
161  );
162 
163  $subject = new PostProcessor($this->formProphecy->reveal(), $typoScript);
164  $this->typoScriptFactoryProphecy->setLayoutHandler($processorConfig)->willReturn($this->typoScriptLayoutProphecy->reveal());
165 
166  $this->assertEquals('', $subject->process());
167  }
168 }
$singletonInstances
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
tearDown()
processFindsClassSpecifiedByTypoScriptWithoutFormPrefix()
processFindsClassSpecifiedByTypoScriptWithFormPrefix()
static addInstance($className, $instance)
processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface()
static resetSingletonInstances(array $newSingletonInstances)
processUsesGlobalLayoutIfNoneIsSet()
$typoScriptLayoutProphecy
$typoScriptFactoryProphecy
$formProphecy
processUsesLocalLayoutIfSet()
setUp()