summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-23 14:05:15 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-23 14:05:15 -0400
commitb6119e7dee84869a619dedccd9c80df4422a4f5b (patch)
tree8487400f592d2c66dba91a9ce4f03b4ae657a0c2
parent5fe81ae6ef59ee73e7d6f34fb333d3d19a08a266 (diff)
Added internal task links to activity stream
-rw-r--r--ChangeLog1
-rw-r--r--app/Action/TaskAssignCategoryLink.php13
-rw-r--r--app/Action/TaskAssignColorLink.php10
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/EventBuilder/TaskLinkEventBuilder.php89
-rw-r--r--app/Helper/HookHelper.php2
-rw-r--r--app/Job/TaskLinkEventJob.php45
-rw-r--r--app/Model/NotificationModel.php39
-rw-r--r--app/Model/TaskLinkModel.php173
-rw-r--r--app/ServiceProvider/JobProvider.php5
-rw-r--r--app/Subscriber/NotificationSubscriber.php3
-rw-r--r--app/Template/event/task_internal_link_create_update.php16
-rw-r--r--app/Template/event/task_internal_link_delete.php16
-rw-r--r--app/Template/notification/task_file_create.php2
-rw-r--r--app/Template/notification/task_internal_link_create_update.php11
-rw-r--r--app/Template/notification/task_internal_link_delete.php11
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php51
-rw-r--r--tests/units/Action/TaskAssignColorLinkTest.php45
-rw-r--r--tests/units/EventBuilder/TaskLinkEventBuilderTest.php70
-rw-r--r--tests/units/Job/TaskLinkEventJobTest.php65
-rw-r--r--tests/units/Model/NotificationModelTest.php39
-rw-r--r--tests/units/Model/TaskLinkModelTest.php28
-rw-r--r--tests/units/Notification/MailNotificationTest.php117
-rw-r--r--tests/units/Notification/MailTest.php117
-rw-r--r--tests/units/Notification/WebhookNotificationTest.php (renamed from tests/units/Notification/WebhookTest.php)14
25 files changed, 683 insertions, 300 deletions
diff --git a/ChangeLog b/ChangeLog
index a1e39436..ee57c86c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ Version 1.0.32 (unreleased)
New features:
* New automated action to close tasks without activity in a specific column
+* Added internal task links to activity stream
* Added new event for removed comments
* Added search filter for task priority
* Added the possibility to hide tasks in dashboard for a specific column
diff --git a/app/Action/TaskAssignCategoryLink.php b/app/Action/TaskAssignCategoryLink.php
index 6937edd1..d4a4c0ec 100644
--- a/app/Action/TaskAssignCategoryLink.php
+++ b/app/Action/TaskAssignCategoryLink.php
@@ -60,8 +60,10 @@ class TaskAssignCategoryLink extends Base
public function getEventRequiredParameters()
{
return array(
- 'task_id',
- 'link_id',
+ 'task_link' => array(
+ 'task_id',
+ 'link_id',
+ )
);
}
@@ -75,7 +77,7 @@ class TaskAssignCategoryLink extends Base
public function doAction(array $data)
{
$values = array(
- 'id' => $data['task_id'],
+ 'id' => $data['task_link']['task_id'],
'category_id' => $this->getParam('category_id'),
);
@@ -91,9 +93,8 @@ class TaskAssignCategoryLink extends Base
*/
public function hasRequiredCondition(array $data)
{
- if ($data['link_id'] == $this->getParam('link_id')) {
- $task = $this->taskFinderModel->getById($data['task_id']);
- return empty($task['category_id']);
+ if ($data['task_link']['link_id'] == $this->getParam('link_id')) {
+ return empty($data['task']['category_id']);
}
return false;
diff --git a/app/Action/TaskAssignColorLink.php b/app/Action/TaskAssignColorLink.php
index 9ab5458b..9759f622 100644
--- a/app/Action/TaskAssignColorLink.php
+++ b/app/Action/TaskAssignColorLink.php
@@ -59,8 +59,10 @@ class TaskAssignColorLink extends Base
public function getEventRequiredParameters()
{
return array(
- 'task_id',
- 'link_id',
+ 'task_link' => array(
+ 'task_id',
+ 'link_id',
+ )
);
}
@@ -74,7 +76,7 @@ class TaskAssignColorLink extends Base
public function doAction(array $data)
{
$values = array(
- 'id' => $data['task_id'],
+ 'id' => $data['task_link']['task_id'],
'color_id' => $this->getParam('color_id'),
);
@@ -90,6 +92,6 @@ class TaskAssignColorLink extends Base
*/
public function hasRequiredCondition(array $data)
{
- return $data['link_id'] == $this->getParam('link_id');
+ return $data['task_link']['link_id'] == $this->getParam('link_id');
}
}
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 098bd880..20a2d391 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -154,6 +154,7 @@ use Pimple\Container;
* @property \Kanboard\Job\SubtaskEventJob $subtaskEventJob
* @property \Kanboard\Job\TaskEventJob $taskEventJob
* @property \Kanboard\Job\TaskFileEventJob $taskFileEventJob
+ * @property \Kanboard\Job\TaskLinkEventJob $taskLinkEventJob
* @property \Kanboard\Job\ProjectFileEventJob $projectFileEventJob
* @property \Kanboard\Job\NotificationJob $notificationJob
* @property \Psr\Log\LoggerInterface $logger
diff --git a/app/EventBuilder/TaskLinkEventBuilder.php b/app/EventBuilder/TaskLinkEventBuilder.php
new file mode 100644
index 00000000..8be5299f
--- /dev/null
+++ b/app/EventBuilder/TaskLinkEventBuilder.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Kanboard\EventBuilder;
+
+use Kanboard\Event\TaskLinkEvent;
+use Kanboard\Model\TaskLinkModel;
+
+/**
+ * Class TaskLinkEventBuilder
+ *
+ * @package Kanboard\EventBuilder
+ * @author Frederic Guillot
+ */
+class TaskLinkEventBuilder extends BaseEventBuilder
+{
+ protected $taskLinkId = 0;
+
+ /**
+ * Set taskLinkId
+ *
+ * @param int $taskLinkId
+ * @return $this
+ */
+ public function withTaskLinkId($taskLinkId)
+ {
+ $this->taskLinkId = $taskLinkId;
+ return $this;
+ }
+
+ /**
+ * Build event data
+ *
+ * @access public
+ * @return TaskLinkEvent|null
+ */
+ public function build()
+ {
+ $taskLink = $this->taskLinkModel->getById($this->taskLinkId);
+
+ if (empty($taskLink)) {
+ $this->logger->debug(__METHOD__.': TaskLink not found');
+ return null;
+ }
+
+ return new TaskLinkEvent(array(
+ 'task_link' => $taskLink,
+ 'task' => $this->taskFinderModel->getDetails($taskLink['task_id']),
+ ));
+ }
+
+ /**
+ * Get event title with author
+ *
+ * @access public
+ * @param string $author
+ * @param string $eventName
+ * @param array $eventData
+ * @return string
+ */
+ public function buildTitleWithAuthor($author, $eventName, array $eventData)
+ {
+ if ($eventName === TaskLinkModel::EVENT_CREATE_UPDATE) {
+ return e('%s set a new internal link for the task #%d', $author, $eventData['task']['id']);
+ } elseif ($eventName === TaskLinkModel::EVENT_DELETE) {
+ return e('%s removed an internal link for the task #%d', $author, $eventData['task']['id']);
+ }
+
+ return '';
+ }
+
+ /**
+ * Get event title without author
+ *
+ * @access public
+ * @param string $eventName
+ * @param array $eventData
+ * @return string
+ */
+ public function buildTitleWithoutAuthor($eventName, array $eventData)
+ {
+ if ($eventName === TaskLinkModel::EVENT_CREATE_UPDATE) {
+ return e('A new internal link for the task #%d have been defined', $eventData['task']['id']);
+ } elseif ($eventName === TaskLinkModel::EVENT_DELETE) {
+ return e('Internal link removed for the task #%d', $eventData['task']['id']);
+ }
+
+ return '';
+ }
+}
diff --git a/app/Helper/HookHelper.php b/app/Helper/HookHelper.php
index 2d13ebcc..cb4dc1ef 100644
--- a/app/Helper/HookHelper.php
+++ b/app/Helper/HookHelper.php
@@ -56,7 +56,7 @@ class HookHelper extends Base
* @access public
* @param string $hook
* @param string $template
- * @return \Kanboard\Helper\Hook
+ * @return $this
*/
public function attach($hook, $template)
{
diff --git a/app/Job/TaskLinkEventJob.php b/app/Job/TaskLinkEventJob.php
new file mode 100644
index 00000000..669608ad
--- /dev/null
+++ b/app/Job/TaskLinkEventJob.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
+
+/**
+ * Class TaskLinkEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class TaskLinkEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $taskLinkId
+ * @param string $eventName
+ * @return $this
+ */
+ public function withParams($taskLinkId, $eventName)
+ {
+ $this->jobParams = array($taskLinkId, $eventName);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $taskLinkId
+ * @param string $eventName
+ * @return $this
+ */
+ public function execute($taskLinkId, $eventName)
+ {
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId($taskLinkId)
+ ->build();
+
+ if ($event !== null) {
+ $this->dispatcher->dispatch($eventName, $event);
+ }
+ }
+}
diff --git a/app/Model/NotificationModel.php b/app/Model/NotificationModel.php
index 925d646e..39c1f581 100644
--- a/app/Model/NotificationModel.php
+++ b/app/Model/NotificationModel.php
@@ -3,6 +3,7 @@
namespace Kanboard\Model;
use Kanboard\Core\Base;
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
/**
* Notification
@@ -85,7 +86,9 @@ class NotificationModel extends Base
case CommentModel::EVENT_USER_MENTION:
return e('%s mentioned you in a comment on the task #%d', $event_author, $event_data['task']['id']);
default:
- return e('Notification');
+ return TaskLinkEventBuilder::getInstance($this->container)
+ ->buildTitleWithAuthor($event_author, $event_name, $event_data) ?:
+ e('Notification');
}
}
@@ -138,7 +141,9 @@ class NotificationModel extends Base
case CommentModel::EVENT_USER_MENTION:
return e('You were mentioned in a comment on the task #%d', $event_data['task']['id']);
default:
- return e('Notification');
+ return TaskLinkEventBuilder::getInstance($this->container)
+ ->buildTitleWithoutAuthor($event_name, $event_data) ?:
+ e('Notification');
}
}
@@ -152,32 +157,10 @@ class NotificationModel extends Base
*/
public function getTaskIdFromEvent($event_name, array $event_data)
{
- switch ($event_name) {
- case TaskFileModel::EVENT_CREATE:
- return $event_data['file']['task_id'];
- case CommentModel::EVENT_CREATE:
- case CommentModel::EVENT_UPDATE:
- case CommentModel::EVENT_DELETE:
- return $event_data['comment']['task_id'];
- case SubtaskModel::EVENT_CREATE:
- case SubtaskModel::EVENT_UPDATE:
- case SubtaskModel::EVENT_DELETE:
- return $event_data['subtask']['task_id'];
- case TaskModel::EVENT_CREATE:
- case TaskModel::EVENT_UPDATE:
- case TaskModel::EVENT_CLOSE:
- case TaskModel::EVENT_OPEN:
- case TaskModel::EVENT_MOVE_COLUMN:
- case TaskModel::EVENT_MOVE_POSITION:
- case TaskModel::EVENT_MOVE_SWIMLANE:
- case TaskModel::EVENT_ASSIGNEE_CHANGE:
- case CommentModel::EVENT_USER_MENTION:
- case TaskModel::EVENT_USER_MENTION:
- return $event_data['task']['id'];
- case TaskModel::EVENT_OVERDUE:
- return $event_data['tasks'][0]['id'];
- default:
- return 0;
+ if ($event_name === TaskModel::EVENT_OVERDUE) {
+ return $event_data['tasks'][0]['id'];
}
+
+ return isset($event_data['task']['id']) ? $event_data['task']['id'] : 0;
}
}
diff --git a/app/Model/TaskLinkModel.php b/app/Model/TaskLinkModel.php
index 09978eae..e8d3c5df 100644
--- a/app/Model/TaskLinkModel.php
+++ b/app/Model/TaskLinkModel.php
@@ -3,7 +3,6 @@
namespace Kanboard\Model;
use Kanboard\Core\Base;
-use Kanboard\Event\TaskLinkEvent;
/**
* TaskLink model
@@ -26,7 +25,8 @@ class TaskLinkModel extends Base
*
* @var string
*/
- const EVENT_CREATE_UPDATE = 'tasklink.create_update';
+ const EVENT_CREATE_UPDATE = 'task_internal_link.create_update';
+ const EVENT_DELETE = 'task_internal_link.delete';
/**
* Get projectId from $task_link_id
@@ -53,7 +53,19 @@ class TaskLinkModel extends Base
*/
public function getById($task_link_id)
{
- return $this->db->table(self::TABLE)->eq('id', $task_link_id)->findOne();
+ return $this->db
+ ->table(self::TABLE)
+ ->columns(
+ self::TABLE.'.id',
+ self::TABLE.'.opposite_task_id',
+ self::TABLE.'.task_id',
+ self::TABLE.'.link_id',
+ LinkModel::TABLE.'.label',
+ LinkModel::TABLE.'.opposite_id AS opposite_link_id'
+ )
+ ->eq(self::TABLE.'.id', $task_link_id)
+ ->join(LinkModel::TABLE, 'id', 'link_id')
+ ->findOne();
}
/**
@@ -140,62 +152,31 @@ class TaskLinkModel extends Base
}
/**
- * Publish events
- *
- * @access private
- * @param array $events
- */
- private function fireEvents(array $events)
- {
- foreach ($events as $event) {
- $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']);
- $this->container['dispatcher']->dispatch(self::EVENT_CREATE_UPDATE, new TaskLinkEvent($event));
- }
- }
-
- /**
* Create a new link
*
* @access public
* @param integer $task_id Task id
* @param integer $opposite_task_id Opposite task id
* @param integer $link_id Link id
- * @return integer Task link id
+ * @return integer|boolean
*/
public function create($task_id, $opposite_task_id, $link_id)
{
- $events = array();
$this->db->startTransaction();
- // Get opposite link
$opposite_link_id = $this->linkModel->getOppositeLinkId($link_id);
+ $task_link_id1 = $this->createTaskLink($task_id, $opposite_task_id, $link_id);
+ $task_link_id2 = $this->createTaskLink($opposite_task_id, $task_id, $opposite_link_id);
- $values = array(
- 'task_id' => $task_id,
- 'opposite_task_id' => $opposite_task_id,
- 'link_id' => $link_id,
- );
-
- // Create the original task link
- $this->db->table(self::TABLE)->insert($values);
- $task_link_id = $this->db->getLastId();
- $events[] = $values;
-
- // Create the opposite task link
- $values = array(
- 'task_id' => $opposite_task_id,
- 'opposite_task_id' => $task_id,
- 'link_id' => $opposite_link_id,
- );
-
- $this->db->table(self::TABLE)->insert($values);
- $events[] = $values;
+ if ($task_link_id1 === false || $task_link_id2 === false) {
+ $this->db->cancelTransaction();
+ return false;
+ }
$this->db->closeTransaction();
+ $this->fireEvents(array($task_link_id1, $task_link_id2), self::EVENT_CREATE_UPDATE);
- $this->fireEvents($events);
-
- return (int) $task_link_id;
+ return $task_link_id1;
}
/**
@@ -210,46 +191,24 @@ class TaskLinkModel extends Base
*/
public function update($task_link_id, $task_id, $opposite_task_id, $link_id)
{
- $events = array();
$this->db->startTransaction();
- // Get original task link
$task_link = $this->getById($task_link_id);
-
- // Find opposite task link
$opposite_task_link = $this->getOppositeTaskLink($task_link);
-
- // Get opposite link
$opposite_link_id = $this->linkModel->getOppositeLinkId($link_id);
- // Update the original task link
- $values = array(
- 'task_id' => $task_id,
- 'opposite_task_id' => $opposite_task_id,
- 'link_id' => $link_id,
- );
-
- $rs1 = $this->db->table(self::TABLE)->eq('id', $task_link_id)->update($values);
- $events[] = $values;
+ $result1 = $this->updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id);
+ $result2 = $this->updateTaskLink($opposite_task_link['id'], $opposite_task_id, $task_id, $opposite_link_id);
- // Update the opposite link
- $values = array(
- 'task_id' => $opposite_task_id,
- 'opposite_task_id' => $task_id,
- 'link_id' => $opposite_link_id,
- );
-
- $rs2 = $this->db->table(self::TABLE)->eq('id', $opposite_task_link['id'])->update($values);
- $events[] = $values;
+ if ($result1 === false || $result2 === false) {
+ $this->db->cancelTransaction();
+ return false;
+ }
$this->db->closeTransaction();
+ $this->fireEvents(array($task_link_id, $opposite_task_link['id']), self::EVENT_CREATE_UPDATE);
- if ($rs1 && $rs2) {
- $this->fireEvents($events);
- return true;
- }
-
- return false;
+ return true;
}
/**
@@ -261,21 +220,83 @@ class TaskLinkModel extends Base
*/
public function remove($task_link_id)
{
+ $this->taskLinkEventJob->execute($task_link_id, self::EVENT_DELETE);
+
$this->db->startTransaction();
$link = $this->getById($task_link_id);
$link_id = $this->linkModel->getOppositeLinkId($link['link_id']);
- $this->db->table(self::TABLE)->eq('id', $task_link_id)->remove();
+ $result1 = $this->db
+ ->table(self::TABLE)
+ ->eq('id', $task_link_id)
+ ->remove();
- $this->db
+ $result2 = $this->db
->table(self::TABLE)
->eq('opposite_task_id', $link['task_id'])
->eq('task_id', $link['opposite_task_id'])
- ->eq('link_id', $link_id)->remove();
+ ->eq('link_id', $link_id)
+ ->remove();
+
+ if ($result1 === false || $result2 === false) {
+ $this->db->cancelTransaction();
+ return false;
+ }
$this->db->closeTransaction();
return true;
}
+
+ /**
+ * Publish events
+ *
+ * @access protected
+ * @param integer[] $task_link_ids
+ * @param string $eventName
+ */
+ protected function fireEvents(array $task_link_ids, $eventName)
+ {
+ foreach ($task_link_ids as $task_link_id) {
+ $this->queueManager->push($this->taskLinkEventJob->withParams($task_link_id, $eventName));
+ }
+ }
+
+ /**
+ * Create task link
+ *
+ * @access protected
+ * @param integer $task_id
+ * @param integer $opposite_task_id
+ * @param integer $link_id
+ * @return integer|boolean
+ */
+ protected function createTaskLink($task_id, $opposite_task_id, $link_id)
+ {
+ return $this->db->table(self::TABLE)->persist(array(
+ 'task_id' => $task_id,
+ 'opposite_task_id' => $opposite_task_id,
+ 'link_id' => $link_id,
+ ));
+ }
+
+ /**
+ * Update task link
+ *
+ * @access protected
+ * @param integer $task_link_id
+ * @param integer $task_id
+ * @param integer $opposite_task_id
+ * @param integer $link_id
+ * @return boolean
+ */
+ protected function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $task_link_id)->update(array(
+ 'task_id' => $task_id,
+ 'opposite_task_id' => $opposite_task_id,
+ 'link_id' => $link_id,
+ ));
+ }
}
diff --git a/app/ServiceProvider/JobProvider.php b/app/ServiceProvider/JobProvider.php
index c7f323f1..5b42794b 100644
--- a/app/ServiceProvider/JobProvider.php
+++ b/app/ServiceProvider/JobProvider.php
@@ -8,6 +8,7 @@ use Kanboard\Job\ProjectFileEventJob;
use Kanboard\Job\SubtaskEventJob;
use Kanboard\Job\TaskEventJob;
use Kanboard\Job\TaskFileEventJob;
+use Kanboard\Job\TaskLinkEventJob;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
@@ -44,6 +45,10 @@ class JobProvider implements ServiceProviderInterface
return new TaskFileEventJob($c);
});
+ $container['taskLinkEventJob'] = $container->factory(function ($c) {
+ return new TaskLinkEventJob($c);
+ });
+
$container['projectFileEventJob'] = $container->factory(function ($c) {
return new ProjectFileEventJob($c);
});
diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php
index 7de24e49..7cc68b26 100644
--- a/app/Subscriber/NotificationSubscriber.php
+++ b/app/Subscriber/NotificationSubscriber.php
@@ -3,6 +3,7 @@
namespace Kanboard\Subscriber;
use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\CommentModel;
use Kanboard\Model\SubtaskModel;
@@ -31,6 +32,8 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn
CommentModel::EVENT_DELETE => 'handleEvent',
CommentModel::EVENT_USER_MENTION => 'handleEvent',
TaskFileModel::EVENT_CREATE => 'handleEvent',
+ TaskLinkModel::EVENT_CREATE_UPDATE => 'handleEvent',
+ TaskLinkModel::EVENT_DELETE => 'handleEvent',
);
}
diff --git a/app/Template/event/task_internal_link_create_update.php b/app/Template/event/task_internal_link_create_update.php
new file mode 100644
index 00000000..de257977
--- /dev/null
+++ b/app/Template/event/task_internal_link_create_update.php
@@ -0,0 +1,16 @@
+<p class="activity-title">
+ <?= e('%s set a new internal link for the task %s',
+ $this->text->e($author),
+ $this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))
+ ) ?>
+ <span class="activity-date"><?= $this->dt->datetime($date_creation) ?></span>
+</p>
+<div class="activity-description">
+ <p class="activity-task-title">
+ <?= e(
+ 'This task is now linked to the task %s with the relation "%s"',
+ $this->url->link(t('#%d', $task_link['opposite_task_id']), 'TaskViewController', 'show', array('task_id' => $task_link['opposite_task_id'])),
+ $this->text->e($task_link['label'])
+ ) ?>
+ </p>
+</div>
diff --git a/app/Template/event/task_internal_link_delete.php b/app/Template/event/task_internal_link_delete.php
new file mode 100644
index 00000000..e537bf81
--- /dev/null
+++ b/app/Template/event/task_internal_link_delete.php
@@ -0,0 +1,16 @@
+<p class="activity-title">
+ <?= e('%s removed an internal link for the task %s',
+ $this->text->e($author),
+ $this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))
+ ) ?>
+ <span class="activity-date"><?= $this->dt->datetime($date_creation) ?></span>
+</p>
+<div class="activity-description">
+ <p class="activity-task-title">
+ <?= e(
+ 'The link with the relation "%s" to the task %s have been removed',
+ $this->text->e($task_link['label']),
+ $this->url->link(t('#%d', $task_link['opposite_task_id']), 'TaskViewController', 'show', array('task_id' => $task_link['opposite_task_id']))
+ ) ?>
+ </p>
+</div>
diff --git a/app/Template/notification/task_file_create.php b/app/Template/notification/task_file_create.php
index feab8dd2..c19f7279 100644
--- a/app/Template/notification/task_file_create.php
+++ b/app/Template/notification/task_file_create.php
@@ -2,4 +2,4 @@
<p><?= t('New attachment added "%s"', $file['name']) ?></p>
-<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?> \ No newline at end of file
+<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?>
diff --git a/app/Template/notification/task_internal_link_create_update.php b/app/Template/notification/task_internal_link_create_update.php
new file mode 100644
index 00000000..73cad84d
--- /dev/null
+++ b/app/Template/notification/task_internal_link_create_update.php
@@ -0,0 +1,11 @@
+<h2><?= $this->text->e($task['title']) ?> (#<?= $task['id'] ?>)</h2>
+
+<p>
+ <?= e(
+ 'This task is now linked to the task %s with the relation "%s"',
+ $this->url->link(t('#%d', $task_link['opposite_task_id']), 'TaskViewController', 'show', array('task_id' => $task_link['opposite_task_id'])),
+ $this->text->e($task_link['label'])
+ ) ?>
+</p>
+
+<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?>
diff --git a/app/Template/notification/task_internal_link_delete.php b/app/Template/notification/task_internal_link_delete.php
new file mode 100644
index 00000000..bb54e0a7
--- /dev/null
+++ b/app/Template/notification/task_internal_link_delete.php
@@ -0,0 +1,11 @@
+<h2><?= $this->text->e($task['title']) ?> (#<?= $task['id'] ?>)</h2>
+
+<p>
+ <?= e(
+ 'The link with the relation "%s" to the task %s have been removed',
+ $this->text->e($task_link['label']),
+ $this->url->link(t('#%d', $task_link['opposite_task_id']), 'TaskViewController', 'show', array('task_id' => $task_link['opposite_task_id']))
+ ) ?>
+</p>
+
+<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?>
diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php
index d7e68f72..b9d7e9d9 100644
--- a/tests/units/Action/TaskAssignCategoryLinkTest.php
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -2,12 +2,12 @@
require_once __DIR__.'/../Base.php';
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\CategoryModel;
-use Kanboard\Event\TaskLinkEvent;
use Kanboard\Action\TaskAssignCategoryLink;
class TaskAssignCategoryLinkTest extends Base
@@ -18,6 +18,7 @@ class TaskAssignCategoryLinkTest extends Base
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
@@ -27,13 +28,12 @@ class TaskAssignCategoryLinkTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->build();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
@@ -44,51 +44,58 @@ class TaskAssignCategoryLinkTest extends Base
public function testWhenLinkDontMatch()
{
$taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
- $action->setParam('link_id', 1);
+ $action->setParam('link_id', 2);
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->build();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
}
public function testThatExistingCategoryWillNotChange()
{
$taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
- $action->setParam('category_id', 2);
+ $action->setParam('category_id', 1);
$action->setParam('link_id', 2);
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->build();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php
index 07d0969b..27364bc9 100644
--- a/tests/units/Action/TaskAssignColorLinkTest.php
+++ b/tests/units/Action/TaskAssignColorLinkTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -13,42 +13,55 @@ class TaskAssignColorLinkTest extends Base
{
public function testChangeColor()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->build();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
$task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
$this->assertEquals('red', $task['color_id']);
}
public function testWithWrongLink()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 2));
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->build();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
}
}
diff --git a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
new file mode 100644
index 00000000..7364d651
--- /dev/null
+++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
@@ -0,0 +1,70 @@
+<?php
+
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventBuilderTest extends Base
+{
+ public function testWithMissingLink()
+ {
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+ $taskLinkEventBuilder->withTaskLinkId(42);
+ $this->assertNull($taskLinkEventBuilder->build());
+ }
+
+ public function testBuild()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = $taskLinkEventBuilder->withTaskLinkId(1)->build();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event);
+ $this->assertNotEmpty($event['task_link']);
+ $this->assertNotEmpty($event['task']);
+ }
+
+ public function testBuildTitle()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $eventData = $taskLinkEventBuilder->withTaskLinkId(1)->build();
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('Foobar set a new internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Foobar removed an internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', 'not found', $eventData->getAll());
+ $this->assertSame('', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('A new internal link for the task #1 have been defined', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Internal link removed for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor('not found', $eventData->getAll());
+ $this->assertSame('', $title);
+ }
+}
diff --git a/tests/units/Job/TaskLinkEventJobTest.php b/tests/units/Job/TaskLinkEventJobTest.php
new file mode 100644
index 00000000..1949316a
--- /dev/null
+++ b/tests/units/Job/TaskLinkEventJobTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use Kanboard\Job\TaskLinkEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskLinkEventJob->getJobParams());
+ }
+
+ public function testWithMissingLink()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->execute(42, TaskLinkModel::EVENT_CREATE_UPDATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreationEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerDeleteEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_DELETE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+ $this->assertTrue($taskLinkModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Model/NotificationModelTest.php b/tests/units/Model/NotificationModelTest.php
index 889f3349..0bd9db6e 100644
--- a/tests/units/Model/NotificationModelTest.php
+++ b/tests/units/Model/NotificationModelTest.php
@@ -7,6 +7,7 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\CommentModel;
use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\NotificationModel;
@@ -23,47 +24,38 @@ class NotificationModelTest extends Base
$subtaskModel = new SubtaskModel($this->container);
$commentModel = new CommentModel($this->container);
$taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
$this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
$this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
$task = $taskFinderModel->getDetails(1);
$subtask = $subtaskModel->getById(1, true);
$comment = $commentModel->getById(1);
$file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $title = $notificationModel->getTitleWithoutAuthor($event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
-
- $title = $notificationModel->getTitleWithAuthor('foobar', $event_name, array(
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'file' => $file,
+ 'task_link' => $tasklink,
'changes' => array()
- ));
+ );
- $this->assertNotEmpty($title);
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor($eventName, $eventData));
+ $this->assertNotEmpty($notificationModel->getTitleWithAuthor('Foobar', $eventName, $eventData));
}
$this->assertNotEmpty($notificationModel->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
- $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unkown', array()));
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unknown', array()));
}
public function testGetTaskIdFromEvent()
@@ -75,6 +67,7 @@ class NotificationModelTest extends Base
$subtaskModel = new SubtaskModel($this->container);
$commentModel = new CommentModel($this->container);
$taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
@@ -86,18 +79,20 @@ class NotificationModelTest extends Base
$subtask = $subtaskModel->getById(1, true);
$comment = $commentModel->getById(1);
$file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
$this->assertNotEmpty($task);
$this->assertNotEmpty($subtask);
$this->assertNotEmpty($comment);
$this->assertNotEmpty($file);
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $task_id = $notificationModel->getTaskIdFromEvent($event_name, array(
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $task_id = $notificationModel->getTaskIdFromEvent($eventName, array(
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'file' => $file,
+ 'task_link' => $tasklink,
'changes' => array()
));
diff --git a/tests/units/Model/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php
index 78590891..01a7888b 100644
--- a/tests/units/Model/TaskLinkModelTest.php
+++ b/tests/units/Model/TaskLinkModelTest.php
@@ -9,6 +9,34 @@ use Kanboard\Model\ProjectModel;
class TaskLinkModelTest extends Base
{
+ public function testGeyById()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 6));
+
+ $taskLink = $taskLinkModel->getById(1);
+ $this->assertEquals(1, $taskLink['id']);
+ $this->assertEquals(1, $taskLink['task_id']);
+ $this->assertEquals(2, $taskLink['opposite_task_id']);
+ $this->assertEquals(6, $taskLink['link_id']);
+ $this->assertEquals(7, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a child of', $taskLink['label']);
+
+ $taskLink = $taskLinkModel->getById(2);
+ $this->assertEquals(2, $taskLink['id']);
+ $this->assertEquals(2, $taskLink['task_id']);
+ $this->assertEquals(1, $taskLink['opposite_task_id']);
+ $this->assertEquals(7, $taskLink['link_id']);
+ $this->assertEquals(6, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a parent of', $taskLink['label']);
+ }
+
// Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
public function testGetTaskWithMultipleMilestoneLink()
{
diff --git a/tests/units/Notification/MailNotificationTest.php b/tests/units/Notification/MailNotificationTest.php
new file mode 100644
index 00000000..6579d9bc
--- /dev/null
+++ b/tests/units/Notification/MailNotificationTest.php
@@ -0,0 +1,117 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Notification\MailNotification;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class MailNotificationTest extends Base
+{
+ public function testGetMailContent()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $fileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+ $this->assertNotEmpty($mailNotification->getMailContent($eventName, $eventData));
+ $this->assertNotEmpty($mailNotification->getMailSubject($eventName, $eventData));
+ }
+ }
+
+ public function testSendWithEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'test@localhost')));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->once())
+ ->method('send')
+ ->with(
+ $this->equalTo('test@localhost'),
+ $this->equalTo('admin'),
+ $this->equalTo('[test][New task] test (#1)'),
+ $this->stringContains('test')
+ );
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+
+ public function testSendWithoutEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+}
diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php
deleted file mode 100644
index 9f077ac8..00000000
--- a/tests/units/Notification/MailTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\TaskFileModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Notification\MailNotification;
-use Kanboard\Subscriber\NotificationSubscriber;
-
-class MailTest extends Base
-{
- public function testGetMailContent()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
- $f = new TaskFileModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
- $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event => $values) {
- $this->assertNotEmpty($en->getMailContent($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
-
- $this->assertNotEmpty($en->getMailSubject($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
- }
- }
-
- public function testSendWithEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->once())
- ->method('send')
- ->with(
- $this->equalTo('test@localhost'),
- $this->equalTo('admin'),
- $this->equalTo('[test][New task] test (#1)'),
- $this->stringContains('test')
- );
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-
- public function testSendWithoutEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->never())
- ->method('send');
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-}
diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookNotificationTest.php
index 5a9eb1c7..6fbc349c 100644
--- a/tests/units/Notification/WebhookTest.php
+++ b/tests/units/Notification/WebhookNotificationTest.php
@@ -7,23 +7,23 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Subscriber\NotificationSubscriber;
-class WebhookTest extends Base
+class WebhookNotificationTest extends Base
{
public function testTaskCreation()
{
- $c = new ConfigModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container));
- $c->save(array('webhook_url' => 'http://localhost/?task-creation'));
+ $configModel->save(array('webhook_url' => 'http://localhost/?task-creation'));
$this->container['httpClient']
->expects($this->once())
->method('postJson')
->with($this->stringContains('http://localhost/?task-creation&token='), $this->anything());
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
}
}