TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CommandControllerTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
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  */
17 
22 {
26  protected $commandController;
27 
31  protected $mockConsoleOutput;
32 
33  protected function setUp()
34  {
35  $this->commandController = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\CommandController::class, ['dummyCommand']);
36  $this->mockConsoleOutput = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Cli\ConsoleOutput::class)->disableOriginalConstructor()->getMock();
37  $this->commandController->_set('output', $this->mockConsoleOutput);
38  }
39 
44  {
45  $this->mockConsoleOutput->expects($this->once())->method('output')->with('some text');
46  $this->commandController->_call('output', 'some text');
47  }
48 
53  {
54  $this->mockConsoleOutput->expects($this->once())->method('output')->with('%2$s %1$s', ['text', 'some']);
55  $this->commandController->_call('output', '%2$s %1$s', ['text', 'some']);
56  }
57 
62  {
63  $this->expectException(StopActionException::class);
64  // @TODO expectExceptionCode is 0
65  $mockResponse = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
66  $this->commandController->_set('response', $mockResponse);
67  $this->commandController->_call('quit');
68  }
69 
73  public function quitSetsResponseExitCode()
74  {
75  $this->expectException(StopActionException::class);
76  // @TODO expectExceptionCode is 0
77  $mockResponse = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
78  $mockResponse->expects($this->once())->method('setExitCode')->with(123);
79  $this->commandController->_set('response', $mockResponse);
80  $this->commandController->_call('quit', 123);
81  }
82 
87  {
88  $mockedUserAuthentication = $this->createMock(\TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::class);
89  $mockedUserAuthentication->user['admin'] = 42;
90  $this->commandController->expects($this->once())
91  ->method('dummyCommand')
92  ->will(
93  $this->returnCallback(
94  function () use ($mockedUserAuthentication) {
95  if ($mockedUserAuthentication->user['admin'] !== 1) {
96  throw new \Exception('User role is not admin', 1476050222);
97  }
98  }
99  ));
100  $GLOBALS['BE_USER'] = $mockedUserAuthentication;
101  $this->commandController->_set('arguments', []);
102  $this->commandController->_set('commandMethodName', 'dummyCommand');
103  $this->commandController->_set('requestAdminPermissions', true);
104  $this->commandController->_call('callCommandMethod');
105 
106  $this->assertSame(42, $mockedUserAuthentication->user['admin']);
107  }
108 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)