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