Move events handling to Symfony\EventDispatcher

This commit is contained in:
Frédéric Guillot
2014-12-27 19:10:38 -05:00
parent cf821e117c
commit 17dc5bdc9e
75 changed files with 1076 additions and 1167 deletions

View File

@@ -25,7 +25,7 @@ class Api extends PHPUnit_Framework_TestCase
$pdo = new PDO('pgsql:host='.DB_HOSTNAME.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD);
}
$service = new ServiceProvider\Database;
$service = new ServiceProvider\DatabaseProvider;
$service->getInstance();
$pdo->exec("UPDATE settings SET value='".API_KEY."' WHERE option='api_token'");

View File

@@ -7,6 +7,7 @@ use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
use Event\GenericEvent;
class ActionTaskAssignColorCategory extends Base
{
@@ -21,7 +22,7 @@ class ActionTaskAssignColorCategory extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -51,7 +52,7 @@ class ActionTaskAssignColorCategory extends Base
);
// Our event should NOT be executed
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the ategory_id=1 and have the green color
$task = $tf->getById(1);
@@ -69,7 +70,7 @@ class ActionTaskAssignColorCategory extends Base
);
// Our event should be executed
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should have the blue color
$task = $tf->getById(1);

View File

@@ -6,6 +6,7 @@ use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Event\GenericEvent;
class ActionTaskAssignColorUser extends Base
{
@@ -20,7 +21,7 @@ class ActionTaskAssignColorUser extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -44,7 +45,7 @@ class ActionTaskAssignColorUser extends Base
);
// Our event should NOT be executed
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to nobody and have the green color
$task = $tf->getById(1);
@@ -60,7 +61,7 @@ class ActionTaskAssignColorUser extends Base
);
// Our event should be executed
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to nobody and have the blue color
$task = $tf->getById(1);

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
@@ -22,7 +23,7 @@ class ActionTaskAssignCurrentUser extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
@@ -36,7 +37,7 @@ class ActionTaskAssignCurrentUser extends Base
'column_id' => 3,
);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -65,7 +66,7 @@ class ActionTaskAssignCurrentUser extends Base
);
// Our event should be executed
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the user 5 (from the session)
$task = $tf->getById(1);

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
@@ -21,7 +22,7 @@ class ActionTaskAssignSpecificUser extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
@@ -35,7 +36,7 @@ class ActionTaskAssignSpecificUser extends Base
'column_id' => 3,
);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -59,7 +60,7 @@ class ActionTaskAssignSpecificUser extends Base
);
// Our event should be executed
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the user 1
$task = $tf->getById(1);

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
@@ -45,7 +46,7 @@ class ActionTaskCloseTest extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadProject()
@@ -60,7 +61,7 @@ class ActionTaskCloseTest extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
@@ -74,7 +75,7 @@ class ActionTaskCloseTest extends Base
'column_id' => 3,
);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -97,7 +98,7 @@ class ActionTaskCloseTest extends Base
);
// Our event should be executed
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be closed
$task = $tf->getById(1);

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
@@ -21,7 +22,7 @@ class ActionTaskDuplicateAnotherProject extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
@@ -35,7 +36,7 @@ class ActionTaskDuplicateAnotherProject extends Base
'column_id' => 3,
);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -60,7 +61,7 @@ class ActionTaskDuplicateAnotherProject extends Base
// Our event should NOT be executed because we define the same project
$action->setParam('column_id', 2);
$action->setParam('project_id', 1);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
@@ -78,7 +79,7 @@ class ActionTaskDuplicateAnotherProject extends Base
$action->setParam('column_id', 2);
$action->setParam('project_id', 2);
$this->assertTrue($action->hasRequiredCondition($event));
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
@@ -21,7 +22,7 @@ class ActionTaskMoveAnotherProject extends Base
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
@@ -35,7 +36,7 @@ class ActionTaskMoveAnotherProject extends Base
'column_id' => 3,
);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
@@ -60,7 +61,7 @@ class ActionTaskMoveAnotherProject extends Base
// Our event should NOT be executed because we define the same project
$action->setParam('column_id', 2);
$action->setParam('project_id', 1);
$this->assertFalse($action->execute($event));
$this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
@@ -77,7 +78,7 @@ class ActionTaskMoveAnotherProject extends Base
// Our event should be executed because we define a different project
$action->setParam('column_id', 2);
$action->setParam('project_id', 2);
$this->assertTrue($action->execute($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 2
$task = $tf->getById(1);

View File

@@ -10,46 +10,11 @@ use Model\TaskPosition;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Category;
use Model\GithubWebhook;
class ActionTest extends Base
{/*
public function testFetchActions()
{
$action = new Action($this->container);
$board = new Board($this->container);
$project = new Project($this->container);
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
// We should have nothing
$this->assertEmpty($action->getAll());
$this->assertEmpty($action->getAllByProject(1));
// We create a new action
$this->assertTrue($action->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_COLUMN,
'action_name' => 'TaskClose',
'params' => array(
'column_id' => 4,
)
)));
// We should have our action
$this->assertNotEmpty($action->getAll());
$this->assertEquals($action->getAll(), $action->getAllByProject(1));
$actions = $action->getAll();
$this->assertEquals(1, count($actions));
$this->assertEquals(1, $actions[0]['project_id']);
$this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
$this->assertEquals('TaskClose', $actions[0]['action_name']);
$this->assertEquals('column_id', $actions[0]['params'][0]['name']);
$this->assertEquals(4, $actions[0]['params'][0]['value']);
}
public function testEventMoveColumn()
public function testSingleAction()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
@@ -61,15 +26,6 @@ class ActionTest extends Base
// We create a project
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
// We create a task
$this->assertEquals(1, $tc->create(array(
'title' => 'unit_test',
'project_id' => 1,
'owner_id' => 1,
'color_id' => 'red',
'column_id' => 1,
)));
// We create a new action
$this->assertTrue($action->create(array(
'project_id' => 1,
@@ -80,7 +36,16 @@ class ActionTest extends Base
)
)));
// We bind events
// We create a task
$this->assertEquals(1, $tc->create(array(
'title' => 'unit_test',
'project_id' => 1,
'owner_id' => 1,
'color_id' => 'red',
'column_id' => 1,
)));
// We attach events
$action->attachEvents();
// Our task should be open
@@ -91,87 +56,86 @@ class ActionTest extends Base
// We move our task
$tp->movePosition(1, 1, 4, 1);
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
// Our task should be closed
$t1 = $tf->getById(1);
$this->assertEquals(4, $t1['column_id']);
$this->assertEquals(0, $t1['is_active']);
}
*/
public function testExecuteMultipleActions()
public function testMultipleActions()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$board = new Board($this->container);
$project = new Project($this->container);
$action = new Action($this->container);
$b = new Board($this->container);
$p = new Project($this->container);
$a = new Action($this->container);
$c = new Category($this->container);
$g = new GithubWebhook($this->container);
// We create 2 projects
$this->assertEquals(1, $project->create(array('name' => 'unit_test1')));
$this->assertEquals(2, $project->create(array('name' => 'unit_test2')));
// We create a project
$this->assertEquals(1, $p->create(array('name' => 'unit_test')));
$this->assertEquals(1, $c->create(array('name' => 'unit_test')));
// We create a task
$this->assertEquals(1, $tc->create(array(
'title' => 'unit_test',
// We create a new action
$this->assertTrue($a->create(array(
'project_id' => 1,
'owner_id' => 1,
'color_id' => 'red',
'column_id' => 1,
'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
'action_name' => 'TaskCreation',
'params' => array()
)));
// We create 2 actions
$this->assertTrue($action->create(array(
$this->assertTrue($a->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_CLOSE,
'action_name' => 'TaskDuplicateAnotherProject',
'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
'action_name' => 'TaskAssignCategoryLabel',
'params' => array(
'column_id' => 4,
'project_id' => 2,
'label' => 'bug',
'category_id' => 1,
)
)));
$this->assertTrue($action->create(array(
$this->assertTrue($a->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_COLUMN,
'action_name' => 'TaskClose',
'event_name' => Task::EVENT_CREATE_UPDATE,
'action_name' => 'TaskAssignColorCategory',
'params' => array(
'column_id' => 4,
'color_id' => 'red',
'category_id' => 1,
)
)));
// We bind events
$action->attachEvents();
// We attach events
$a->attachEvents();
$g->setProjectId(1);
// Events should be attached
$this->assertTrue($this->container['event']->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
$this->assertTrue($this->container['event']->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
// We create a Github issue
$issue = array(
'number' => 123,
'title' => 'Bugs everywhere',
'body' => 'There is a bug!',
'html_url' => 'http://localhost/',
);
// Our task should be open, linked to the first project and in the first column
$t1 = $tf->getById(1);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals(1, $t1['column_id']);
$this->assertEquals(1, $t1['project_id']);
$this->assertTrue($g->handleIssueOpened($issue));
// We move our task
$tp->movePosition(1, 1, 4, 1);
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['is_active']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals('yellow', $task['color_id']);
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
// We assign a label to our issue
$label = array(
'name' => 'bug',
);
// Our task should be closed
$t1 = $tf->getById(1);
$this->assertEquals(4, $t1['column_id']);
$this->assertEquals(0, $t1['is_active']);
$this->assertTrue($g->handleIssueLabeled($issue, $label));
// Our task should be duplicated to the 2nd project
$t2 = $tf->getById(2);
$this->assertNotEmpty($t2);
$this->assertNotEquals(4, $t2['column_id']);
$this->assertEquals(1, $t2['is_active']);
$this->assertEquals(2, $t2['project_id']);
$this->assertEquals('unit_test', $t2['title']);
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['is_active']);
$this->assertEquals(1, $task['category_id']);
$this->assertEquals('red', $task['color_id']);
}
}

View File

@@ -3,6 +3,10 @@
require __DIR__.'/../../vendor/autoload.php';
require __DIR__.'/../../app/constants.php';
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
use Symfony\Component\Stopwatch\Stopwatch;
date_default_timezone_set('UTC');
abstract class Base extends PHPUnit_Framework_TestCase
@@ -23,8 +27,13 @@ abstract class Base extends PHPUnit_Framework_TestCase
}
$this->container = new Pimple\Container;
$this->container->register(new ServiceProvider\Database);
$this->container->register(new ServiceProvider\Event);
$this->container->register(new ServiceProvider\DatabaseProvider);
$this->container->register(new ServiceProvider\ModelProvider);
$this->container['dispatcher'] = new TraceableEventDispatcher(
new EventDispatcher,
new Stopwatch
);
}
public function tearDown()

View File

@@ -2,6 +2,7 @@
require_once __DIR__.'/Base.php';
use Subscriber\ProjectModificationDateSubscriber;
use Model\Project;
use Model\ProjectPermission;
use Model\User;
@@ -52,7 +53,6 @@ class ProjectTest extends Base
$tc = new TaskCreation($this->container);
$now = time();
$p->attachEvents();
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -62,9 +62,13 @@ class ProjectTest extends Base
sleep(1);
$listener = new ProjectModificationDateSubscriber($this->container);
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($listener, 'execute'));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertEquals('Event\ProjectModificationDateListener', $this->container['event']->getLastListenerExecuted());
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.Subscriber\ProjectModificationDateSubscriber::execute', $called);
$project = $p->getById(1);
$this->assertNotEmpty($project);

View File

@@ -11,17 +11,31 @@ use Model\ProjectPermission;
class TaskCreationTest extends Base
{
public function onCreate($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('test', $event_data['title']);
}
public function testNoProjectId()
{
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0)));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called);
}
public function testNoTitle()
@@ -30,11 +44,15 @@ class TaskCreationTest extends Base
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(0, $tc->create(array('project_id' => 1)));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called);
}
public function testMinimum()
@@ -43,11 +61,15 @@ class TaskCreationTest extends Base
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, array($this, 'onCreate'));
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(Task::EVENT_CREATE.'.TaskCreationTest::onCreate', $called);
$task = $tf->getById(1);
$this->assertNotEmpty($task);

