TYPO3 CMS  TYPO3_7-6
CommandManagerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
28 {
32  protected $mockObjectManager;
33 
37  protected $commandManager;
38 
39  protected function setUp()
40  {
41  $this->commandManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager::class, ['getAvailableCommands']);
42  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
43  $this->commandManager->_set('objectManager', $this->mockObjectManager);
44  }
45 
49  public function getAvailableCommandsReturnsAllAvailableCommands()
50  {
52  $commandManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager::class, ['dummy']);
53  $commandManager->_set('objectManager', $this->mockObjectManager);
54  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'] = [
55  \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class,
56  \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockBCommandController::class
57  ];
58  $mockCommand1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
59  $mockCommand2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
60  $mockCommand3 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
61  $this->mockObjectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class, 'foo')->will($this->returnValue($mockCommand1));
62  $this->mockObjectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class, 'bar')->will($this->returnValue($mockCommand2));
63  $this->mockObjectManager->expects($this->at(2))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockBCommandController::class, 'baz')->will($this->returnValue($mockCommand3));
64  $commands = $commandManager->getAvailableCommands();
65  $this->assertEquals(3, count($commands));
66  $this->assertSame($mockCommand1, $commands[0]);
67  $this->assertSame($mockCommand2, $commands[1]);
68  $this->assertSame($mockCommand3, $commands[2]);
69  }
70 
75  {
76  $mockCommand = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
77  $mockCommand->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extensionkey:controller:command'));
78  $mockCommands = [$mockCommand];
79  $this->commandManager->expects($this->once())->method('getAvailableCommands')->will($this->returnValue($mockCommands));
80  $this->assertSame($mockCommand, $this->commandManager->getCommandByIdentifier('extensionkey:controller:command'));
81  }
82 
87  {
88  $mockCommand = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
89  $mockCommand->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extensionkey:controller:command'));
90  $mockCommands = [$mockCommand];
91  $this->commandManager->expects($this->once())->method('getAvailableCommands')->will($this->returnValue($mockCommands));
92  $this->assertSame($mockCommand, $this->commandManager->getCommandByIdentifier(' ExtensionKey:conTroLler:Command '));
93  }
94 
100  {
101  $mockCommand = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
102  $mockCommand->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extensionkey:controller:command'));
103  $mockCommands = [$mockCommand];
104  $this->commandManager->expects($this->once())->method('getAvailableCommands')->will($this->returnValue($mockCommands));
105  $this->commandManager->getCommandByIdentifier('extensionkey:controller:someothercommand');
106  }
107 
113  {
114  $mockCommand1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
115  $mockCommand1->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extensionkey:controller:command'));
116  $mockCommand2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, [], [], '', false);
117  $mockCommand2->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('otherextensionkey:controller:command'));
118  $mockCommands = [$mockCommand1, $mockCommand2];
119  $this->commandManager->expects($this->once())->method('getAvailableCommands')->will($this->returnValue($mockCommands));
120  $this->commandManager->getCommandByIdentifier('controller:command');
121  }
122 }
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']