2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget
;
5 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
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. *
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. *
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 *
21 * The TYPO3 project - inspiring people to share! *
24 use TYPO3\CMS\Core\Tests\UnitTestCase
;
25 use TYPO3\CMS\Core\Utility\GeneralUtility
;
26 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager
;
27 use TYPO3\CMS\Extbase\Mvc\Controller\Arguments
;
28 use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
;
29 use TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService
;
30 use TYPO3\CMS\Extbase\Mvc\ResponseInterface
;
31 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
;
32 use TYPO3\CMS\Extbase\
Object\ObjectManagerInterface
;
33 use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
;
34 use TYPO3\CMS\Fluid\Core\Widget\WidgetContext
;
35 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
;
36 use TYPO3\CMS\Fluid\View\TemplateView
;
37 use TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper
;
42 class AbstractWidgetControllerTest
extends UnitTestCase
{
47 public function canHandleWidgetRequest() {
48 /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */
49 $request = $this->getMock(WidgetRequest
::class, array('dummy'), array(), '', FALSE);
50 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject $abstractWidgetController */
51 $abstractWidgetController = $this->getMock(AbstractWidgetController
::class, array('dummy'), array(), '', FALSE);
52 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
58 public function processRequestSetsWidgetConfiguration() {
59 $widgetContext = $this->getMock(WidgetContext
::class);
60 $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
61 /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */
62 $request = $this->getMock(WidgetRequest
::class, array(), array(), '', FALSE);
63 $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
64 /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject $response */
65 $response = $this->getMock(ResponseInterface
::class);
66 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractWidgetController */
67 $abstractWidgetController = $this->getAccessibleMock(AbstractWidgetController
::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE);
68 $mockUriBuilder = $this->getMock(UriBuilder
::class);
69 $objectManager = $this->getMock(ObjectManagerInterface
::class);
70 $objectManager->expects($this->any())->method('get')->with(UriBuilder
::class)->will($this->returnValue($mockUriBuilder));
72 $configurationService = $this->getMock(MvcPropertyMappingConfigurationService
::class);
73 $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
74 $abstractWidgetController->_set('arguments', new Arguments());
76 $abstractWidgetController->_set('objectManager', $objectManager);
77 $abstractWidgetController->processRequest($request, $response);
78 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
79 $this->assertEquals('myConfiguration', $widgetConfiguration);
85 public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
86 $frameworkConfiguration = array(
89 PaginateViewHelper
::class => array(
90 'templateRootPath' => 'EXT:fluid/Resources/Private',
91 'templateRootPaths' => ['EXT:fluid/Resources/Private']
96 $overriddenConfiguration['view'] = array_merge_recursive($frameworkConfiguration['view'], $frameworkConfiguration['view']['widget'][PaginateViewHelper
::class]);
98 $widgetContext = $this->getMock(WidgetContext
::class);
99 $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(PaginateViewHelper
::class));
101 $request = $this->getMock(WidgetRequest
::class, array(), array(), '', FALSE);
102 $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
103 $request->expects($this->any())->method('getControllerExtensionKey')->will($this->returnValue('fluid'));
105 $configurationManager = $this->getMock(ConfigurationManager
::class);
106 $configurationManager->expects($this->at(1))->method('setConfiguration')->with($overriddenConfiguration);
107 $configurationManager->expects($this->any())->method('getConfiguration')->willReturnOnConsecutiveCalls($this->returnValue($frameworkConfiguration), $this->returnValue($overriddenConfiguration));
109 $controllerContext = $this->getMock(ControllerContext
::class);
110 $controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($request));
112 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $view */
113 $view = $this->getAccessibleMock(TemplateView
::class, array('dummy'), array(), '', FALSE);
114 $view->_set('controllerContext', $controllerContext);
116 $abstractWidgetController = $this->getAccessibleMock(AbstractWidgetController
::class, array('dummy'));
117 $abstractWidgetController->_set('configurationManager', $configurationManager);
118 $abstractWidgetController->_set('request', $request);
119 $abstractWidgetController->_set('controllerContext', $controllerContext);
120 $abstractWidgetController->_call('setViewConfiguration', $view);
121 $this->assertSame(array('EXT:fluid/Resources/Private'), $view->_call('getTemplateRootPaths'));