[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Controller / CommandControllerTest.php
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 */
16
17 /**
18 * Test case
19 */
20 class CommandControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Mvc\Controller\CommandController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
24 */
25 protected $commandController;
26
27 public function setUp() {
28 $this->commandController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\CommandController', array('dummyCommand'));
29 }
30
31 /**
32 * @test
33 */
34 public function outputAppendsGivenStringToTheResponseContent() {
35 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
36 $mockResponse->expects($this->once())->method('appendContent')->with('some text');
37 $this->commandController->_set('response', $mockResponse);
38 $this->commandController->_call('output', 'some text');
39 }
40
41 /**
42 * @test
43 */
44 public function outputReplacesArgumentsInGivenString() {
45 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
46 $mockResponse->expects($this->once())->method('appendContent')->with('some text');
47 $this->commandController->_set('response', $mockResponse);
48 $this->commandController->_call('output', '%2$s %1$s', array('text', 'some'));
49 }
50
51 /**
52 * @test
53 */
54 public function outputLineAppendsGivenStringAndNewlineToTheResponseContent() {
55 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
56 $mockResponse->expects($this->once())->method('appendContent')->with('some text' . PHP_EOL);
57 $this->commandController->_set('response', $mockResponse);
58 $this->commandController->_call('outputLine', 'some text');
59 }
60
61 /**
62 * @test
63 * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
64 */
65 public function quitThrowsStopActionException() {
66 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
67 $this->commandController->_set('response', $mockResponse);
68 $this->commandController->_call('quit');
69 }
70
71 /**
72 * @test
73 * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
74 */
75 public function quitSetsResponseExitCode() {
76 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
77 $mockResponse->expects($this->once())->method('setExitCode')->with(123);
78 $this->commandController->_set('response', $mockResponse);
79 $this->commandController->_call('quit', 123);
80 }
81
82 /**
83 * @test
84 */
85 public function settingRequestAdminPropertySetsAdminRoleInUserAuthentication() {
86 $mockedUserAuthentication = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\AbstractUserAuthentication');
87 $mockedUserAuthentication->user['admin'] = 42;
88 $this->commandController->expects($this->once())
89 ->method('dummyCommand')
90 ->will(
91 $this->returnCallback(
92 function() use ($mockedUserAuthentication) {
93 if ($mockedUserAuthentication->user['admin'] !== 1) {
94 throw new \Exception('User role is not admin');
95 }
96 }
97 ));
98 $this->commandController->_set('userAuthentication', $mockedUserAuthentication);
99 $this->commandController->_set('arguments', array());
100 $this->commandController->_set('commandMethodName', 'dummyCommand');
101 $this->commandController->_set('requestAdminPermissions', TRUE);
102 $this->commandController->_call('callCommandMethod');
103
104 $this->assertSame(42, $mockedUserAuthentication->user['admin']);
105 }
106 }