diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-05-26 12:54:06 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-05-26 12:54:06 -0400 |
commit | 93783274a438204a31865c848913088af96f0377 (patch) | |
tree | 0624ee61a42d20f55a765c4e1ef4cfa080aa0a83 | |
parent | 2cb6b77ac87c52e9655a1333d39d0263b4880ed5 (diff) |
Improve automatic actions (move task to another position same columns)
-rw-r--r-- | app/Core/Event.php | 11 | ||||
-rw-r--r-- | app/Model/Task.php | 2 | ||||
-rw-r--r-- | tests/ActionTest.php | 30 |
3 files changed, 38 insertions, 5 deletions
diff --git a/app/Core/Event.php b/app/Core/Event.php index ac81bf87..0e6df5e8 100644 --- a/app/Core/Event.php +++ b/app/Core/Event.php @@ -128,6 +128,17 @@ class Event } /** + * Flush the list of triggered events + * + * @access public + */ + public function clearTriggeredEvents() + { + $this->events = array(); + $this->lastEvent = ''; + } + + /** * Check if a listener bind to an event * * @access public diff --git a/app/Model/Task.php b/app/Model/Task.php index 04500272..70f1404c 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -456,6 +456,8 @@ class Task extends Base */ public function move($task_id, $column_id, $position) { + $this->event->clearTriggeredEvents(); + return $this->update(array( 'id' => $task_id, 'column_id' => $column_id, diff --git a/tests/ActionTest.php b/tests/ActionTest.php index 5cab0fc0..2eb12784 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -107,7 +107,7 @@ class ActionTest extends Base // We create a task $this->assertEquals(1, $task->create(array( - 'title' => 'unit_test', + 'title' => 'unit_test 0', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', @@ -115,6 +115,15 @@ class ActionTest extends Base 'category_id' => 1, ))); + $this->assertEquals(2, $task->create(array( + 'title' => 'unit_test 1', + 'project_id' => 1, + 'owner_id' => 1, + 'color_id' => 'yellow', + 'column_id' => 1, + 'category_id' => 1, + ))); + // We create a new action, when the category_id=2 then the color_id should be green $this->assertTrue($action->create(array( 'project_id' => 1, @@ -137,14 +146,25 @@ class ActionTest extends Base $this->assertEquals(1, $t1['is_active']); $this->assertEquals('red', $t1['color_id']); - // We move our task - $task->move(1, 1, 2); + $t1 = $task->getById(2); + $this->assertEquals(1, $t1['position']); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals('yellow', $t1['color_id']); + + // We move our tasks + $task->move(1, 1, 1); // task #1 to position 1 + $task->move(2, 1, 0); // task #2 to position 0 $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); - // Our task should be green and have the position 2 + // Both tasks should be green $t1 = $task->getById(1); - $this->assertEquals(2, $t1['position']); + $this->assertEquals(1, $t1['position']); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals('green', $t1['color_id']); + + $t1 = $task->getById(2); + $this->assertEquals(0, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('green', $t1['color_id']); } |