View File

@@ -45,10 +45,15 @@ class TaskDuplicationTest extends Base
$this->assertEquals(2, $task['category_id']);
$this->assertEquals(4.4, $task['time_spent']);
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
// We duplicate our task
$this->assertEquals(2, $td->duplicate(1));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -82,10 +87,15 @@ class TaskDuplicationTest extends Base
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -121,8 +131,6 @@ class TaskDuplicationTest extends Base
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -156,8 +164,6 @@ class TaskDuplicationTest extends Base
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -191,8 +197,6 @@ class TaskDuplicationTest extends Base
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -223,8 +227,6 @@ class TaskDuplicationTest extends Base
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -265,6 +267,16 @@ class TaskDuplicationTest extends Base
$this->assertEquals(5, $task['column_id']);
}
public function onMoveProject($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('test', $event_data['title']);
}
public function testMoveAnotherProject()
{
$td = new TaskDuplication($this->container);
@@ -281,9 +293,14 @@ class TaskDuplicationTest extends Base
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
// We duplicate our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);

View File

@@ -12,6 +12,36 @@ use Model\ProjectPermission;
class TaskModificationTest extends Base
{
public function onCreateUpdate($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('Task #1', $event_data['title']);
}
public function onUpdate($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('Task #1', $event_data['title']);
}
public function onAssigneeChange($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['owner_id']);
}
public function testChangeTitle()
{
$p = new Project($this->container);
@@ -21,15 +51,15 @@ class TaskModificationTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
$this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate'));
$this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
$event_data = $this->container['event']->getEventData(Task::EVENT_UPDATE);
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('Task #1', $event_data['title']);
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called);
$this->assertArrayHasKey(Task::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called);
$task = $tf->getById(1);
$this->assertEquals('Task #1', $task['title']);
@@ -48,14 +78,12 @@ class TaskModificationTest extends Base
$task = $tf->getById(1);
$this->assertEquals(0, $task['owner_id']);
$this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
$this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
$event_data = $this->container['event']->getEventData(Task::EVENT_ASSIGNEE_CHANGE);
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['owner_id']);
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called);
$task = $tf->getById(1);
$this->assertEquals(1, $task['owner_id']);

