[TASK] Redesign TYPO3 error page
[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\BackendFormProtection;
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 protected function setUp()
44 {
45 $this->requestMock = $this->getAccessibleMock(\TYPO3\CMS\Core\Http\ServerRequest::class, array(), array(), '', false);
46 $this->formProtectionMock = $this->getMockForAbstractClass(BackendFormProtection::class, array(), '', false, true, true, array('validateToken'));
47 $this->subject = $this->getAccessibleMock(BackendModuleRequestHandler::class, array('boot', 'getFormProtection'), array(\TYPO3\CMS\Core\Core\Bootstrap::getInstance()), '', true);
48 }
49
50 /**
51 * @test
52 * @expectedException \InvalidArgumentException
53 * @expectedExceptionCode 1425236663
54 */
55 public function moduleIndexIsCalled()
56 {
57 $GLOBALS['TBE_MODULES'] = array(
58 '_PATHS' => array(
59 'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
60 )
61 );
62
63 $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(array('M' => 'module_fixture')));
64 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(true));
65 $this->subject->expects($this->once())->method('boot');
66 $this->subject->expects($this->atLeastOnce())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
67
68 $this->subject->handleRequest($this->requestMock);
69 }
70
71 /**
72 * @test
73 * @expectedException \TYPO3\CMS\Core\Exception
74 * @expectedExceptionCode 1417988921
75 */
76 public function throwsExceptionIfTokenIsInvalid()
77 {
78 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(false));
79 $this->subject->expects($this->once())->method('boot');
80 $this->subject->expects($this->atLeastOnce())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
81
82 $this->subject->handleRequest($this->requestMock);
83 }
84
85 /**
86 * @test
87 * @expectedException \InvalidArgumentException
88 * @expectedExceptionCode 1425236663
89 */
90 public function moduleDispatcherIsCalled()
91 {
92 $GLOBALS['TBE_MODULES'] = array(
93 '_PATHS' => array(
94 'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
95 )
96 );
97 $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(array('M' => 'module_fixture')));
98 $this->formProtectionMock->expects($this->once())->method('validateToken')->will($this->returnValue(true));
99 $this->subject->expects($this->once())->method('boot');
100 $this->subject->expects($this->atLeastOnce())->method('getFormProtection')->will($this->returnValue($this->formProtectionMock));
101
102 $this->subject->handleRequest($this->requestMock);
103 }
104 }