[+FEATURE] Backport CommandController Implementation
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / MVC / Controller / CommandControllerTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * All rights reserved
6 *
7 * This class is a backport of the corresponding class of FLOW3.
8 * All credits go to the v5 team.
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for the Command Controller
29 */
30 class Tx_Extbase_Tests_Unit_MVC_Controller_CommandControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
31
32 /**
33 * @var Tx_Extbase_MVC_Controller_CommandController
34 */
35 protected $commandController;
36
37 public function setUp() {
38 $this->commandController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_CommandController', array('dummy'));
39 }
40
41 /**
42 * @test
43 */
44 public function outputAppendsGivenStringToTheResponseContent() {
45 $mockResponse = $this->getMock('Tx_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', 'some text');
49 }
50
51 /**
52 * @test
53 */
54 public function outputReplacesArgumentsInGivenString() {
55 $mockResponse = $this->getMock('Tx_Extbase_MVC_CLI_Response');
56 $mockResponse->expects($this->once())->method('appendContent')->with('some text');
57 $this->commandController->_set('response', $mockResponse);
58 $this->commandController->_call('output', '%2$s %1$s', array('text', 'some'));
59 }
60
61 /**
62 * @test
63 */
64 public function outputLineAppendsGivenStringAndNewlineToTheResponseContent() {
65 $mockResponse = $this->getMock('Tx_Extbase_MVC_CLI_Response');
66 $mockResponse->expects($this->once())->method('appendContent')->with('some text' . PHP_EOL);
67 $this->commandController->_set('response', $mockResponse);
68 $this->commandController->_call('outputLine', 'some text');
69 }
70
71 /**
72 * @test
73 * @expectedException Tx_Extbase_MVC_Exception_StopAction
74 */
75 public function quitThrowsStopActionException() {
76 $mockResponse = $this->getMock('Tx_Extbase_MVC_CLI_Response');
77 $this->commandController->_set('response', $mockResponse);
78 $this->commandController->_call('quit');
79 }
80
81 /**
82 * @test
83 * @expectedException Tx_Extbase_MVC_Exception_StopAction
84 */
85 public function quitSetsResponseExitCode() {
86 $mockResponse = $this->getMock('Tx_Extbase_MVC_CLI_Response');
87 $mockResponse->expects($this->once())->method('setExitCode')->with(123);
88 $this->commandController->_set('response', $mockResponse);
89 $this->commandController->_call('quit', 123);
90 }
91 }
92 ?>