[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[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 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 */
16 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
17 use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
18 use TYPO3\CMS\Extbase\Mvc\Request;
19 use TYPO3\CMS\Extbase\Mvc\ResponseInterface;
20 use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController;
21 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequest;
22 use TYPO3\CMS\Fluid\View\TemplatePaths;
23 use TYPO3\CMS\Fluid\View\TemplateView;
24
25 /**
26 * Test case
27 */
28 class AbstractWidgetControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
30 /**
31 * @test
32 */
33 public function canHandleWidgetRequest()
34 {
35 /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */
36 $request = $this->getMockBuilder(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)
37 ->setMethods(['dummy'])
38 ->disableOriginalConstructor()
39 ->getMock();
40 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject $abstractWidgetController */
41 $abstractWidgetController = $this->getMockBuilder(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class)
42 ->setMethods(['dummy'])
43 ->disableOriginalConstructor()
44 ->getMock();
45 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
46 }
47
48 /**
49 * @test
50 */
51 public function processRequestSetsWidgetConfiguration()
52 {
53 $widgetContext = $this->createMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
54 $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration'));
55 /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */
56 $request = $this->createMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
57 $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext));
58 /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject $response */
59 $response = $this->createMock(\TYPO3\CMS\Extbase\Mvc\ResponseInterface::class);
60 /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $abstractWidgetController */
61 $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, ['resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'], [], '', false);
62 $mockUriBuilder = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
63 $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
64 $objectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class)->will($this->returnValue($mockUriBuilder));
65
66 $configurationService = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class);
67 $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService);
68 $abstractWidgetController->_set('arguments', new Arguments());
69
70 $abstractWidgetController->_set('objectManager', $objectManager);
71 $abstractWidgetController->processRequest($request, $response);
72 $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
73 $this->assertEquals('myConfiguration', $widgetConfiguration);
74 }
75
76 /**
77 * @test
78 * @dataProvider getSetViewConfigurationTestValues
79 * @param array $parent
80 * @param array|null $widget
81 * @param array $expected
82 */
83 public function setViewConfigurationPerformsExpectedInitialization(array $parent, $widget, array $expected)
84 {
85 $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
86 $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
87 'view' => [
88 'widget' => [
89 'foobarClassName' => $widget
90 ]
91 ]
92 ]);
93 $parentRequest = $this->getMockBuilder(Request::class)
94 ->setMethods(['getControllerExtensionKey'])
95 ->getMock();
96 $parentRequest->expects($this->once())->method('getControllerExtensionKey')->willReturn(null);
97 $controllerContext = $this->getMockBuilder(ControllerContext::class)
98 ->setMethods(['getRequest'])
99 ->getMock();
100 $controllerContext->expects($this->once())->method('getRequest')->willReturn($parentRequest);
101 $templatePaths = $this->getMockBuilder(TemplatePaths::class)
102 ->setMethods(['fillFromConfigurationArray', 'toArray'])
103 ->getMock();
104 $templatePaths->expects($this->once())->method('fillFromConfigurationArray')->with($expected);
105 $templatePaths->expects($this->any())->method('toArray')->willReturn($parent);
106 $widgetContext = $this->getMockBuilder(WidgetContext::class)
107 ->setMethods(['getWidgetViewHelperClassName'])
108 ->getMock();
109 $widgetContext->expects($this->once())->method('getWidgetViewHelperClassName')->willReturn('foobarClassName');
110 $request = $this->getMockBuilder(Request::class)
111 ->setMethods(['getWidgetContext'])
112 ->getMock();
113 $request->expects($this->once())->method('getWidgetContext')->willReturn($widgetContext);
114
115 $view = $this->getAccessibleMock(TemplateView::class, ['getTemplatePaths', 'toArray'], [], '', false);
116 $view->expects($this->exactly(2))->method('getTemplatePaths')->willReturn($templatePaths);
117
118 $mock = $this->getAccessibleMock(AbstractWidgetController::class, ['dummy']);
119 $mock->_set('configurationManager', $configurationManager);
120 $mock->_set('controllerContext', $controllerContext);
121 $mock->_set('request', $request);
122 $method = new \ReflectionMethod(AbstractWidgetController::class, 'setViewConfiguration');
123 $method->setAccessible(true);
124 $method->invokeArgs($mock, [$view]);
125 }
126
127 /**
128 * @return array
129 */
130 public function getSetViewConfigurationTestValues()
131 {
132 return [
133 'Empty path sets cause empty widget paths' => [
134 [],
135 null,
136 [
137 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [],
138 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [],
139 TemplatePaths::CONFIG_PARTIALROOTPATHS => []
140 ]
141 ],
142 'Parent request paths are reused when not overridden' => [
143 [
144 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo'],
145 TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar'],
146 TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz']
147 ],
148 [],
149 [
150 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo'],
151 TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar'],
152 TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz']
153 ]
154 ],
155 'Widget paths are added to parent paths' => [
156 [
157 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo1'],
158 TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar1'],
159 TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz1']
160 ],
161 [
162 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo2'],
163 TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar2'],
164 TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz2']
165 ],
166 [
167 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => ['foo1', 'foo2'],
168 TemplatePaths::CONFIG_LAYOUTROOTPATHS => ['bar1', 'bar2'],
169 TemplatePaths::CONFIG_PARTIALROOTPATHS => ['baz1', 'baz2']
170 ]
171 ],
172 ];
173 }
174 }