diff options
-rw-r--r-- | app/Model/TaskModificationModel.php | 29 | ||||
-rw-r--r-- | tests/units/Model/TaskModificationTest.php | 32 |
2 files changed, 52 insertions, 9 deletions
diff --git a/app/Model/TaskModificationModel.php b/app/Model/TaskModificationModel.php index 0fc3617e..1b176a41 100644 --- a/app/Model/TaskModificationModel.php +++ b/app/Model/TaskModificationModel.php @@ -25,6 +25,7 @@ class TaskModificationModel extends Base { $original_task = $this->taskFinderModel->getById($values['id']); + $this->updateTags($values, $original_task); $this->prepare($values); $result = $this->db->table(TaskModel::TABLE)->eq('id', $original_task['id'])->update($values); @@ -80,16 +81,11 @@ class TaskModificationModel extends Base /** * Prepare data before task modification * - * @access public - * @param array $values Form values + * @access protected + * @param array $values */ - public function prepare(array &$values) + protected function prepare(array &$values) { - if (isset($values['tags'])) { - $this->taskTagModel->save($values['project_id'], $values['id'], $values['tags']); - unset($values['tags']); - } - $values = $this->dateParser->convert($values, array('date_due')); $values = $this->dateParser->convert($values, array('date_started'), true); @@ -99,4 +95,21 @@ class TaskModificationModel extends Base $values['date_modification'] = time(); } + + /** + * Update tags + * + * @access protected + * @param array $values + * @param array $original_task + */ + protected function updateTags(array &$values, array $original_task) + { + if (isset($values['tags'])) { + $this->taskTagModel->save($original_task['project_id'], $values['id'], $values['tags']); + unset($values['tags']); + } else { + $this->taskTagModel->save($original_task['project_id'], $values['id'], array()); + } + } } diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index a8ace25a..5cbc44e6 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -7,6 +7,7 @@ use Kanboard\Model\TaskCreationModel; use Kanboard\Model\TaskModificationModel; use Kanboard\Model\TaskFinderModel; use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskTagModel; class TaskModificationTest extends Base { @@ -45,7 +46,6 @@ class TaskModificationTest extends Base $p = new ProjectModel($this->container); $tc = new TaskCreationModel($this->container); $tm = new TaskModificationModel($this->container); - $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -280,4 +280,34 @@ class TaskModificationTest extends Base $task = $tf->getById(1); $this->assertEquals(13.3, $task['time_spent']); } + + public function testChangeTags() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskModificationModel = new TaskModificationModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('tag1', 'tag2')))); + $this->assertTrue($taskModificationModel->update(array('id' => 1, 'tags' => array('tag2')))); + + $tags = $taskTagModel->getList(1); + $this->assertEquals(array(2 => 'tag2'), $tags); + } + + public function testRemoveAllTags() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskModificationModel = new TaskModificationModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('tag1', 'tag2')))); + $this->assertTrue($taskModificationModel->update(array('id' => 1))); + + $tags = $taskTagModel->getList(1); + $this->assertEquals(array(), $tags); + } } |