TYPO3 CMS  TYPO3_8-7
WidgetRequestHandlerTest.php
Go to the documentation of this file.
1 <?php
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  */
22 
26 class WidgetRequestHandlerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
32 
36  protected function setUp()
37  {
38  $this->widgetRequestHandler = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestHandler::class, ['dummy'], [], '', false);
39  }
40 
45  {
46  $_GET['fluid-widget-id'] = 123;
47  $this->assertTrue($this->widgetRequestHandler->canHandleRequest());
48  }
49 
54  {
55  $_GET['some-other-id'] = 123;
56  $this->assertFalse($this->widgetRequestHandler->canHandleRequest());
57  }
58 
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 
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 }