24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
37 $request = $this->getMockBuilder(\
TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)
38 ->setMethods([
'dummy'])
39 ->disableOriginalConstructor()
42 $abstractWidgetController = $this->getMockBuilder(\
TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class)
43 ->setMethods([
'dummy'])
44 ->disableOriginalConstructor()
46 $this->assertTrue($abstractWidgetController->canProcessRequest($request));
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));
67 $configurationService = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class);
68 $abstractWidgetController->_set(
'mvcPropertyMappingConfigurationService', $configurationService);
69 $abstractWidgetController->_set(
'arguments',
new Arguments());
71 $abstractWidgetController->_set(
'objectManager', $objectManager);
72 $abstractWidgetController->processRequest($request, $response);
73 $widgetConfiguration = $abstractWidgetController->_get(
'widgetConfiguration');
74 $this->assertEquals(
'myConfiguration', $widgetConfiguration);
86 $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
87 $configurationManager->expects($this->once())->method(
'getConfiguration')->willReturn([
90 'foobarClassName' => $widget
94 $parentRequest = $this->getMockBuilder(Request::class)
95 ->setMethods([
'getControllerExtensionKey'])
97 $parentRequest->expects($this->once())->method(
'getControllerExtensionKey')->willReturn(
null);
98 $controllerContext = $this->getMockBuilder(ControllerContext::class)
99 ->setMethods([
'getRequest'])
101 $controllerContext->expects($this->once())->method(
'getRequest')->willReturn($parentRequest);
102 $templatePaths = $this->getMockBuilder(TemplatePaths::class)
103 ->setMethods([
'fillFromConfigurationArray',
'toArray'])
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'])
110 $widgetContext->expects($this->once())->method(
'getWidgetViewHelperClassName')->willReturn(
'foobarClassName');
111 $request = $this->getMockBuilder(Request::class)
112 ->setMethods([
'getWidgetContext'])
114 $request->expects($this->once())->method(
'getWidgetContext')->willReturn($widgetContext);
116 $view = $this->getAccessibleMock(TemplateView::class, [
'getTemplatePaths',
'toArray'], [],
'',
false);
117 $view->expects($this->exactly(2))->method(
'getTemplatePaths')->willReturn($templatePaths);
119 $prophecy = $this->prophesize(AbstractWidgetController::class);
122 $controller = $prophecy->reveal();
124 $reflectionClass = new \ReflectionClass($controller);
126 $reflectionProperty = $reflectionClass->getProperty(
'configurationManager');
127 $reflectionProperty->setAccessible(
true);
128 $reflectionProperty->setValue($controller, $configurationManager);
130 $reflectionProperty = $reflectionClass->getProperty(
'controllerContext');
131 $reflectionProperty->setAccessible(
true);
132 $reflectionProperty->setValue($controller, $controllerContext);
134 $reflectionProperty = $reflectionClass->getProperty(
'request');
135 $reflectionProperty->setAccessible(
true);
136 $reflectionProperty->setValue($controller, $request);
138 $reflectionMethod = $reflectionClass->getMethod(
'setViewConfiguration');
139 $reflectionMethod->setAccessible(
true);
141 $reflectionMethod->setAccessible(
true);
142 $reflectionMethod->invokeArgs($controller, [$view]);
151 'Empty path sets cause empty widget paths' => [
155 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [],
156 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [],
157 TemplatePaths::CONFIG_PARTIALROOTPATHS => []
160 'Parent request paths are reused when not overridden' => [
162 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [
'foo'],
163 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [
'bar'],
164 TemplatePaths::CONFIG_PARTIALROOTPATHS => [
'baz']
168 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [
'foo'],
169 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [
'bar'],
170 TemplatePaths::CONFIG_PARTIALROOTPATHS => [
'baz']
173 'Widget paths are added to parent paths' => [
175 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [
'foo1'],
176 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [
'bar1'],
177 TemplatePaths::CONFIG_PARTIALROOTPATHS => [
'baz1']
180 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [
'foo2'],
181 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [
'bar2'],
182 TemplatePaths::CONFIG_PARTIALROOTPATHS => [
'baz2']
185 TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [
'foo1',
'foo2'],
186 TemplatePaths::CONFIG_LAYOUTROOTPATHS => [
'bar1',
'bar2'],
187 TemplatePaths::CONFIG_PARTIALROOTPATHS => [
'baz1',
'baz2']