mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Model\Manipulator;
|
|
|
|
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
|
|
use Entities\Task;
|
|
|
|
class TaskManipulatorTest extends \PhraseanetPHPUnitAbstract
|
|
{
|
|
private function findAllTasks()
|
|
{
|
|
return self::$DI['app']['EM']->getRepository('Entities\Task')->findAll();
|
|
}
|
|
|
|
private function loadTask()
|
|
{
|
|
$task = new Task();
|
|
$task
|
|
->setName('test')
|
|
->setClassname('SuperSpace');
|
|
|
|
self::$DI['app']['EM']->persist($task);
|
|
self::$DI['app']['EM']->flush();
|
|
|
|
return $task;
|
|
}
|
|
|
|
public function testCreate()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$this->assertCount(0, $this->findAllTasks());
|
|
$task = $manipulator->create('prout', 'bla bla', 'super settings', 0);
|
|
$this->assertEquals('prout', $task->getName());
|
|
$this->assertEquals('bla bla', $task->getClassname());
|
|
$this->assertEquals('super settings', $task->getSettings());
|
|
$this->assertEquals(0, $task->getPeriod());
|
|
$this->assertSame(array($task), $this->findAllTasks());
|
|
|
|
return $task;
|
|
}
|
|
|
|
public function testUpdate()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$task = $this->loadTask();
|
|
$task->setName('new name');
|
|
$this->assertSame($task, $manipulator->update($task));
|
|
self::$DI['app']['EM']->clear();
|
|
$this->assertEquals(array($task), $this->findAllTasks());
|
|
}
|
|
|
|
public function testDelete()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$task = $this->loadTask();
|
|
$manipulator->delete($task);
|
|
$this->assertEquals(array(), $this->findAllTasks());
|
|
}
|
|
|
|
public function testStart()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$task = $this->loadTask();
|
|
$task->setStatus(Task::STATUS_STOPPED);
|
|
$manipulator->update($task);
|
|
$manipulator->start($task);
|
|
$this->assertEquals(Task::STATUS_STARTED, $task->getStatus());
|
|
}
|
|
|
|
public function testStop()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$task = $this->loadTask();
|
|
$task->setStatus(Task::STATUS_STARTED);
|
|
$manipulator->update($task);
|
|
$manipulator->stop($task);
|
|
$this->assertEquals(Task::STATUS_STOPPED, $task->getStatus());
|
|
}
|
|
|
|
public function testResetCrashes()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$task = $this->loadTask();
|
|
$task->setCrashed(42);
|
|
$manipulator->resetCrashes($task);
|
|
$this->assertEquals(0, $task->getCrashed());
|
|
}
|
|
|
|
public function testGetRepository()
|
|
{
|
|
$manipulator = new TaskManipulator(self::$DI['app']['EM']);
|
|
$this->assertSame(self::$DI['app']['EM']->getRepository('Entities\Task'), $manipulator->getRepository());
|
|
}
|
|
}
|