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