TYPO3 CMS  TYPO3_6-2
All Classes Namespaces Files Functions Variables Pages
AbstractWidgetViewHelperTest.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 
38 
42  protected $widgetContext;
43 
47  protected $objectManager;
48 
52  protected $controllerContext;
53 
57  protected $request;
58 
63 
67  public function setUp() {
68  $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetViewHelper', array('validateArguments', 'initialize', 'callRenderMethod', 'getWidgetConfiguration', 'getRenderingContext'));
69  $this->mockExtensionService = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\ExtensionService');
70  $this->viewHelper->_set('extensionService', $this->mockExtensionService);
71  $this->ajaxWidgetContextHolder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder', array(), array(), '', FALSE);
72  $this->viewHelper->injectAjaxWidgetContextHolder($this->ajaxWidgetContextHolder);
73  $this->widgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
74  $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
75  $this->objectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext')->will($this->returnValue($this->widgetContext));
76  $this->viewHelper->injectObjectManager($this->objectManager);
77  $this->request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
78  $this->controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE);
79  $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
80  $this->viewHelper->_set('controllerContext', $this->controllerContext);
81  }
82 
87  $this->callViewHelper();
88  }
89 
94  $this->viewHelper->_set('ajaxWidget', TRUE);
95  $this->ajaxWidgetContextHolder->expects($this->once())->method('store')->with($this->widgetContext);
96  $this->callViewHelper();
97  }
98 
104  public function callViewHelper() {
105  $mockViewHelperVariableContainer = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer');
106  $mockRenderingContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface');
107  $mockRenderingContext->expects($this->atLeastOnce())->method('getViewHelperVariableContainer')->will($this->returnValue($mockViewHelperVariableContainer));
108  $this->viewHelper->setRenderingContext($mockRenderingContext);
109  $this->viewHelper->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('Some Widget Configuration'));
110  $this->widgetContext->expects($this->once())->method('setWidgetConfiguration')->with('Some Widget Configuration');
111  $this->widgetContext->expects($this->once())->method('setWidgetIdentifier')->with('@widget_0');
112  $this->viewHelper->_set('controller', new \stdClass());
113  $this->widgetContext->expects($this->once())->method('setControllerObjectName')->with('stdClass');
114  $this->viewHelper->expects($this->once())->method('validateArguments');
115  $this->viewHelper->expects($this->once())->method('initialize');
116  $this->viewHelper->expects($this->once())->method('callRenderMethod')->will($this->returnValue('renderedResult'));
117  $output = $this->viewHelper->initializeArgumentsAndRender();
118  $this->assertEquals('renderedResult', $output);
119  }
120 
125  $node1 = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode');
126  $node2 = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', array(), array(), '', FALSE);
127  $node3 = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode');
128  $rootNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
129  $rootNode->expects($this->at(0))->method('addChildNode')->with($node1);
130  $rootNode->expects($this->at(1))->method('addChildNode')->with($node2);
131  $rootNode->expects($this->at(2))->method('addChildNode')->with($node3);
132  $this->objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode')->will($this->returnValue($rootNode));
133  $renderingContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface');
134  $this->viewHelper->_set('renderingContext', $renderingContext);
135  $this->widgetContext->expects($this->once())->method('setViewHelperChildNodes')->with($rootNode, $renderingContext);
136  $this->viewHelper->setChildNodes(array($node1, $node2, $node3));
137  }
138 
144  $controller = $this->getMock('Tx_Fluid_MVC_Controller_ControllerInterface');
145  $this->viewHelper->_set('controller', $controller);
146  $this->viewHelper->_call('initiateSubRequest');
147  }
148 
153  $controller = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetController', array(), array(), '', FALSE);
154  $this->viewHelper->_set('controller', $controller);
155  // Initial Setup
156  $widgetRequest = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest');
157  $response = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
158  $this->objectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest')->will($this->returnValue($widgetRequest));
159  $this->objectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response')->will($this->returnValue($response));
160  // Widget Context is set
161  $widgetRequest->expects($this->once())->method('setWidgetContext')->with($this->widgetContext);
162  // The namespaced arguments are passed to the sub-request
163  // and the action name is exctracted from the namespace.
164  $this->controllerContext->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
165  $this->widgetContext->expects($this->once())->method('getWidgetIdentifier')->will($this->returnValue('widget-1'));
166  $this->request->expects($this->once())->method('getArguments')->will($this->returnValue(array(
167  'k1' => 'k2',
168  'widget-1' => array(
169  'arg1' => 'val1',
170  'arg2' => 'val2',
171  'action' => 'myAction'
172  )
173  )));
174  $widgetRequest->expects($this->once())->method('setArguments')->with(array(
175  'arg1' => 'val1',
176  'arg2' => 'val2'
177  ));
178  $widgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
179  // Controller is called
180  $controller->expects($this->once())->method('processRequest')->with($widgetRequest, $response);
181  $output = $this->viewHelper->_call('initiateSubRequest');
182  // SubResponse is returned
183  $this->assertSame($response, $output);
184  }
185 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)