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