[+FEATURE] Fluid (Widgets): Allow overriding templateRootPath
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Widget / AbstractWidgetControllerTest.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 /**
24 * Testcase for AbstractWidgetController
25 *
26 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
27 */
28 class Tx_Fluid_Tests_Unit_Core_Widget_AbstractWidgetControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
29
30 /**
31 * @test
32 * @author Sebastian Kurfürst <sebastian@typo3.org>
33 */
34 public function canHandleWidgetRequest() {
35 $request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest', array('dummy'), array(), '', FALSE);
36 $abstractWidgetController = $this->getMock('Tx_Fluid_Core_Widget_AbstractWidgetController', array('dummy'), array(), '', FALSE);
37 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
38 }
39
40 /**
41 * @test
42 * @author Sebastian Kurfürst <sebastian@typo3.org>
43 * @author Bastian Waidelich <bastian@typo3.org>
44 */
45 public function processRequestSetsWidgetConfiguration() {
46 $widgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext');
47 $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
48
49 $request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest', array(), array(), '', FALSE);
50 $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
51
52 $response = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
53
54 $abstractWidgetController = $this->getAccessibleMock('Tx_Fluid_Core_Widget_AbstractWidgetController', array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE);
55
56 $mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder');
57
58 $objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
59 $objectManager->expects($this->any())->method('create')->with('Tx_Extbase_MVC_Web_Routing_UriBuilder')->will($this->returnValue($mockUriBuilder));
60 $abstractWidgetController->_set('objectManager', $objectManager);
61
62 $abstractWidgetController->processRequest($request, $response);
63
64 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
65 $this->assertEquals('myConfiguration', $widgetConfiguration);
66 }
67
68 /**
69 * @test
70 */
71 public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
72 $frameworkConfiguration = array(
73 'view' => array(
74 'widget' => array(
75 'Tx_Fluid_ViewHelpers_Widget_PaginateViewHelper' => array(
76 'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates'
77 )
78 )
79 )
80 );
81
82 $widgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext');
83 $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue('Tx_Fluid_ViewHelpers_Widget_PaginateViewHelper'));
84
85 $request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest', array(), array(), '', FALSE);
86 $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
87
88 $configurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager');
89 $configurationManager->expects($this->any())
90 ->method('getConfiguration')
91 ->will($this->returnValue($frameworkConfiguration));
92
93 $view = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'));
94
95 $abstractWidgetController = $this->getAccessibleMock('Tx_Fluid_Core_Widget_AbstractWidgetController', array('dummy'));
96 $abstractWidgetController->injectConfigurationManager($configurationManager);
97 $abstractWidgetController->_set('request', $request);
98 $abstractWidgetController->_call('setViewConfiguration', $view);
99 $this->assertEquals(t3lib_div::getFileAbsFileName('EXT:fluid/Resources/Private/DummyTestTemplates'), $view->_call('getTemplateRootPath'));
100 }
101 }
102 ?>