From ec0ecc5b0387924f061865f4ec12dbfc5b7018fe Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 17 Jul 2016 17:15:14 -0400 Subject: Added event for removed comments with some refactoring --- tests/units/Job/CommentEventJobTest.php | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/units/Job/CommentEventJobTest.php (limited to 'tests/units/Job/CommentEventJobTest.php') diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php new file mode 100644 index 00000000..88742feb --- /dev/null +++ b/tests/units/Job/CommentEventJobTest.php @@ -0,0 +1,52 @@ +container); + $commentEventJob->withParams(123, 'foobar'); + + $this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams()); + } + + public function testWithMissingComment() + { + $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {}); + + $commentEventJob = new CommentEventJob($this->container); + $commentEventJob->execute(42, CommentModel::EVENT_CREATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerEvents() + { + $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {}); + $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {}); + $this->container['dispatcher']->addListener(CommentModel::EVENT_REMOVE, function() {}); + + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1))); + $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test'))); + $this->assertTrue($commentModel->remove(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called); + $this->assertArrayHasKey(CommentModel::EVENT_REMOVE.'.closure', $called); + } +} -- cgit v1.2.3 From 3dd20c9c78e61028a4c7db232c7b2b30662a2987 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 20 Jul 2016 21:47:23 -0400 Subject: Rename CommentModel::EVENT_REMOVE to CommentModel::EVENT_DELETE --- app/Model/CommentModel.php | 4 ++-- app/Model/NotificationModel.php | 6 +++--- app/Subscriber/NotificationSubscriber.php | 2 +- app/Template/event/comment_delete.php | 11 +++++++++++ app/Template/event/comment_remove.php | 11 ----------- app/Template/notification/comment_delete.php | 7 +++++++ app/Template/notification/comment_remove.php | 7 ------- tests/units/Job/CommentEventJobTest.php | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 app/Template/event/comment_delete.php delete mode 100644 app/Template/event/comment_remove.php create mode 100644 app/Template/notification/comment_delete.php delete mode 100644 app/Template/notification/comment_remove.php (limited to 'tests/units/Job/CommentEventJobTest.php') diff --git a/app/Model/CommentModel.php b/app/Model/CommentModel.php index 6b983858..a9e48bd3 100644 --- a/app/Model/CommentModel.php +++ b/app/Model/CommentModel.php @@ -26,7 +26,7 @@ class CommentModel extends Base */ const EVENT_UPDATE = 'comment.update'; const EVENT_CREATE = 'comment.create'; - const EVENT_REMOVE = 'comment.remove'; + const EVENT_DELETE = 'comment.delete'; const EVENT_USER_MENTION = 'comment.user.mention'; /** @@ -166,7 +166,7 @@ class CommentModel extends Base */ public function remove($comment_id) { - $this->commentEventJob->execute($comment_id, self::EVENT_REMOVE); + $this->commentEventJob->execute($comment_id, self::EVENT_DELETE); return $this->db->table(self::TABLE)->eq('id', $comment_id)->remove(); } } diff --git a/app/Model/NotificationModel.php b/app/Model/NotificationModel.php index ac8d9bae..925d646e 100644 --- a/app/Model/NotificationModel.php +++ b/app/Model/NotificationModel.php @@ -76,7 +76,7 @@ class NotificationModel extends Base return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']); case CommentModel::EVENT_CREATE: return e('%s commented on the task #%d', $event_author, $event_data['task']['id']); - case CommentModel::EVENT_REMOVE: + case CommentModel::EVENT_DELETE: return e('%s removed a comment on the task #%d', $event_author, $event_data['task']['id']); case TaskFileModel::EVENT_CREATE: return e('%s attached a file to the task #%d', $event_author, $event_data['task']['id']); @@ -106,7 +106,7 @@ class NotificationModel extends Base return e('New comment on task #%d', $event_data['comment']['task_id']); case CommentModel::EVENT_UPDATE: return e('Comment updated on task #%d', $event_data['comment']['task_id']); - case CommentModel::EVENT_REMOVE: + case CommentModel::EVENT_DELETE: return e('Comment removed on task #%d', $event_data['comment']['task_id']); case SubtaskModel::EVENT_CREATE: return e('New subtask on task #%d', $event_data['subtask']['task_id']); @@ -157,7 +157,7 @@ class NotificationModel extends Base return $event_data['file']['task_id']; case CommentModel::EVENT_CREATE: case CommentModel::EVENT_UPDATE: - case CommentModel::EVENT_REMOVE: + case CommentModel::EVENT_DELETE: return $event_data['comment']['task_id']; case SubtaskModel::EVENT_CREATE: case SubtaskModel::EVENT_UPDATE: diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php index 104927a0..7de24e49 100644 --- a/app/Subscriber/NotificationSubscriber.php +++ b/app/Subscriber/NotificationSubscriber.php @@ -28,7 +28,7 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn SubtaskModel::EVENT_DELETE => 'handleEvent', CommentModel::EVENT_CREATE => 'handleEvent', CommentModel::EVENT_UPDATE => 'handleEvent', - CommentModel::EVENT_REMOVE => 'handleEvent', + CommentModel::EVENT_DELETE => 'handleEvent', CommentModel::EVENT_USER_MENTION => 'handleEvent', TaskFileModel::EVENT_CREATE => 'handleEvent', ); diff --git a/app/Template/event/comment_delete.php b/app/Template/event/comment_delete.php new file mode 100644 index 00000000..ead7d56a --- /dev/null +++ b/app/Template/event/comment_delete.php @@ -0,0 +1,11 @@ +

+ text->e($author), + $this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) + ) ?> + dt->datetime($date_creation) ?> +

+
+

text->e($task['title']) ?>

+
text->markdown($comment['comment']) ?>
+
diff --git a/app/Template/event/comment_remove.php b/app/Template/event/comment_remove.php deleted file mode 100644 index ead7d56a..00000000 --- a/app/Template/event/comment_remove.php +++ /dev/null @@ -1,11 +0,0 @@ -

- text->e($author), - $this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) - ) ?> - dt->datetime($date_creation) ?> -

-
-

text->e($task['title']) ?>

-
text->markdown($comment['comment']) ?>
-
diff --git a/app/Template/notification/comment_delete.php b/app/Template/notification/comment_delete.php new file mode 100644 index 00000000..928623ec --- /dev/null +++ b/app/Template/notification/comment_delete.php @@ -0,0 +1,7 @@ +

text->e($task['title']) ?> (#)

+ +

+ +text->markdown($comment['comment']) ?> + +render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?> diff --git a/app/Template/notification/comment_remove.php b/app/Template/notification/comment_remove.php deleted file mode 100644 index 928623ec..00000000 --- a/app/Template/notification/comment_remove.php +++ /dev/null @@ -1,7 +0,0 @@ -

text->e($task['title']) ?> (#)

- -

- -text->markdown($comment['comment']) ?> - -render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?> diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php index 88742feb..8571af8e 100644 --- a/tests/units/Job/CommentEventJobTest.php +++ b/tests/units/Job/CommentEventJobTest.php @@ -32,7 +32,7 @@ class CommentEventJobTest extends Base { $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {}); $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {}); - $this->container['dispatcher']->addListener(CommentModel::EVENT_REMOVE, function() {}); + $this->container['dispatcher']->addListener(CommentModel::EVENT_DELETE, function() {}); $commentModel = new CommentModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); @@ -47,6 +47,6 @@ class CommentEventJobTest extends Base $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called); $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called); - $this->assertArrayHasKey(CommentModel::EVENT_REMOVE.'.closure', $called); + $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called); } } -- cgit v1.2.3