TYPO3 CMS  TYPO3_7-6
AbstractWidgetControllerTest.php
Go to the documentation of this file.
1 <?php
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 
29 
34 {
38  public function canHandleWidgetRequest()
39  {
41  $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, ['dummy'], [], '', false);
43  $abstractWidgetController = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, ['dummy'], [], '', false);
44  $this->assertTrue($abstractWidgetController->canProcessRequest($request));
45  }
46 
50  public function processRequestSetsWidgetConfiguration()
51  {
52  $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
53  $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
55  $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, [], [], '', false);
56  $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
58  $response = $this->getMock(\TYPO3\CMS\Extbase\Mvc\ResponseInterface::class);
60  $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, ['resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'], [], '', false);
61  $mockUriBuilder = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
62  $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
63  $objectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class)->will($this->returnValue($mockUriBuilder));
64 
65  $configurationService = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class);
66  $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
67  $abstractWidgetController->_set('arguments', new Arguments());
68 
69  $abstractWidgetController->_set('objectManager', $objectManager);
70  $abstractWidgetController->processRequest($request, $response);
71  $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
72  $this->assertEquals('myConfiguration', $widgetConfiguration);
73  }
74 
79  {
80  $frameworkConfiguration = [
81  'view' => [
82  'widget' => [
83  \TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper::class => [
84  'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates'
85  ]
86  ]
87  ]
88  ];
89  $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
90  $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper::class));
91  $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, [], [], '', false);
92  $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
93  $configurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
94  $configurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($frameworkConfiguration));
95  $view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['dummy'], [], '', false);
96  $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, ['dummy']);
97  $abstractWidgetController->_set('configurationManager', $configurationManager);
98  $abstractWidgetController->_set('request', $request);
99  $abstractWidgetController->_call('setViewConfiguration', $view);
100  $this->assertSame([GeneralUtility::getFileAbsFileName('EXT:fluid/Resources/Private/DummyTestTemplates')], $view->_call('getTemplateRootPaths'));
101  }
102 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static getFileAbsFileName($filename, $onlyRelative=true, $relToTYPO3_mainDir=false)