[TASK] Replace inject methods with @inject
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Widget / AbstractWidgetControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget;
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 /**
24 * Testcase for AbstractWidgetController
25 */
26 class AbstractWidgetControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
27
28 /**
29 * @test
30 */
31 public function canHandleWidgetRequest() {
32 $request = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest', array('dummy'), array(), '', FALSE);
33 $abstractWidgetController = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetController', array('dummy'), array(), '', FALSE);
34 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
35 }
36
37 /**
38 * @test
39 */
40 public function processRequestSetsWidgetConfiguration() {
41 $widgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
42 $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
43 $request = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest', array(), array(), '', FALSE);
44 $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
45 $response = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface');
46 $abstractWidgetController = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetController', array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE);
47 $mockUriBuilder = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
48 $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
49 $objectManager->expects($this->any())->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder')->will($this->returnValue($mockUriBuilder));
50
51 $configurationService = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfigurationService');
52 $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
53 $abstractWidgetController->_set('arguments', new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments());
54
55 $abstractWidgetController->_set('objectManager', $objectManager);
56 $abstractWidgetController->processRequest($request, $response);
57 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
58 $this->assertEquals('myConfiguration', $widgetConfiguration);
59 }
60
61 /**
62 * @test
63 */
64 public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
65 $frameworkConfiguration = array(
66 'view' => array(
67 'widget' => array(
68 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Widget\\PaginateViewHelper' => array(
69 'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates'
70 )
71 )
72 )
73 );
74 $widgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
75 $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue('TYPO3\\CMS\\Fluid\\ViewHelpers\\Widget\\PaginateViewHelper'));
76 $request = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest', array(), array(), '', FALSE);
77 $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
78 $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
79 $configurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($frameworkConfiguration));
80 $view = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'));
81 $abstractWidgetController = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetController', array('dummy'));
82 $abstractWidgetController->_set('configurationManager', $configurationManager);
83 $abstractWidgetController->_set('request', $request);
84 $abstractWidgetController->_call('setViewConfiguration', $view);
85 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:fluid/Resources/Private/DummyTestTemplates'), $view->_call('getTemplateRootPath'));
86 }
87 }
88
89 ?>