Files
Phraseanet/tests/classes/module/console/module_console_taskStateTest.php
jygaulier 2d6e087104 syslog + maillog in task / task-manager as service
fix task interfaces / cleanup
fix tests using task manager
2013-01-21 12:50:35 +01:00

64 lines
2.7 KiB
PHP

<?php
use Alchemy\Phrasea\CLI;
use Symfony\Component\Console\Tester\CommandTester;
class module_console_taskStateTest extends PhraseanetPHPUnitAbstract
{
/**
* @covers module_console_taskState::execute
*/
public function testExecute()
{
$application = new CLI('test', null, 'test');
$application->command(new module_console_taskState('system:taskState'));
$command = $application['console']->find('system:taskState');
$commandTester = new CommandTester($command);
// test a bad argument
$commandTester->execute(array('command' => $command->getName(), 'task_id' => 'not_a_number'));
$sentence = 'Argument must be an ID';
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
$commandTester->execute(array('command' => $command->getName(), 'task_id' => 'not_a_number', '--short' => true));
$sentence = 'bad_id';
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
// test good tasks ids
$task_manager = self::$DI['app']['task-manager'];
$tasks = $task_manager->getTasks();
$tids = array(); // list known ids of tasks so we can generate a 'unknown id' later
foreach ($tasks as $task) {
$tids[] = $task->getID();
$task = $task_manager->getTask($task->getID());
$state = $task->getState();
$pid = $task->getPID();
$commandTester->execute(array('command' => $command->getName(), 'task_id' => $task->getID()));
$sentence = sprintf('Task %d is %s', $task->getID(), $state);
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
$commandTester->execute(array('command' => $command->getName(), 'task_id' => $task->getID(), '--short' => true));
$sentence = sprintf('%s(%s)', $state, ($pid !== NULL ? $pid : ''));
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
}
// test an unknown id
for ($badid = 999; in_array($badid, $tids); $badid += 10) {
;
}
/* we may not test the 'long' error message since it comes from the upper level exception and might be translated
$commandTester->execute(array('command' => $command->getName(), 'task_id' => $badid));
$sentence = sprintf('Unknown task_id %d', $task->getID());
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
*/
$commandTester->execute(array('command' => $command->getName(), 'task_id' => $badid, '--short' => true));
$sentence = 'unknown_id';
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
}
}