summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-12-27 19:10:38 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-12-27 19:10:38 -0500
commit17dc5bdc9ede52ad618bbf326e67e3b6988170f7 (patch)
tree9cf4d325667f11fa735bca84042fb385e3273329 /tests/units
parentcf821e117ce8b937cff7f386a107aaa81ba6bf9b (diff)
Move events handling to Symfony\EventDispatcher
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/ActionTaskAssignColorCategoryTest.php7
-rw-r--r--tests/units/ActionTaskAssignColorUserTest.php7
-rw-r--r--tests/units/ActionTaskAssignCurrentUserTest.php7
-rw-r--r--tests/units/ActionTaskAssignSpecificUserTest.php7
-rw-r--r--tests/units/ActionTaskCloseTest.php9
-rw-r--r--tests/units/ActionTaskDuplicateAnotherProjectTest.php9
-rw-r--r--tests/units/ActionTaskMoveAnotherProjectTest.php9
-rw-r--r--tests/units/ActionTest.php164
-rw-r--r--tests/units/Base.php13
-rw-r--r--tests/units/ProjectTest.php10
-rw-r--r--tests/units/TaskCreationTest.php34
-rw-r--r--tests/units/TaskDuplicationTest.php41
-rw-r--r--tests/units/TaskModificationTest.php54
-rw-r--r--tests/units/TaskPositionTest.php73
-rw-r--r--tests/units/TaskStatusTest.php23
15 files changed, 274 insertions, 193 deletions
diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php
index ff41a4b9..c9665268 100644
--- a/tests/units/ActionTaskAssignColorCategoryTest.php
+++ b/tests/units/ActionTaskAssignColorCategoryTest.php
@@ -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);
diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php
index d41a5ef4..c1bf3a34 100644
--- a/tests/units/ActionTaskAssignColorUserTest.php
+++ b/tests/units/ActionTaskAssignColorUserTest.php
@@ -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);
diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php
index afc659ce..374277ce 100644
--- a/tests/units/ActionTaskAssignCurrentUserTest.php
+++ b/tests/units/ActionTaskAssignCurrentUserTest.php
@@ -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);
diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php
index 07fa1e25..ac054ba6 100644
--- a/tests/units/ActionTaskAssignSpecificUserTest.php
+++ b/tests/units/ActionTaskAssignSpecificUserTest.php
@@ -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);
diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php
index fd4f752d..a5087af0 100644
--- a/tests/units/ActionTaskCloseTest.php
+++ b/tests/units/ActionTaskCloseTest.php
@@ -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);
diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
index d7f9d2c3..10c7c36a 100644
--- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php
+++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
@@ -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);
diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php
index 605c3e55..3f0c3de6 100644
--- a/tests/units/ActionTaskMoveAnotherProjectTest.php
+++ b/tests/units/ActionTaskMoveAnotherProjectTest.php
@@ -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);
diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php
index 84f383f7..77a939e0 100644
--- a/tests/units/ActionTest.php
+++ b/tests/units/ActionTest.php
@@ -10,21 +10,22 @@ use Model\TaskPosition;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Category;
+use Model\GithubWebhook;
class ActionTest extends Base
{/*
- public function testFetchActions()
+ public function testSingleAction()
{
- $action = new Action($this->container);
+ $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);
+ // We create a project
$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,
@@ -35,32 +36,6 @@ class ActionTest extends Base
)
)));
- // 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()
- {
- $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);
-
- // 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',
@@ -70,17 +45,7 @@ class ActionTest extends Base
'column_id' => 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 bind events
+ // 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();
-
- // 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'));
-
- // 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']);
-
- // We move our task
- $tp->movePosition(1, 1, 4, 1);
-
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
-
- // Our task should be closed
- $t1 = $tf->getById(1);
- $this->assertEquals(4, $t1['column_id']);
- $this->assertEquals(0, $t1['is_active']);
-
- // 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']);
+ // We attach events
+ $a->attachEvents();
+ $g->setProjectId(1);
+
+ // We create a Github issue
+ $issue = array(
+ 'number' => 123,
+ 'title' => 'Bugs everywhere',
+ 'body' => 'There is a bug!',
+ 'html_url' => 'http://localhost/',
+ );
+
+ $this->assertTrue($g->handleIssueOpened($issue));
+
+ $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']);
+
+ // We assign a label to our issue
+ $label = array(
+ 'name' => 'bug',
+ );
+
+ $this->assertTrue($g->handleIssueLabeled($issue, $label));
+
+ $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']);
}
}
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 27960610..3e491969 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -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()
diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php
index 5fff8ad6..31481d96 100644
--- a/tests/units/ProjectTest.php
+++ b/tests/units/ProjectTest.php
@@ -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);
diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php
index 48742a19..41a3f276 100644
--- a/tests/units/TaskCreationTest.php
+++ b/tests/units/TaskCreationTest.php
@@ -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);
diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php
index 7b2983f8..6f1ee0e2 100644
--- a/tests/units/TaskDuplicationTest.php
+++ b/tests/units/TaskDuplicationTest.php
@@ -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);
diff --git a/tests/units/TaskModificationTest.php b/tests/units/TaskModificationTest.php
index 9217c582..e6d8f8dc 100644
--- a/tests/units/TaskModificationTest.php
+++ b/tests/units/TaskModificationTest.php
@@ -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->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));
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate'));
- $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']);
+ $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
+
+ $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->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
+ $this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
+ $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
- $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']);
diff --git a/tests/units/TaskPositionTest.php b/tests/units/TaskPositionTest.php
index dbc6c74b..21f1fd62 100644
--- a/tests/units/TaskPositionTest.php
+++ b/tests/units/TaskPositionTest.php
@@ -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));
+ }
+
+ 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 = $this->container['event']->getEventData(Task::EVENT_MOVE_SWIMLANE);
+ $event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals(1, $event_data['position']);
diff --git a/tests/units/TaskStatusTest.php b/tests/units/TaskStatusTest.php
index f2847bda..b1c3f695 100644
--- a/tests/units/TaskStatusTest.php
+++ b/tests/units/TaskStatusTest.php
@@ -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']);
}
}