‪TYPO3CMS  9.5
AbstractWidgetControllerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪AbstractWidgetControllerTest extends UnitTestCase
30 {
34  public function ‪canHandleWidgetRequest()
35  {
37  $request = $this->getMockBuilder(\‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)
38  ->setMethods(['dummy'])
39  ->disableOriginalConstructor()
40  ->getMock();
42  $abstractWidgetController = $this->getMockBuilder(\‪TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class)
43  ->setMethods(['dummy'])
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->assertTrue($abstractWidgetController->canProcessRequest($request));
47  }
48 
53  {
54  $widgetContext = $this->createMock(\‪TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
55  $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
57  $request = $this->createMock(\‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
58  $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
60  $response = $this->createMock(\‪TYPO3\CMS\‪Extbase\Mvc\ResponseInterface::class);
62  $abstractWidgetController = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, ['resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'], [], '', false);
63  $mockUriBuilder = $this->createMock(\‪TYPO3\CMS\‪Extbase\Mvc\Web\Routing\UriBuilder::class);
64  $objectManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManagerInterface::class);
65  $objectManager->expects($this->any())->method('get')->with(\‪TYPO3\CMS\‪Extbase\Mvc\Web\Routing\UriBuilder::class)->will($this->returnValue($mockUriBuilder));
66 
67  $configurationService = $this->createMock(\‪TYPO3\CMS\‪Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class);
68  $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
69  $abstractWidgetController->_set('arguments', new ‪Arguments());
70 
71  $abstractWidgetController->_set('objectManager', $objectManager);
72  $abstractWidgetController->processRequest($request, $response);
73  $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
74  $this->assertEquals('myConfiguration', $widgetConfiguration);
75  }
76 
84  public function ‪setViewConfigurationPerformsExpectedInitialization(array $parent, $widget, array $expected)
85  {
86  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
87  $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
88  'view' => [
89  'widget' => [
90  'foobarClassName' => $widget
91  ]
92  ]
93  ]);
94  $parentRequest = $this->getMockBuilder(Request::class)
95  ->setMethods(['getControllerExtensionKey'])
96  ->getMock();
97  $parentRequest->expects($this->once())->method('getControllerExtensionKey')->willReturn(null);
98  $controllerContext = $this->getMockBuilder(ControllerContext::class)
99  ->setMethods(['getRequest'])
100  ->getMock();
101  $controllerContext->expects($this->once())->method('getRequest')->willReturn($parentRequest);
102  $templatePaths = $this->getMockBuilder(TemplatePaths::class)
103  ->setMethods(['fillFromConfigurationArray', 'toArray'])
104  ->getMock();
105  $templatePaths->expects($this->once())->method('fillFromConfigurationArray')->with($expected);
106  $templatePaths->expects($this->any())->method('toArray')->willReturn($parent);
107  $widgetContext = $this->getMockBuilder(WidgetContext::class)
108  ->setMethods(['getWidgetViewHelperClassName'])
109  ->getMock();
110  $widgetContext->expects($this->once())->method('getWidgetViewHelperClassName')->willReturn('foobarClassName');
111  $request = $this->getMockBuilder(Request::class)
112  ->setMethods(['getWidgetContext'])
113  ->getMock();
114  $request->expects($this->once())->method('getWidgetContext')->willReturn($widgetContext);
115 
116  $view = $this->getAccessibleMock(TemplateView::class, ['getTemplatePaths', 'toArray'], [], '', false);
117  $view->expects($this->exactly(2))->method('getTemplatePaths')->willReturn($templatePaths);
118 
119  $prophecy = $this->prophesize(AbstractWidgetController::class);
120 
122  $controller = $prophecy->reveal();
123 
124  $reflectionClass = new \ReflectionClass($controller);
125 
126  $reflectionProperty = $reflectionClass->getProperty('configurationManager');
127  $reflectionProperty->setAccessible(true);
128  $reflectionProperty->setValue($controller, $configurationManager);
129 
130  $reflectionProperty = $reflectionClass->getProperty('controllerContext');
131  $reflectionProperty->setAccessible(true);
132  $reflectionProperty->setValue($controller, $controllerContext);
133 
134  $reflectionProperty = $reflectionClass->getProperty('request');
135  $reflectionProperty->setAccessible(true);
136  $reflectionProperty->setValue($controller, $request);
137 
138  $reflectionMethod = $reflectionClass->getMethod('setViewConfiguration');
139  $reflectionMethod->setAccessible(true);
140 
141  $reflectionMethod->setAccessible(true);
142  $reflectionMethod->invokeArgs($controller, [$view]);
143  }
144 
149  {
150  return [
151  'Empty path sets cause empty widget paths' => [
152  [],
153  null,
154  [
155  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [],
156  TemplatePaths::CONFIG_LAYOUTROOTPATHS => [],
157  TemplatePaths::CONFIG_PARTIALROOTPATHS => []
158  ]
159  ],
160  'Parent request paths are reused when not overridden' => [
161  [
162  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo'],
163  TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar'],
164  TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz']
165  ],
166  [],
167  [
168  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo'],
169  TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar'],
170  TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz']
171  ]
172  ],
173  'Widget paths are added to parent paths' => [
174  [
175  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo1'],
176  TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar1'],
177  TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz1']
178  ],
179  [
180  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo2'],
181  TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar2'],
182  TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz2']
183  ],
184  [
185  TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo1', 'foo2'],
186  TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar1', 'bar2'],
187  TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz1', 'baz2']
188  ]
189  ],
190  ];
191  }
192 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:34
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
Definition: WidgetRequest.php:22
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Mvc\ResponseInterface
Definition: ResponseInterface.php:21
‪TYPO3
‪TYPO3\CMS\Extbase\Mvc\Controller\Arguments
Definition: Arguments.php:22
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\AbstractWidgetControllerTest\canHandleWidgetRequest
‪canHandleWidgetRequest()
Definition: AbstractWidgetControllerTest.php:34
‪TYPO3\CMS\Fluid\View\TemplateView
Definition: TemplateView.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\AbstractWidgetControllerTest\getSetViewConfigurationTestValues
‪array getSetViewConfigurationTestValues()
Definition: AbstractWidgetControllerTest.php:148
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget
Definition: AbstractWidgetControllerTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\AbstractWidgetControllerTest\processRequestSetsWidgetConfiguration
‪processRequestSetsWidgetConfiguration()
Definition: AbstractWidgetControllerTest.php:52
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:23
‪TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
Definition: AbstractWidgetController.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\AbstractWidgetControllerTest\setViewConfigurationPerformsExpectedInitialization
‪setViewConfigurationPerformsExpectedInitialization(array $parent, $widget, array $expected)
Definition: AbstractWidgetControllerTest.php:84
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\AbstractWidgetControllerTest
Definition: AbstractWidgetControllerTest.php:30