TYPO3 CMS  TYPO3_7-6
AbstractConditionViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 {
22  protected $viewHelper;
23 
27  protected $mockArguments;
28 
29  protected function setUp()
30  {
31  parent::setUp();
32  $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::class, ['getRenderingContext', 'renderChildren', 'hasArgument']);
33  $this->viewHelper->expects($this->any())->method('getRenderingContext')->will($this->returnValue($this->renderingContext));
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('foo'));
43 
44  $actualResult = $this->viewHelper->_call('renderThenChild');
45  $this->assertEquals('foo', $actualResult);
46  }
47 
52  {
53  $mockThenViewHelperNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['getViewHelperClassName', 'evaluate'], [], '', false);
54  $mockThenViewHelperNode->expects($this->at(0))->method('getViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\ThenViewHelper::class));
55  $mockThenViewHelperNode->expects($this->at(1))->method('evaluate')->with($this->renderingContext)->will($this->returnValue('ThenViewHelperResults'));
56 
57  $this->viewHelper->setChildNodes([$mockThenViewHelperNode]);
58  $actualResult = $this->viewHelper->_call('renderThenChild');
59  $this->assertEquals('ThenViewHelperResults', $actualResult);
60  }
61 
66  {
67  $actualResult = $this->viewHelper->_call('renderElseChild');
68  $this->assertEquals('', $actualResult);
69  }
70 
75  {
76  $mockElseViewHelperNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['getViewHelperClassName', 'evaluate', 'setRenderingContext'], [], '', false);
77  $mockElseViewHelperNode->expects($this->at(0))->method('getViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\ElseViewHelper::class));
78  $mockElseViewHelperNode->expects($this->at(1))->method('evaluate')->with($this->renderingContext)->will($this->returnValue('ElseViewHelperResults'));
79 
80  $this->viewHelper->setChildNodes([$mockElseViewHelperNode]);
81  $actualResult = $this->viewHelper->_call('renderElseChild');
82  $this->assertEquals('ElseViewHelperResults', $actualResult);
83  }
84 
89  {
90  $this->arguments['then'] = 'ThenArgument';
91  $this->injectDependenciesIntoViewHelper($this->viewHelper);
92 
93  $actualResult = $this->viewHelper->_call('renderThenChild');
94  $this->assertEquals('ThenArgument', $actualResult);
95  }
96 
101  {
102  $mockElseViewHelperNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['getViewHelperClassName', 'evaluate'], [], '', false);
103  $mockElseViewHelperNode->expects($this->any())->method('getViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\ElseViewHelper::class));
104  $this->viewHelper->setChildNodes([$mockElseViewHelperNode]);
105  $this->viewHelper->expects($this->never())->method('renderChildren')->will($this->returnValue('Child nodes'));
106 
107  $actualResult = $this->viewHelper->_call('renderThenChild');
108  $this->assertEquals('', $actualResult);
109  }
110 
115  {
116  $mockThenViewHelperNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['getViewHelperClassName', 'evaluate', 'setRenderingContext'], [], '', false);
117  $mockThenViewHelperNode->expects($this->never())->method('evaluate');
118 
119  $this->viewHelper->setChildNodes([$mockThenViewHelperNode]);
120 
121  $this->arguments['then'] = 'ThenArgument';
122 
123  $this->injectDependenciesIntoViewHelper($this->viewHelper);
124 
125  $actualResult = $this->viewHelper->_call('renderThenChild');
126  $this->assertEquals('ThenArgument', $actualResult);
127  }
128 
133  {
134  $this->arguments['else'] = 'ElseArgument';
135  $this->injectDependenciesIntoViewHelper($this->viewHelper);
136 
137  $actualResult = $this->viewHelper->_call('renderElseChild');
138  $this->assertEquals('ElseArgument', $actualResult);
139  }
140 
145  {
146  $mockElseViewHelperNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['getViewHelperClassName', 'evaluate', 'setRenderingContext'], [], '', false);
147  $mockElseViewHelperNode->expects($this->any())->method('getViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\ElseViewHelper::class));
148  $mockElseViewHelperNode->expects($this->never())->method('evaluate');
149 
150  $this->viewHelper->setChildNodes([$mockElseViewHelperNode]);
151 
152  $this->arguments['else'] = 'ElseArgument';
153  $this->injectDependenciesIntoViewHelper($this->viewHelper);
154 
155  $actualResult = $this->viewHelper->_call('renderElseChild');
156  $this->assertEquals('ElseArgument', $actualResult);
157  }
158 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)