TYPO3 CMS  TYPO3_7-6
BackendModuleRequestHandlerTest.php
Go to the documentation of this file.
1 <?php
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 
22 
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, [], [], '', false);
46  $this->formProtectionMock = $this->getMockForAbstractClass(BackendFormProtection::class, [], '', false, true, true, ['validateToken']);
47  $this->subject = $this->getAccessibleMock(BackendModuleRequestHandler::class, ['boot', 'getFormProtection'], [\TYPO3\CMS\Core\Core\Bootstrap::getInstance()], '', true);
48  }
49 
55  public function moduleIndexIsCalled()
56  {
57  $GLOBALS['TBE_MODULES'] = [
58  '_PATHS' => [
59  'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
60  ]
61  ];
62 
63  $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(['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'] = [
93  '_PATHS' => [
94  'module_fixture' => __DIR__ . '/../Fixtures/ModuleFixture/'
95  ]
96  ];
97  $this->requestMock->expects($this->any())->method('getQueryParams')->will($this->returnValue(['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 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']