TYPO3  7.6
BackendModuleRequestHandlerTest.php
Go to the documentation of this file.
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;
20 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
21 use TYPO3\CMS\Core\Tests\UnitTestCase;
22 
26 class BackendModuleRequestHandlerTest extends UnitTestCase
27 {
31  protected $subject;
32 
37 
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 
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 
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 
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 }