TYPO3 CMS  TYPO3_7-6
RenderChildrenViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the FLOW3 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  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
28 {
32  protected $viewHelper;
33 
37  protected function setUp()
38  {
39  $this->controllerContext = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class, [], [], '', false);
40  $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper::class, ['renderChildren']);
41  $this->viewHelper->_set('controllerContext', $this->controllerContext);
42  }
43 
48  {
49  $this->request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
50  $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
51  $this->viewHelper->initializeArguments();
52  $templateVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer::class);
53  $templateVariableContainer->expects($this->at(0))->method('add')->with('k1', 'v1');
54  $templateVariableContainer->expects($this->at(1))->method('add')->with('k2', 'v2');
55  $templateVariableContainer->expects($this->at(2))->method('remove')->with('k1');
56  $templateVariableContainer->expects($this->at(3))->method('remove')->with('k2');
57  $renderingContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface::class);
58  $renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($templateVariableContainer));
59  $rootNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode::class);
60  $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
61  $this->request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
62  $widgetContext->expects($this->any())->method('getViewHelperChildNodeRenderingContext')->will($this->returnValue($renderingContext));
63  $widgetContext->expects($this->any())->method('getViewHelperChildNodes')->will($this->returnValue($rootNode));
64  $rootNode->expects($this->any())->method('evaluate')->with($renderingContext)->will($this->returnValue('Rendered Results'));
65  $output = $this->viewHelper->render(['k1' => 'v1', 'k2' => 'v2']);
66  $this->assertEquals('Rendered Results', $output);
67  }
68 
74  {
75  $this->request = $this->getMock('Tx_Fluid_MVC_Request');
76  $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
77  $this->viewHelper->initializeArguments();
78  $this->viewHelper->render();
79  }
80 
86  {
87  $this->request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
88  $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
89  $this->viewHelper->initializeArguments();
90  $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
91  $this->request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
92  $widgetContext->expects($this->any())->method('getViewHelperChildNodeRenderingContext')->will($this->returnValue(null));
93  $widgetContext->expects($this->any())->method('getViewHelperChildNodes')->will($this->returnValue(null));
94  $this->viewHelper->render();
95  }
96 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)