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

@@ -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);