[TASK] Shorten the extend class in all unit tests
[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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class WidgetRequestHandlerTest extends UnitTestCase
28 {
29 /**
30 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler
31 */
32 protected $widgetRequestHandler;
33
34 /**
35 * Set up
36 */
37 protected function setUp()
38 {
39 $this->widgetRequestHandler = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler::class, ['dummy'], [], '', false);
40 }
41
42 /**
43 * @test
44 */
45 public function canHandleRequestReturnsTrueIfCorrectGetParameterIsSet()
46 {
47 $_GET['fluid-widget-id'] = 123;
48 $this->assertTrue($this->widgetRequestHandler->canHandleRequest());
49 }
50
51 /**
52 * @test
53 */
54 public function canHandleRequestReturnsFalsefGetParameterIsNotSet()
55 {
56 $_GET['some-other-id'] = 123;
57 $this->assertFalse($this->widgetRequestHandler->canHandleRequest());
58 }
59
60 /**
61 * @test
62 */
63 public function priorityIsHigherThanDefaultRequestHandler()
64 {
65 $defaultWebRequestHandler = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler::class)
66 ->setMethods(['handleRequest'])
67 ->disableOriginalConstructor()
68 ->getMock();
69 $this->assertTrue($this->widgetRequestHandler->getPriority() > $defaultWebRequestHandler->getPriority());
70 }
71
72 /**
73 * @test
74 */
75 public function handleRequestCallsExpectedMethods()
76 {
77 $handler = new WidgetRequestHandler();
78 $request = $this->createMock(Request::class);
79 $requestBuilder = $this->getMockBuilder(WidgetRequestBuilder::class)
80 ->setMethods(['build'])
81 ->getMock();
82 $requestBuilder->expects($this->once())->method('build')->willReturn($request);
83 $objectManager = $this->createMock(ObjectManagerInterface::class);
84 $objectManager->expects($this->once())->method('get')->willReturn($this->createMock(Response::class));
85 $requestDispatcher = $this->getMockBuilder(Dispatcher::class)
86 ->setMethods(['dispatch'])
87 ->disableOriginalConstructor()
88 ->getMock();
89 $requestDispatcher->expects($this->once())->method('dispatch')->with($request);
90 $this->inject($handler, 'widgetRequestBuilder', $requestBuilder);
91 $this->inject($handler, 'dispatcher', $requestDispatcher);
92 $this->inject($handler, 'objectManager', $objectManager);
93 $handler->handleRequest();
94 }
95 }