summaryrefslogtreecommitdiff
path: root/tests/units/Model/SubtaskStatusModelTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-23 21:48:59 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-23 21:48:59 -0400
commit24555080fd3ca8607f0a798b5a0e4be98ff131f8 (patch)
tree8a92479149bbc079a7f6b1daa678d612534d80a2 /tests/units/Model/SubtaskStatusModelTest.php
parentf216e345ba2ad7486037c393c0475a1371ca2b00 (diff)
Create new class SubtaskStatusModel
Diffstat (limited to 'tests/units/Model/SubtaskStatusModelTest.php')
-rw-r--r--tests/units/Model/SubtaskStatusModelTest.php123
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/units/Model/SubtaskStatusModelTest.php b/tests/units/Model/SubtaskStatusModelTest.php
new file mode 100644
index 00000000..af4c3955
--- /dev/null
+++ b/tests/units/Model/SubtaskStatusModelTest.php
@@ -0,0 +1,123 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskStatusModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskStatusModelTest extends Base
+{
+ public function testToggleStatusWithoutSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testToggleStatusWithSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ // Set the current logged user
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testCloseAll()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskStatusModel->closeAll(1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+
+ foreach ($subtasks as $subtask) {
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ }
+ }
+}