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\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
;
33 class AbstractWidgetControllerTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
38 public function canHandleWidgetRequest() {
39 /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */
40 $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
::class, array('dummy'), array(), '', FALSE);
41 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject $abstractWidgetController */
42 $abstractWidgetController = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
::class, array('dummy'), array(), '', FALSE);
43 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
49 public function processRequestSetsWidgetConfiguration() {
50 $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext
::class);
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
::class, 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
::class);
57 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractWidgetController */
58 $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE);
59 $mockUriBuilder = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
::class);
60 $objectManager = $this->getMock(\TYPO3\CMS\Extbase\
Object\ObjectManagerInterface
::class);
61 $objectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
::class)->will($this->returnValue($mockUriBuilder));
63 $configurationService = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService
::class);
64 $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
65 $abstractWidgetController->_set('arguments', new Arguments());
67 $abstractWidgetController->_set('objectManager', $objectManager);
68 $abstractWidgetController->processRequest($request, $response);
69 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
70 $this->assertEquals('myConfiguration', $widgetConfiguration);
76 public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
77 $frameworkConfiguration = array(
80 \TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper
::class => array(
81 'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates'
86 $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext
::class);
87 $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper
::class));
88 $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
::class, array(), array(), '', FALSE);
89 $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
90 $configurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager
::class);
91 $configurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($frameworkConfiguration));
92 $view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView
::class, array('dummy'), array(), '', FALSE);
93 $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
::class, 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'));