TYPO3 CMS  TYPO3_6-2
CommandControllerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $commandController;
26 
27  public function setUp() {
28  $this->commandController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\CommandController', array('dummyCommand'));
29  }
30 
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 
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 
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 
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 
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 
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 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)