[BUGFIX] Remove competing injects from WidgetRequestHandler
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Widget / WidgetRequestHandlerTest.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\Mvc\Dispatcher;
17 use TYPO3\CMS\Extbase\Mvc\Web\Request;
18 use TYPO3\CMS\Extbase\Mvc\Web\Response;
19 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
20 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder;
21 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler;
22
23 /**
24 * Test case
25 */
26 class WidgetRequestHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
27 {
28 /**
29 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler
30 */
31 protected $widgetRequestHandler;
32
33 /**
34 * Set up
35 */
36 protected function setUp()
37 {
38 $this->widgetRequestHandler = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler::class, array('dummy'), array(), '', false);
39 }
40
41 /**
42 * @test
43 */
44 public function canHandleRequestReturnsTrueIfCorrectGetParameterIsSet()
45 {
46 $_GET['fluid-widget-id'] = 123;
47 $this->assertTrue($this->widgetRequestHandler->canHandleRequest());
48 }
49
50 /**
51 * @test
52 */
53 public function canHandleRequestReturnsFalsefGetParameterIsNotSet()
54 {
55 $_GET['some-other-id'] = 123;
56 $this->assertFalse($this->widgetRequestHandler->canHandleRequest());
57 }
58
59 /**
60 * @test
61 */
62 public function priorityIsHigherThanDefaultRequestHandler()
63 {
64 $defaultWebRequestHandler = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler::class, array('handleRequest'), array(), '', false);
65 $this->assertTrue($this->widgetRequestHandler->getPriority() > $defaultWebRequestHandler->getPriority());
66 }
67
68 /**
69 * @test
70 */
71 public function handleRequestCallsExpectedMethods()
72 {
73 $handler = new WidgetRequestHandler();
74 $request = $this->getMock(Request::class);
75 $requestBuilder = $this->getMock(WidgetRequestBuilder::class, array('build'));
76 $requestBuilder->expects($this->once())->method('build')->willReturn($request);
77 $objectManager = $this->getMock(ObjectManagerInterface::class);
78 $objectManager->expects($this->once())->method('get')->willReturn($this->getMock(Response::class));
79 $requestDispatcher = $this->getMock(Dispatcher::class, array('dispatch'), array(), '', false);
80 $requestDispatcher->expects($this->once())->method('dispatch')->with($request);
81 $this->inject($handler, 'widgetRequestBuilder', $requestBuilder);
82 $this->inject($handler, 'dispatcher', $requestDispatcher);
83 $this->inject($handler, 'objectManager', $objectManager);
84 $handler->handleRequest();
85 }
86 }