diff options
Diffstat (limited to 'tests/units/TaskModificationTest.php')
-rw-r--r-- | tests/units/TaskModificationTest.php | 54 |
1 files changed, 41 insertions, 13 deletions
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']); |