summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-16 20:04:07 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-16 20:04:07 -0400
commit79de1a0cea67d3f6348fa47825edc6fe84a1c454 (patch)
tree2c03de0f3aa5fb3bff7b51a75295deb08f02f687
parente7ccaaeee4180bbf3a9ac23a5423c28185875bac (diff)
API: Change parameters for updateTask, enforce the use of moveTaskPosition() to move a task
-rw-r--r--app/Api/Task.php6
-rw-r--r--app/Subscriber/TaskMovedDateSubscriber.php1
-rw-r--r--docs/api-json-rpc.markdown3
-rw-r--r--tests/functionals/ApiTest.php42
-rw-r--r--tests/units/TaskMovedDateSubscriberTest.php77
5 files changed, 117 insertions, 12 deletions
diff --git a/app/Api/Task.php b/app/Api/Task.php
index d7a9e91b..e06c012b 100644
--- a/app/Api/Task.php
+++ b/app/Api/Task.php
@@ -82,9 +82,9 @@ class Task extends Base
return $valid ? $this->taskCreation->create($values) : false;
}
- public function updateTask($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null,
+ public function updateTask($id, $title = null, $project_id = null, $color_id = null, $owner_id = null,
$creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null,
- $swimlane_id = null, $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null,
+ $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null,
$recurrence_timeframe = null, $recurrence_basedate = null, $reference = null)
{
$values = array(
@@ -92,14 +92,12 @@ class Task extends Base
'title' => $title,
'project_id' => $project_id,
'color_id' => $color_id,
- 'column_id' => $column_id,
'owner_id' => $owner_id,
'creator_id' => $creator_id,
'date_due' => $date_due,
'description' => $description,
'category_id' => $category_id,
'score' => $score,
- 'swimlane_id' => $swimlane_id,
'recurrence_status' => $recurrence_status,
'recurrence_trigger' => $recurrence_trigger,
'recurrence_factor' => $recurrence_factor,
diff --git a/app/Subscriber/TaskMovedDateSubscriber.php b/app/Subscriber/TaskMovedDateSubscriber.php
index eb04d62c..16a75c19 100644
--- a/app/Subscriber/TaskMovedDateSubscriber.php
+++ b/app/Subscriber/TaskMovedDateSubscriber.php
@@ -12,6 +12,7 @@ class TaskMovedDateSubscriber extends \Core\Base implements EventSubscriberInter
{
return array(
Task::EVENT_MOVE_COLUMN => array('execute', 0),
+ Task::EVENT_MOVE_SWIMLANE => array('execute', 0),
);
}
diff --git a/docs/api-json-rpc.markdown b/docs/api-json-rpc.markdown
index 3e5d76a6..dc7254d9 100644
--- a/docs/api-json-rpc.markdown
+++ b/docs/api-json-rpc.markdown
@@ -2189,14 +2189,12 @@ Response example:
- **title** (string, optional)
- **project_id** (integer, optional)
- **color_id** (string, optional)
- - **column_id** (integer, optional)
- **owner_id** (integer, optional)
- **creator_id** (integer, optional)
- **date_due**: ISO8601 format (string, optional)
- **description** Markdown content (string, optional)
- **category_id** (integer, optional)
- **score** (integer, optional)
- - **swimlane_id** (integer, optional)
- **recurrence_status** (integer, optional)
- **recurrence_trigger** (integer, optional)
- **recurrence_factor** (integer, optional)
@@ -2330,6 +2328,7 @@ Response example:
- **task_id** (integer, required)
- **column_id** (integer, required)
- **position** (integer, required)
+ - **swimlane_id** (integer, optional, default=0)
- Result on success: **true**
- Result on failure: **false**
diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php
index 92c752bb..642288b8 100644
--- a/tests/functionals/ApiTest.php
+++ b/tests/functionals/ApiTest.php
@@ -348,11 +348,6 @@ class Api extends PHPUnit_Framework_TestCase
$this->assertEquals('Swimlane A', $swimlanes[2]['name']);
}
- public function testRemoveSwimlane()
- {
- $this->assertTrue($this->client->removeSwimlane(1, 2));
- }
-
public function testCreateTask()
{
$task = array(
@@ -408,6 +403,42 @@ class Api extends PHPUnit_Framework_TestCase
$this->assertEmpty($tasks);
}
+ public function testMoveTaskSwimlane()
+ {
+ $task_id = $this->getTaskId();
+
+ $task = $this->client->getTask($task_id);
+ $this->assertNotFalse($task);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $moved_timestamp = $task['date_moved'];
+ sleep(1);
+ $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 4, 1, 2));
+
+ $task = $this->client->getTask($task_id);
+ $this->assertNotFalse($task);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ $this->assertNotEquals($moved_timestamp, $task['date_moved']);
+ }
+
+ public function testRemoveSwimlane()
+ {
+ $this->assertTrue($this->client->removeSwimlane(1, 2));
+
+ $task = $this->client->getTask($this->getTaskId());
+ $this->assertNotFalse($task);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ }
+
public function testUpdateTask()
{
$task = $this->client->getTask(1);
@@ -415,7 +446,6 @@ class Api extends PHPUnit_Framework_TestCase
$values = array();
$values['id'] = $task['id'];
$values['color_id'] = 'green';
- $values['column_id'] = 1;
$values['description'] = 'test';
$values['date_due'] = '';
diff --git a/tests/units/TaskMovedDateSubscriberTest.php b/tests/units/TaskMovedDateSubscriberTest.php
new file mode 100644
index 00000000..e0364918
--- /dev/null
+++ b/tests/units/TaskMovedDateSubscriberTest.php
@@ -0,0 +1,77 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\TaskPosition;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\Swimlane;
+use Subscriber\TaskMovedDateSubscriber;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+
+class TaskMovedDateSubscriberTest extends Base
+{
+ public function testMoveTaskAnotherColumn()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->container['dispatcher'] = new EventDispatcher;
+ $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
+
+ $now = time();
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals($now, $task['date_moved'], '', 1);
+
+ sleep(1);
+
+ $this->assertTrue($tp->movePosition(1, 1, 2, 1));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotEquals($now, $task['date_moved']);
+ }
+
+ public function testMoveTaskAnotherSwimlane()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $tf = new TaskFinder($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->container['dispatcher'] = new EventDispatcher;
+ $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
+
+ $now = time();
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals($now, $task['date_moved'], '', 1);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ sleep(1);
+
+ $this->assertTrue($tp->movePosition(1, 1, 2, 1, 2));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotEquals($now, $task['date_moved']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ }
+}