Raised Extbase and Fluid to version 1.3.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / RenderChildrenViewHelperTest.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once(dirname(__FILE__) . '/ViewHelperBaseTestcase.php');
24
25 /**
26 * Testcase for CycleViewHelper
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class Tx_Fluid_Tests_Unit_ViewHelpers_RenderChildrenViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
31
32 /**
33 * var Tx_Fluid_ViewHelpers_RenderChildrenViewHelper
34 */
35 protected $viewHelper;
36
37 /**
38 * @author Sebastian Kurfürst <sebastian@typo3.org>
39 */
40 public function setUp() {
41 $this->controllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
42 $this->viewHelper = $this->getMock('Tx_Fluid_ViewHelpers_RenderChildrenViewHelper', array('renderChildren'));
43 }
44
45 /**
46 * @test
47 * @author Sebastian Kurfürst <sebastian@typo3.org>
48 */
49 public function renderCallsEvaluateOnTheRootNodeAndRegistersTheArguments() {
50 $this->request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest');
51 $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
52 $this->viewHelper->setControllerContext($this->controllerContext);
53 $this->viewHelper->initializeArguments();
54
55 $templateVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer');
56 $templateVariableContainer->expects($this->at(0))->method('add')->with('k1', 'v1');
57 $templateVariableContainer->expects($this->at(1))->method('add')->with('k2', 'v2');
58 $templateVariableContainer->expects($this->at(2))->method('remove')->with('k1');
59 $templateVariableContainer->expects($this->at(3))->method('remove')->with('k2');
60
61 $renderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContextInterface');
62 $renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($templateVariableContainer));
63
64 $rootNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_RootNode');
65
66 $widgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext');
67 $this->request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
68 $widgetContext->expects($this->any())->method('getViewHelperChildNodeRenderingContext')->will($this->returnValue($renderingContext));
69 $widgetContext->expects($this->any())->method('getViewHelperChildNodes')->will($this->returnValue($rootNode));
70
71 $rootNode->expects($this->any())->method('evaluate')->with($renderingContext)->will($this->returnValue('Rendered Results'));
72
73 $output = $this->viewHelper->render(array('k1' => 'v1', 'k2' => 'v2'));
74 $this->assertEquals('Rendered Results', $output);
75 }
76
77 /**
78 * @test
79 * @expectedException Tx_Fluid_Core_Widget_Exception_WidgetRequestNotFoundException
80 * @author Sebastian Kurfürst <sebastian@typo3.org>
81 */
82 public function renderThrowsExceptionIfTheRequestIsNotAWidgetRequest() {
83 $this->request = $this->getMock('Tx_Fluid_MVC_Request');
84 $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
85 $this->viewHelper->setControllerContext($this->controllerContext);
86 $this->viewHelper->initializeArguments();
87
88 $output = $this->viewHelper->render();
89 }
90
91 /**
92 * @test
93 * @expectedException Tx_Fluid_Core_Widget_Exception_RenderingContextNotFoundException
94 * @author Sebastian Kurfürst <sebastian@typo3.org>
95 */
96 public function renderThrowsExceptionIfTheChildNodeRenderingContextIsNotThere() {
97 $this->request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest');
98 $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
99 $this->viewHelper->setControllerContext($this->controllerContext);
100 $this->viewHelper->initializeArguments();
101
102 $widgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext');
103 $this->request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
104 $widgetContext->expects($this->any())->method('getViewHelperChildNodeRenderingContext')->will($this->returnValue(NULL));
105 $widgetContext->expects($this->any())->method('getViewHelperChildNodes')->will($this->returnValue(NULL));
106
107 $output = $this->viewHelper->render();
108 }
109 }
110 ?>