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