summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Subscriber/RecurringTaskSubscriber.php14
-rw-r--r--tests/units/Subscriber/RecurringTaskSubscriberTest.php164
2 files changed, 172 insertions, 6 deletions
diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php
index 21cd3996..3e2848f8 100644
--- a/app/Subscriber/RecurringTaskSubscriber.php
+++ b/app/Subscriber/RecurringTaskSubscriber.php
@@ -19,12 +19,13 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI
public function onMove(TaskEvent $event)
{
$this->logger->debug('Subscriber executed: '.__METHOD__);
+ $task = $event['task'];
- if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) {
- if ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($event['project_id']) == $event['src_column_id']) {
- $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
- } elseif ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($event['project_id']) == $event['dst_column_id']) {
- $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
+ if ($task['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) {
+ if ($task['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($task['project_id']) == $event['src_column_id']) {
+ $this->taskRecurrenceModel->duplicateRecurringTask($task['id']);
+ } elseif ($task['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($task['project_id']) == $event['dst_column_id']) {
+ $this->taskRecurrenceModel->duplicateRecurringTask($task['id']);
}
}
}
@@ -32,8 +33,9 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI
public function onClose(TaskEvent $event)
{
$this->logger->debug('Subscriber executed: '.__METHOD__);
+ $task = $event['task'];
- if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) {
+ if ($task['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $task['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) {
$this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
}
}
diff --git a/tests/units/Subscriber/RecurringTaskSubscriberTest.php b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
new file mode 100644
index 00000000..d6aba7cf
--- /dev/null
+++ b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
@@ -0,0 +1,164 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Subscriber\RecurringTaskSubscriber;
+
+require_once __DIR__.'/../Base.php';
+
+class RecurringTaskSubscriberTest extends Base
+{
+ public function testWithNoRecurrence()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 1))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ 'column_id' => 2,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 4))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceOnClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withChanges(array('is_active' => 0))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+}