View File

@@ -73,8 +73,6 @@ class TaskPositionTest extends Base
// We move the task 3 to the column 3
$this->assertTrue($tp->movePosition(1, 3, 3, 2));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
// Check tasks position
$task = $tf->getById(1);
@@ -470,6 +468,10 @@ class TaskPositionTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn'));
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition'));
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane'));
// We move the task 1 to the column 2
$this->assertTrue($tp->movePosition(1, 1, 2, 1));
@@ -483,18 +485,9 @@ class TaskPositionTest extends Base
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_SWIMLANE));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
$event_data = $this->container['event']->getEventData(Task::EVENT_MOVE_COLUMN);
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['position']);
$this->assertEquals(2, $event_data['column_id']);
$this->assertEquals(1, $event_data['project_id']);
$this->container['event']->clearTriggeredEvents();
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
$this->assertEquals(1, count($called));
// We move the task 1 to the position 2
$this->assertTrue($tp->movePosition(1, 1, 2, 2));
@@ -509,18 +502,9 @@ class TaskPositionTest extends Base
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_SWIMLANE));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
$event_data = $this->container['event']->getEventData(Task::EVENT_MOVE_POSITION);
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(2, $event_data['position']);
$this->assertEquals(2, $event_data['column_id']);
$this->assertEquals(1, $event_data['project_id']);
$this->container['event']->clearTriggeredEvents();
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
$this->assertEquals(2, count($called));
// Move to another swimlane
$this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
@@ -537,11 +521,40 @@ class TaskPositionTest extends Base
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_SWIMLANE));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
$this->assertEquals(3, count($called));
}
$event_data = $this->container['event']->getEventData(Task::EVENT_MOVE_SWIMLANE);
public function onMoveColumn($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['position']);
$this->assertEquals(2, $event_data['column_id']);
$this->assertEquals(1, $event_data['project_id']);
}
public function onMovePosition($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(2, $event_data['position']);
$this->assertEquals(2, $event_data['column_id']);
$this->assertEquals(1, $event_data['project_id']);
}
public function onMoveSwimlane($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['position']);

View File

@@ -33,6 +33,9 @@ class TaskStatusTest extends Base
// We close the task
$this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose'));
$this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen'));
$this->assertTrue($ts->close(1));
$this->assertTrue($ts->isClosed(1));
@@ -42,8 +45,6 @@ class TaskStatusTest extends Base
$this->assertEquals(time(), $task['date_completed']);
$this->assertEquals(time(), $task['date_modification']);
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
// We open the task again
$this->assertTrue($ts->open(1));
@@ -55,6 +56,22 @@ class TaskStatusTest extends Base
$this->assertEquals(0, $task['date_completed']);
$this->assertEquals(time(), $task['date_modification']);
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_OPEN));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey('task.close.TaskStatusTest::onTaskClose', $called);
$this->assertArrayHasKey('task.open.TaskStatusTest::onTaskOpen', $called);
}
public function onTaskOpen($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$this->assertArrayHasKey('task_id', $event);
$this->assertNotEmpty($event['task_id']);
}
public function onTaskClose($event)
{
$this->assertInstanceOf('Event\TaskEvent', $event);
$this->assertArrayHasKey('task_id', $event);
$this->assertNotEmpty($event['task_id']);
}
}