diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-08 19:40:13 +0200 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-08 19:40:13 +0200 |
commit | 9d39943bd43e2e0651bda3df7a32940a26f5e8ec (patch) | |
tree | c736f1d9ec858f6112f2e561093cadb778409f7a | |
parent | 5d5b4711e3783f9d75fba99695930aa09119a051 (diff) |
Fix bug when moving tasks position in the same column
-rw-r--r-- | app/Model/Task.php | 16 | ||||
-rw-r--r-- | tests/units/TaskTest.php | 72 |
2 files changed, 83 insertions, 5 deletions
diff --git a/app/Model/Task.php b/app/Model/Task.php index d326c382..6eb24281 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -560,23 +560,30 @@ class Task extends Base ->eq('project_id', $project_id) ->findAll(); - // We sort everything by column and position $board = $this->board->getColumnsList($project_id); $columns = array(); + $task_id = (int) $task_id; + // Prepare the columns foreach ($board as $board_column_id => $board_column_name) { $columns[$board_column_id] = array(); } + // The column must exists + if (! isset($columns[$column_id])) { + return false; + } + + // Sort everything by column foreach ($tasks as &$task) { if ($task['id'] != $task_id) { $columns[$task['column_id']][$task['position'] - 1] = (int) $task['id']; } } - // The column must exists - if (! isset($columns[$column_id])) { - return false; + // Sort all tasks by position + foreach ($columns as &$column) { + ksort($column); } // We put our task to the new position @@ -601,7 +608,6 @@ class Task extends Base foreach ($columns as $column_id => $column) { $position = 1; - ksort($column); foreach ($column as $task_id) { diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php index a45127e2..8121a575 100644 --- a/tests/units/TaskTest.php +++ b/tests/units/TaskTest.php @@ -9,6 +9,78 @@ use Model\User; class TaskTest extends Base { + public function testMoveTaskTop() + { + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1))); + + // Move the last task to hte top + $this->assertTrue($t->movePosition(1, 4, 1, 1)); + + // Check tasks position + $task = $t->getById(1); + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(2, $task['position']); + + $task = $t->getById(2); + $this->assertEquals(2, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(3, $task['position']); + + $task = $t->getById(3); + $this->assertEquals(3, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(4, $task['position']); + + $task = $t->getById(4); + $this->assertEquals(4, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(1, $task['position']); + } + + public function testMoveTaskBottom() + { + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1))); + + // Move the last task to hte top + $this->assertTrue($t->movePosition(1, 1, 1, 4)); + + // Check tasks position + $task = $t->getById(1); + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(4, $task['position']); + + $task = $t->getById(2); + $this->assertEquals(2, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(1, $task['position']); + + $task = $t->getById(3); + $this->assertEquals(3, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(2, $task['position']); + + $task = $t->getById(4); + $this->assertEquals(4, $task['id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(3, $task['position']); + } + public function testMovePosition() { $t = new Task($this->registry); |