[FEATURE] Introduce Request/Response based on PSR-7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Http / BackendModuleRequestHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Http;
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
17 use PHPUnit_Framework_MockObject_MockObject;
18 use TYPO3\CMS\Backend\Http\BackendModuleRequestHandler;
19 use TYPO3\CMS\Core\FormProtection\AbstractFormProtection;
20 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
21 use TYPO3\CMS\Core\Tests\UnitTestCase;
22
23 /**
24 * Class BackendModuleRequestHandlerTest
25 */
26 class BackendModuleRequestHandlerTest extends UnitTestCase {
27
28 /**
29 * @var BackendModuleRequestHandler|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
30 */
31 protected $subject;
32
33 /**
34 * @var \TYPO3\CMS\Core\FormProtection\AbstractFormProtection|PHPUnit_Framework_MockObject_MockObject
35 */
36 protected $formProtectionMock;
37
38 /**
39 * @var \TYPO3\CMS\Core\Http\ServerRequest|PHPUnit_Framework_MockObject_MockObject
40 */
41 protected $requestMock;
42
43 public function setUp() {
44 $this->requestMock = $this->getAccessibleMock(\TYPO3\CMS\Core\Http\ServerRequest::class, array(), array(), '', FALSE);
45 $this->formProtectionMock = $this->getMockForAbstractClass(AbstractFormProtection::class, array(), '', TRUE, TRUE, TRUE, array('validateToken'));
46 $this->subject = $this->getAccessibleMock(BackendModuleRequestHandler::class, array('boot', 'getFormProtection'), array(\TYPO3\CMS\Core\Core\Bootstrap::getInstance()), '', TRUE);
47 }
48
49 /**
50 * @test
51 * @expectedException \InvalidArgumentException
52 * @expectedExceptionCode 1425236663
53 */
54 public function moduleIndexIsCalled() {
55 $GLOBALS['TBE_MODULES'] = array(
56 '_PATHS' => array(
57 'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
58 )
59 );
60
61 $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(array('M' => 'module_fixture')));
62 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(TRUE));
63 $this->subject->expects($this->once())->method('boot');
64 $this->subject->expects($this->once())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
65
66 $this->subject->handleRequest($this->requestMock);
67 }
68
69 /**
70 * @test
71 * @expectedException \TYPO3\CMS\Core\Exception
72 * @expectedExceptionCode 1417988921
73 */
74 public function throwsExceptionIfTokenIsInvalid() {
75 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(FALSE));
76 $this->subject->expects($this->once())->method('boot');
77 $this->subject->expects($this->once())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
78
79 $this->subject->handleRequest($this->requestMock);
80 }
81
82 /**
83 * @test
84 * @expectedException \InvalidArgumentException
85 * @expectedExceptionCode 1425236663
86 */
87 public function moduleDispatcherIsCalled() {
88 $GLOBALS['TBE_MODULES'] = array(
89 '_PATHS' => array(
90 '_dispatcher' => array(),
91 'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
92 )
93 );
94 $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(array('M' => 'module_fixture')));
95 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(TRUE));
96 $this->subject->expects($this->once())->method('boot');
97 $this->subject->expects($this->once())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
98
99 $this->subject->handleRequest($this->requestMock);
100 }
101
102 }