/** * @test */ public function getAdditionalInformationRespectsArguments() { $this->task->_set('commandIdentifier', 'foo'); $this->task->_set('defaults', array('bar' => 'baz')); $this->task->_set('arguments', array('qux' => 'quux')); $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation()); }
/** * Gets the default value of argument * * @param \TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition $argument * @return mixed */ protected function getDefaultArgumentValue(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition $argument) { $type = $this->getArgumentType($argument); $argumentName = $argument->getName(); $command = $this->commandManager->getCommandByIdentifier($this->task->getCommandIdentifier()); $argumentReflection = $this->reflectionService->getMethodParameters($command->getControllerClassName(), $command->getControllerCommandName() . 'Command'); $defaultValue = $argumentReflection[$argumentName]['defaultValue']; if ($type === 'boolean') { $defaultValue = (bool) $defaultValue ? 1 : 0; } return $defaultValue; }
/** * @test */ public function getAdditionalFieldsRendersRightHtml() { $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test'); /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command1 */ $command1 = $this->getAccessibleMock(Command::class, array(), array(), '', false); $command1->expects($this->once())->method('isInternal')->will($this->returnValue(false)); $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue(MockACommandController::class)); $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA')); $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca')); $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue(array())); /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command2 */ $command2 = $this->getAccessibleMock(Command::class, array(), array(), '', false); $command2->expects($this->once())->method('isInternal')->will($this->returnValue(false)); $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController')); $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB')); $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb')); /** @var Command|\PHPUnit_Framework_MockObject_MockObject $command3 */ $command3 = $this->getAccessibleMock(Command::class, array(), array(), '', false); $command3->expects($this->once())->method('isInternal')->will($this->returnValue(false)); $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController')); $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC')); $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc')); /** @var CommandManager|\PHPUnit_Framework_MockObject_MockObject $commandManager */ $commandManager = $this->getMock(CommandManager::class, array('getAvailableCommands')); $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($command1, $command2, $command3))); /** @var FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fieldProvider */ $fieldProvider = $this->getAccessibleMock(FieldProvider::class, array('getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'), array(), '', false); $fieldProvider->_set('commandManager', $commandManager); $actionLabel = 'action label string'; $argumentLabel = 'argument label string'; $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel)); $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel)); $argArray['arg'] = array('code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ', 'label' => $argumentLabel); $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray)); $expectedAdditionalFields = array('action' => array('code' => '<select name="tx_scheduler[task_extbase][action]">' . LF . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF . '</select>', 'label' => $actionLabel), 'description' => array('code' => '', 'label' => '<strong></strong>'), 'arg' => array('code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ', 'label' => $argumentLabel)); $taskInfo = array(); /** @var Task $task */ $task = new Task(); $task->setCommandIdentifier($command1->getCommandIdentifier()); /** @var SchedulerModuleController $schedulerModule */ $schedulerModule = $this->getMock(SchedulerModuleController::class, array(), array(), '', false); $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule)); }
/** * Execute Task * * If errors occur during Task execution they are thrown as Exceptions which * must be caught manually if you manually execute Tasks through your code. * * @param \TYPO3\CMS\Extbase\Scheduler\Task $task the task to execute * @return void */ public function execute(\TYPO3\CMS\Extbase\Scheduler\Task $task) { $commandIdentifier = $task->getCommandIdentifier(); list($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier); $extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($extensionKey); $this->initialize(array('extensionName' => $extensionName)); // execute command $command = $this->commandManager->getCommandByIdentifier($commandIdentifier); $this->request->setControllerObjectName($command->getControllerClassName()); $this->request->setControllerCommandName($command->getControllerCommandName()); $this->request->setArguments($task->getArguments()); $this->dispatcher->dispatch($this->request, $this->response); $this->shutdown(); }