diff options
author | JLGC @monolinux <monolinux@junglacode.org> | 2016-08-15 23:13:16 -0500 |
---|---|---|
committer | JLGC @monolinux <monolinux@junglacode.org> | 2016-08-15 23:13:16 -0500 |
commit | 683c0464093f6a7976236c68653c2a2cc5dae280 (patch) | |
tree | bf176ecd82415cc4952eea071b7d264dd5fd68b4 /tests/units/Subscriber | |
parent | b1e795fc5b45369f7b9b565b1e106d2673361977 (diff) | |
parent | 5f82a942c0011bf91947b2c1d627c0907bda0c92 (diff) |
Merge https://github.com/kanboard/kanboard
Diffstat (limited to 'tests/units/Subscriber')
-rw-r--r-- | tests/units/Subscriber/RecurringTaskSubscriberTest.php | 164 |
1 files changed, 164 insertions, 0 deletions
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)); + } +} |