[!!!][TASK] Extract testing framework for TYPO3
[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\Components\TestingFramework\Core\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, ['dummy'], [], '', 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->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler::class)
65 ->setMethods(['handleRequest'])
66 ->disableOriginalConstructor()
67 ->getMock();
68 $this->assertTrue($this->widgetRequestHandler->getPriority() > $defaultWebRequestHandler->getPriority());
69 }
70
71 /**
72 * @test
73 */
74 public function handleRequestCallsExpectedMethods()
75 {
76 $handler = new WidgetRequestHandler();
77 $request = $this->createMock(Request::class);
78 $requestBuilder = $this->getMockBuilder(WidgetRequestBuilder::class)
79 ->setMethods(['build'])
80 ->getMock();
81 $requestBuilder->expects($this->once())->method('build')->willReturn($request);
82 $objectManager = $this->createMock(ObjectManagerInterface::class);
83 $objectManager->expects($this->once())->method('get')->willReturn($this->createMock(Response::class));
84 $requestDispatcher = $this->getMockBuilder(Dispatcher::class)
85 ->setMethods(['dispatch'])
86 ->disableOriginalConstructor()
87 ->getMock();
88 $requestDispatcher->expects($this->once())->method('dispatch')->with($request);
89 $this->inject($handler, 'widgetRequestBuilder', $requestBuilder);
90 $this->inject($handler, 'dispatcher', $requestDispatcher);
91 $this->inject($handler, 'objectManager', $objectManager);
92 $handler->handleRequest();
93 }
94 }