diff options
Diffstat (limited to 'tests/units/TaskCreationTest.php')
-rw-r--r-- | tests/units/TaskCreationTest.php | 34 |
1 files changed, 28 insertions, 6 deletions
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); |