[!!!][TASK] Use fallbacks for AbstractWidgetController view-configuration
[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\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;
38
39 /**
40 * Test case
41 */
42 class AbstractWidgetControllerTest extends UnitTestCase {
43
44 /**
45 * @test
46 */
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));
53 }
54
55 /**
56 * @test
57 */
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));
71
72 $configurationService = $this->getMock(MvcPropertyMappingConfigurationService::class);
73 $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
74 $abstractWidgetController->_set('arguments', new Arguments());
75
76 $abstractWidgetController->_set('objectManager', $objectManager);
77 $abstractWidgetController->processRequest($request, $response);
78 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
79 $this->assertEquals('myConfiguration', $widgetConfiguration);
80 }
81
82 /**
83 * @test
84 */
85 public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
86 $frameworkConfiguration = array(
87 'view' => array(
88 'widget' => array(
89 PaginateViewHelper::class => array(
90 'templateRootPath' => 'EXT:fluid/Resources/Private',
91 'templateRootPaths' => ['EXT:fluid/Resources/Private']
92 )
93 )
94 )
95 );
96 $overriddenConfiguration['view'] = array_merge_recursive($frameworkConfiguration['view'], $frameworkConfiguration['view']['widget'][PaginateViewHelper::class]);
97
98 $widgetContext = $this->getMock(WidgetContext::class);
99 $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(PaginateViewHelper::class));
100
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'));
104
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));
108
109 $controllerContext = $this->getMock(ControllerContext::class);
110 $controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($request));
111
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);
115
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'));
122 }
123
124 }