[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 script is backported from the FLOW3 package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23 use TYPO3\CMS\Extbase\Mvc\Dispatcher;
24 use TYPO3\CMS\Extbase\Mvc\Web\Request;
25 use TYPO3\CMS\Extbase\Mvc\Web\Response;
26 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
27 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder;
28 use TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler;
29
30 /**
31 * Test case
32 */
33 class WidgetRequestHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
34 {
35 /**
36 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler
37 */
38 protected $widgetRequestHandler;
39
40 /**
41 * Set up
42 */
43 protected function setUp()
44 {
45 $this->widgetRequestHandler = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler::class, array('dummy'), array(), '', false);
46 }
47
48 /**
49 * @test
50 */
51 public function canHandleRequestReturnsTrueIfCorrectGetParameterIsSet()
52 {
53 $_GET['fluid-widget-id'] = 123;
54 $this->assertTrue($this->widgetRequestHandler->canHandleRequest());
55 }
56
57 /**
58 * @test
59 */
60 public function canHandleRequestReturnsFalsefGetParameterIsNotSet()
61 {
62 $_GET['some-other-id'] = 123;
63 $this->assertFalse($this->widgetRequestHandler->canHandleRequest());
64 }
65
66 /**
67 * @test
68 */
69 public function priorityIsHigherThanDefaultRequestHandler()
70 {
71 $defaultWebRequestHandler = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler::class, array('handleRequest'), array(), '', false);
72 $this->assertTrue($this->widgetRequestHandler->getPriority() > $defaultWebRequestHandler->getPriority());
73 }
74
75 /**
76 * @test
77 */
78 public function handleRequestCallsExpectedMethods()
79 {
80 $handler = new WidgetRequestHandler();
81 $request = $this->getMock(Request::class);
82 $requestBuilder = $this->getMock(WidgetRequestBuilder::class, array('build'));
83 $requestBuilder->expects($this->once())->method('build')->willReturn($request);
84 $objectManager = $this->getMock(ObjectManagerInterface::class);
85 $objectManager->expects($this->once())->method('get')->willReturn($this->getMock(Response::class));
86 $requestDispatcher = $this->getMock(Dispatcher::class, array('dispatch'), array(), '', false);
87 $requestDispatcher->expects($this->once())->method('dispatch')->with($request);
88 $this->inject($handler, 'widgetRequestBuilder', $requestBuilder);
89 $this->inject($handler, 'dispatcher', $requestDispatcher);
90 $this->inject($handler, 'objectManager', $objectManager);
91 $handler->handleRequest();
92 }
93 }