From 4a230d331ec220fc32a48525afb308af0d9787fa Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 10:25:13 -0400 Subject: Added application and project roles validation for API procedure calls --- tests/integration/TaskProcedureTest.php | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/integration/TaskProcedureTest.php (limited to 'tests/integration/TaskProcedureTest.php') diff --git a/tests/integration/TaskProcedureTest.php b/tests/integration/TaskProcedureTest.php new file mode 100644 index 00000000..f456ae52 --- /dev/null +++ b/tests/integration/TaskProcedureTest.php @@ -0,0 +1,55 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertUpdateTask(); + $this->assertGetTaskById(); + $this->assertGetTaskByReference(); + $this->assertGetAllTasks(); + $this->assertOpenCloseTask(); + } + + public function assertUpdateTask() + { + $this->assertTrue($this->app->updateTask(array('id' => $this->taskId, 'color_id' => 'red'))); + } + + public function assertGetTaskById() + { + $task = $this->app->getTask($this->taskId); + $this->assertNotNull($task); + $this->assertEquals('red', $task['color_id']); + $this->assertEquals($this->taskTitle, $task['title']); + } + + public function assertGetTaskByReference() + { + $taskId = $this->app->createTask(array('title' => 'task with reference', 'project_id' => $this->projectId, 'reference' => 'test')); + $this->assertNotFalse($taskId); + + $task = $this->app->getTaskByReference($this->projectId, 'test'); + $this->assertNotNull($task); + $this->assertEquals($taskId, $task['id']); + } + + public function assertGetAllTasks() + { + $tasks = $this->app->getAllTasks($this->projectId); + $this->assertInternalType('array', $tasks); + $this->assertNotEmpty($tasks); + } + + public function assertOpenCloseTask() + { + $this->assertTrue($this->app->closeTask($this->taskId)); + $this->assertTrue($this->app->openTask($this->taskId)); + } +} -- cgit v1.2.3 From 7009718b17ad75e7097390d7f910ee4cbcba923e Mon Sep 17 00:00:00 2001 From: Eskiso Date: Sat, 30 Jul 2016 20:04:09 +0100 Subject: Added Task Metadata API calls tests --- tests/integration/TaskProcedureTest.php | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/integration/TaskProcedureTest.php') diff --git a/tests/integration/TaskProcedureTest.php b/tests/integration/TaskProcedureTest.php index f456ae52..f932355c 100644 --- a/tests/integration/TaskProcedureTest.php +++ b/tests/integration/TaskProcedureTest.php @@ -5,6 +5,7 @@ require_once __DIR__.'/BaseProcedureTest.php'; class TaskProcedureTest extends BaseProcedureTest { protected $projectName = 'My project to test tasks'; + protected $metaKey = 'MyTestMetaKey'; public function testAll() { @@ -15,8 +16,45 @@ class TaskProcedureTest extends BaseProcedureTest $this->assertGetTaskByReference(); $this->assertGetAllTasks(); $this->assertOpenCloseTask(); + $this->assertSaveTaskMetadata(); + $this->assertGetTaskMetadata(); + $this->assertGetTaskMetadataByName(); + $this->assertRemoveTaskMetadata(): } + public function assertSaveTaskMetadata() + { + $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $this->assertTrue($createMetaKey); + } + + public function assertGetTaskMetadata() + { + $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $this->assertTrue($createMetaKey,'Did not create metakey with success'); + $metaData = $this->app->getTaskMetadata(($this->taskId); + $this->assertArrayHasKey($this->metaKey, $metaData); + $this->assertEquals('metaValue1', $metaData[$this->metaKey]); + } + + public function assertGetTaskMetadataByName() + { + $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $this->assertTrue($createMetaKey,'Did not create metakey with success'); + $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); + $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value'); + } + + public function assertRemoveTaskMetadata() + { + $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $this->assertTrue($createMetaKey,'Did not create metakey with success'); + $metaValue = $this->app->removeTaskMetadata($this->taskId,$this->metaKey); + $this->assertTrue($metaValue,'Did not remove metakey with success'); + $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); + $this->assertEquals('',$metaValue,'Did not return an empty string due to metadata being deleted'); + } + public function assertUpdateTask() { $this->assertTrue($this->app->updateTask(array('id' => $this->taskId, 'color_id' => 'red'))); -- cgit v1.2.3 From 9f2ef84cd08607d1b4df0ab31f70eda65ea9ee83 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jul 2016 14:57:30 -0400 Subject: Fix PHP error in PR #2535 --- tests/integration/TaskProcedureTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/integration/TaskProcedureTest.php') diff --git a/tests/integration/TaskProcedureTest.php b/tests/integration/TaskProcedureTest.php index f932355c..8b3e622c 100644 --- a/tests/integration/TaskProcedureTest.php +++ b/tests/integration/TaskProcedureTest.php @@ -19,42 +19,42 @@ class TaskProcedureTest extends BaseProcedureTest $this->assertSaveTaskMetadata(); $this->assertGetTaskMetadata(); $this->assertGetTaskMetadataByName(); - $this->assertRemoveTaskMetadata(): + $this->assertRemoveTaskMetadata(); } public function assertSaveTaskMetadata() { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); $this->assertTrue($createMetaKey); } - + public function assertGetTaskMetadata() { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); $this->assertTrue($createMetaKey,'Did not create metakey with success'); - $metaData = $this->app->getTaskMetadata(($this->taskId); + $metaData = $this->app->getTaskMetadata(($this->taskId)); $this->assertArrayHasKey($this->metaKey, $metaData); $this->assertEquals('metaValue1', $metaData[$this->metaKey]); } - + public function assertGetTaskMetadataByName() { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); $this->assertTrue($createMetaKey,'Did not create metakey with success'); $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value'); } - + public function assertRemoveTaskMetadata() { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId,array($this->metaKey => 'metaValue1')); + $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); $this->assertTrue($createMetaKey,'Did not create metakey with success'); $metaValue = $this->app->removeTaskMetadata($this->taskId,$this->metaKey); $this->assertTrue($metaValue,'Did not remove metakey with success'); $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); $this->assertEquals('',$metaValue,'Did not return an empty string due to metadata being deleted'); } - + public function assertUpdateTask() { $this->assertTrue($this->app->updateTask(array('id' => $this->taskId, 'color_id' => 'red'))); -- cgit v1.2.3 From 86c950743f2d923a37de3f3a91344dae62a1015e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jul 2016 15:10:42 -0400 Subject: Move API calls for task metadata to a separate class --- app/Api/Procedure/TaskMetadataProcedure.php | 38 +++++++++++++++++++++ app/Api/Procedure/TaskProcedure.php | 27 +-------------- app/ServiceProvider/ApiProvider.php | 2 ++ tests/integration/TaskMetadataProcedureTest.php | 45 +++++++++++++++++++++++++ tests/integration/TaskProcedureTest.php | 38 --------------------- 5 files changed, 86 insertions(+), 64 deletions(-) create mode 100644 app/Api/Procedure/TaskMetadataProcedure.php create mode 100644 tests/integration/TaskMetadataProcedureTest.php (limited to 'tests/integration/TaskProcedureTest.php') diff --git a/app/Api/Procedure/TaskMetadataProcedure.php b/app/Api/Procedure/TaskMetadataProcedure.php new file mode 100644 index 00000000..169482f5 --- /dev/null +++ b/app/Api/Procedure/TaskMetadataProcedure.php @@ -0,0 +1,38 @@ +container)->check($this->getClassName(), 'getTask', $task_id); + return $this->taskMetadataModel->getAll($task_id); + } + + public function getTaskMetadataByName($task_id, $name) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id); + return $this->taskMetadataModel->get($task_id, $name); + } + + public function saveTaskMetadata($task_id, array $values) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id); + return $this->taskMetadataModel->save($task_id, $values); + } + + public function removeTaskMetadata($task_id, $name) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id); + return $this->taskMetadataModel->remove($task_id, $name); + } +} diff --git a/app/Api/Procedure/TaskProcedure.php b/app/Api/Procedure/TaskProcedure.php index 59075b13..ee9242d1 100644 --- a/app/Api/Procedure/TaskProcedure.php +++ b/app/Api/Procedure/TaskProcedure.php @@ -6,7 +6,6 @@ use Kanboard\Api\Authorization\ProjectAuthorization; use Kanboard\Api\Authorization\TaskAuthorization; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Model\TaskModel; -use Kanboard\Model\TaskMetadataModel; /** * Task API controller @@ -16,30 +15,6 @@ use Kanboard\Model\TaskMetadataModel; */ class TaskProcedure extends BaseProcedure { - public function getTaskMetadata($task_id) - { - TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id); - return $this->taskMetadataModel->getAll($task_id); - } - - public function getTaskMetadataByName($task_id, $name) - { - TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id); - return $this->taskMetadataModel->get($task_id, $name); - } - - public function saveTaskMetadata($task_id, array $values) - { - TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id); - return $this->taskMetadataModel->save($task_id, $values); - } - - public function removeTaskMetadata($task_id, $name) - { - TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id); - return $this->taskMetadataModel->remove($task_id, $name); - } - public function searchTasks($project_id, $query) { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'searchTasks', $project_id); @@ -117,7 +92,7 @@ class TaskProcedure extends BaseProcedure $recurrence_basedate = 0, $reference = '') { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTask', $project_id); - + if ($owner_id !== 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { return false; } diff --git a/app/ServiceProvider/ApiProvider.php b/app/ServiceProvider/ApiProvider.php index 5cf6231c..d5d1f260 100644 --- a/app/ServiceProvider/ApiProvider.php +++ b/app/ServiceProvider/ApiProvider.php @@ -22,6 +22,7 @@ use Kanboard\Api\Procedure\ProjectPermissionProcedure; use Kanboard\Api\Procedure\SubtaskProcedure; use Kanboard\Api\Procedure\SubtaskTimeTrackingProcedure; use Kanboard\Api\Procedure\SwimlaneProcedure; +use Kanboard\Api\Procedure\TaskMetadataProcedure; use Kanboard\Api\Procedure\TaskProcedure; use Kanboard\Api\Procedure\TaskLinkProcedure; use Kanboard\Api\Procedure\UserProcedure; @@ -69,6 +70,7 @@ class ApiProvider implements ServiceProviderInterface ->withObject(new TaskProcedure($container)) ->withObject(new TaskLinkProcedure($container)) ->withObject(new TaskExternalLinkProcedure($container)) + ->withObject(new TaskMetadataProcedure($container)) ->withObject(new UserProcedure($container)) ->withObject(new GroupProcedure($container)) ->withObject(new GroupMemberProcedure($container)) diff --git a/tests/integration/TaskMetadataProcedureTest.php b/tests/integration/TaskMetadataProcedureTest.php new file mode 100644 index 00000000..9b9b2f39 --- /dev/null +++ b/tests/integration/TaskMetadataProcedureTest.php @@ -0,0 +1,45 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertSaveTaskMetadata(); + $this->assertGetTaskMetadata(); + $this->assertGetTaskMetadataByName(); + $this->assertRemoveTaskMetadata(); + } + + public function assertSaveTaskMetadata() + { + $this->assertTrue($this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1'))); + } + + public function assertGetTaskMetadata() + { + $metaData = $this->app->getTaskMetadata(($this->taskId)); + $this->assertArrayHasKey($this->metaKey, $metaData); + $this->assertEquals('metaValue1', $metaData[$this->metaKey]); + } + + public function assertGetTaskMetadataByName() + { + $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey); + $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value'); + } + + public function assertRemoveTaskMetadata() + { + $result = $this->app->removeTaskMetadata($this->taskId, $this->metaKey); + $this->assertTrue($result, 'Did not remove metakey with success'); + $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey); + $this->assertEquals('', $metaValue, 'Did not return an empty string due to metadata being deleted'); + } +} diff --git a/tests/integration/TaskProcedureTest.php b/tests/integration/TaskProcedureTest.php index 8b3e622c..f456ae52 100644 --- a/tests/integration/TaskProcedureTest.php +++ b/tests/integration/TaskProcedureTest.php @@ -5,7 +5,6 @@ require_once __DIR__.'/BaseProcedureTest.php'; class TaskProcedureTest extends BaseProcedureTest { protected $projectName = 'My project to test tasks'; - protected $metaKey = 'MyTestMetaKey'; public function testAll() { @@ -16,43 +15,6 @@ class TaskProcedureTest extends BaseProcedureTest $this->assertGetTaskByReference(); $this->assertGetAllTasks(); $this->assertOpenCloseTask(); - $this->assertSaveTaskMetadata(); - $this->assertGetTaskMetadata(); - $this->assertGetTaskMetadataByName(); - $this->assertRemoveTaskMetadata(); - } - - public function assertSaveTaskMetadata() - { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); - $this->assertTrue($createMetaKey); - } - - public function assertGetTaskMetadata() - { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); - $this->assertTrue($createMetaKey,'Did not create metakey with success'); - $metaData = $this->app->getTaskMetadata(($this->taskId)); - $this->assertArrayHasKey($this->metaKey, $metaData); - $this->assertEquals('metaValue1', $metaData[$this->metaKey]); - } - - public function assertGetTaskMetadataByName() - { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); - $this->assertTrue($createMetaKey,'Did not create metakey with success'); - $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); - $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value'); - } - - public function assertRemoveTaskMetadata() - { - $createMetaKey = $this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')); - $this->assertTrue($createMetaKey,'Did not create metakey with success'); - $metaValue = $this->app->removeTaskMetadata($this->taskId,$this->metaKey); - $this->assertTrue($metaValue,'Did not remove metakey with success'); - $metaValue = $this->app->getTaskMetadataByName($this->taskId,$this->metaKey); - $this->assertEquals('',$metaValue,'Did not return an empty string due to metadata being deleted'); } public function assertUpdateTask() -- cgit v1.2.3