diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | app/Api/Base.php | 10 | ||||
-rw-r--r-- | app/Api/Me.php | 12 | ||||
-rw-r--r-- | app/Model/Project.php | 10 | ||||
-rw-r--r-- | app/Model/TaskFinder.php | 74 | ||||
-rw-r--r-- | composer.json | 2 | ||||
-rw-r--r-- | composer.lock | 12 | ||||
-rw-r--r-- | tests/functionals/ApiTest.php | 27 | ||||
-rw-r--r-- | tests/functionals/UserApiTest.php | 55 | ||||
-rw-r--r-- | tests/units/Model/ProjectTest.php | 11 | ||||
-rw-r--r-- | tests/units/Model/TaskFinderTest.php | 51 |
11 files changed, 194 insertions, 73 deletions
@@ -7,7 +7,8 @@ New features: * Add swimlane description * New plugin system (alpha) * Added Bahasa Indonesia translation -* Api changes: new getMyOverdueTasks, new getOverdueTasksByProject, allow getProjectActivity for user-api, new GetMyProjects +* Added API procedures: getMyOverdueTasks, getOverdueTasksByProject and GetMyProjects +* Added user API access for procedure getProjectActivity() Breaking changes: diff --git a/app/Api/Base.php b/app/Api/Base.php index c1be1878..fef36e0c 100644 --- a/app/Api/Base.php +++ b/app/Api/Base.php @@ -19,8 +19,8 @@ abstract class Base extends \Core\Base 'getMyActivityStream', 'createMyPrivateProject', 'getMyProjectsList', - 'getMyOverdueTasks', 'getMyProjects', + 'getMyOverdueTasks', ); private $both_allowed_procedures = array( @@ -70,7 +70,7 @@ abstract class Base extends \Core\Base } } - protected function formatTask($task) + protected function formatTask(array $task) { if (! empty($task)) { $task['url'] = $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); @@ -80,7 +80,7 @@ abstract class Base extends \Core\Base return $task; } - protected function formatTasks($tasks) + protected function formatTasks(array $tasks) { if (! empty($tasks)) { foreach ($tasks as &$task) { @@ -91,7 +91,7 @@ abstract class Base extends \Core\Base return $tasks; } - protected function formatProject($project) + protected function formatProject(array $project) { if (! empty($project)) { $project['url'] = array( @@ -104,7 +104,7 @@ abstract class Base extends \Core\Base return $project; } - protected function formatProjects($projects) + protected function formatProjects(array $projects) { if (! empty($projects)) { foreach ($projects as &$project) { diff --git a/app/Api/Me.php b/app/Api/Me.php index ff317557..e7611554 100644 --- a/app/Api/Me.php +++ b/app/Api/Me.php @@ -33,7 +33,8 @@ class Me extends Base public function getMyActivityStream() { - return $this->projectActivity->getProjects($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()), 100); + $project_ids = $this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()); + return $this->projectActivity->getProjects($project_ids, 100); } public function createMyPrivateProject($name, $description = null) @@ -52,14 +53,17 @@ class Me extends Base { return $this->projectPermission->getMemberProjects($this->userSession->getId()); } - + public function getMyOverdueTasks() { return $this->taskFinder->getOverdueTasksByUser($this->userSession->getId()); } - + public function getMyProjects() { - return $this->formatProjects($this->project->getAllByIds($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()))); + $project_ids = $this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()); + $projects = $this->project->getAllByIds($project_ids); + + return $this->formatProjects($projects); } } diff --git a/app/Model/Project.php b/app/Model/Project.php index 6e4cfcfd..8ddcc443 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -172,16 +172,20 @@ class Project extends Base { return $this->db->table(self::TABLE)->asc('name')->findAll(); } - + /** * Get all projects with given Ids * * @access public - * @param integer[] $project_ids Projects id + * @param integer[] $project_ids * @return array */ - public function getAllByIds($project_ids) + public function getAllByIds(array $project_ids) { + if (empty($project_ids)) { + return array(); + } + return $this->db->table(self::TABLE)->in('id', $project_ids)->asc('name')->findAll(); } diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php index 6cdf9146..e9735d81 100644 --- a/app/Model/TaskFinder.php +++ b/app/Model/TaskFinder.php @@ -177,14 +177,14 @@ class TaskFinder extends Base } /** - * Get a list of overdue tasks for all projects + * Get overdue tasks query * * @access public - * @return array + * @return \PicoDb\Table */ - public function getOverdueTasks() + public function getOverdueTasksQuery() { - $tasks = $this->db->table(Task::TABLE) + return $this->db->table(Task::TABLE) ->columns( Task::TABLE.'.id', Task::TABLE.'.title', @@ -201,74 +201,42 @@ class TaskFinder extends Base ->eq(Project::TABLE.'.is_active', 1) ->eq(Task::TABLE.'.is_active', 1) ->neq(Task::TABLE.'.date_due', 0) - ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)) - ->findAll(); + ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)); + } - return $tasks; + /** + * Get a list of overdue tasks for all projects + * + * @access public + * @return array + */ + public function getOverdueTasks() + { + return $this->getOverdueTasksQuery()->findAll(); } - + /** * Get a list of overdue tasks by project * * @access public + * @param integer $project_id * @return array */ public function getOverdueTasksByProject($project_id) { - $tasks = $this->db->table(Task::TABLE) - ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', - Task::TABLE.'.date_due', - Task::TABLE.'.project_id', - Task::TABLE.'.creator_id', - Task::TABLE.'.owner_id', - Project::TABLE.'.name AS project_name', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name' - ) - ->join(Project::TABLE, 'id', 'project_id') - ->join(User::TABLE, 'id', 'owner_id') - ->eq(Project::TABLE.'.is_active', 1) - ->eq(Task::TABLE.'.project_id', $project_id) - ->eq(Task::TABLE.'.is_active', 1) - ->neq(Task::TABLE.'.date_due', 0) - ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)) - ->findAll(); - - return $tasks; + return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.project_id', $project_id)->findAll(); } - + /** * Get a list of overdue tasks by user * * @access public + * @param integer $user_id * @return array */ public function getOverdueTasksByUser($user_id) { - $tasks = $this->db->table(Task::TABLE) - ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', - Task::TABLE.'.date_due', - Task::TABLE.'.project_id', - Task::TABLE.'.creator_id', - Task::TABLE.'.owner_id', - Project::TABLE.'.name AS project_name', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name' - ) - ->join(Project::TABLE, 'id', 'project_id') - ->join(User::TABLE, 'id', 'owner_id') - ->eq(Project::TABLE.'.is_active', 1) - ->eq(Task::TABLE.'.owner_id', $user_id) - ->eq(Task::TABLE.'.is_active', 1) - ->neq(Task::TABLE.'.date_due', 0) - ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)) - ->findAll(); - - return $tasks; + return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.owner_id', $user_id)->findAll(); } /** diff --git a/composer.json b/composer.json index 223aa1fc..e7f1e0b1 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "eluceo/ical": "0.8.0", "erusev/parsedown" : "1.5.4", "fabiang/xmpp" : "0.6.1", - "fguillot/json-rpc" : "1.0.2", + "fguillot/json-rpc" : "1.0.3", "fguillot/picodb" : "1.0.2", "fguillot/simpleLogger" : "1.0.0", "fguillot/simple-validator" : "1.0.0", diff --git a/composer.lock b/composer.lock index 415305cf..ca0034c9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "10de302e730ebc3076393a3a38d1964f", + "hash": "66d81a6b6a317dfb617413cf9d971bc0", "packages": [ { "name": "christian-riesen/base32", @@ -260,16 +260,16 @@ }, { "name": "fguillot/json-rpc", - "version": "v1.0.2", + "version": "v1.0.3", "source": { "type": "git", "url": "https://github.com/fguillot/JsonRPC.git", - "reference": "265cf039c2823f684349de78c0c03a597992bea9" + "reference": "0a77cd311783431c851e4c8eed33858663c17277" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/265cf039c2823f684349de78c0c03a597992bea9", - "reference": "265cf039c2823f684349de78c0c03a597992bea9", + "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/0a77cd311783431c851e4c8eed33858663c17277", + "reference": "0a77cd311783431c851e4c8eed33858663c17277", "shasum": "" }, "require": { @@ -292,7 +292,7 @@ ], "description": "Simple Json-RPC client/server library that just works", "homepage": "https://github.com/fguillot/JsonRPC", - "time": "2015-09-12 16:27:13" + "time": "2015-09-19 02:27:10" }, { "name": "fguillot/picodb", diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index 284c31b9..17741771 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -1055,4 +1055,31 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals('TICKET-1234', $task['reference']); $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } + + public function testCreateOverdueTask() + { + $this->assertNotFalse($this->client->createTask(array( + 'title' => 'overdue task', + 'project_id' => 1, + 'date_due' => date('Y-m-d', strtotime('-2days')), + ))); + } + + public function testGetOverdueTasksByProject() + { + $tasks = $this->client->getOverdueTasksByProject(1); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('API test', $tasks[0]['project_name']); + } + + public function testGetOverdueTasks() + { + $tasks = $this->client->getOverdueTasks(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('API test', $tasks[0]['project_name']); + } }
\ No newline at end of file diff --git a/tests/functionals/UserApiTest.php b/tests/functionals/UserApiTest.php index e2c693dd..96df14ff 100644 --- a/tests/functionals/UserApiTest.php +++ b/tests/functionals/UserApiTest.php @@ -121,6 +121,7 @@ class UserApi extends PHPUnit_Framework_TestCase { $profile = $this->user->getMe(); $this->assertNotEmpty($profile); + $this->assertEquals(2, $profile['id']); $this->assertEquals('user', $profile['username']); } @@ -138,6 +139,18 @@ class UserApi extends PHPUnit_Framework_TestCase $this->assertEquals('my project', $projects[2]); } + public function testGetMyProjects() + { + $projects = $this->user->getMyProjects(); + $this->assertNotEmpty($projects); + $this->assertCount(1, $projects); + $this->assertEquals(2, $projects[0]['id']); + $this->assertEquals('my project', $projects[0]['name']); + $this->assertNotEmpty($projects[0]['url']['calendar']); + $this->assertNotEmpty($projects[0]['url']['board']); + $this->assertNotEmpty($projects[0]['url']['list']); + } + public function testGetProjectById() { $project = $this->user->getProjectById(2); @@ -172,6 +185,20 @@ class UserApi extends PHPUnit_Framework_TestCase $this->user->getTask(2); } + /** + * @expectedException JsonRPC\AccessDeniedException + */ + public function testGetProjectActivityDenied() + { + $this->user->getProjectActivity(1); + } + + public function testGetProjectActivityAllowed() + { + $activity = $this->user->getProjectActivity(2); + $this->assertNotEmpty($activity); + } + public function testGetMyActivityStream() { $activity = $this->user->getMyActivityStream(); @@ -222,4 +249,32 @@ class UserApi extends PHPUnit_Framework_TestCase { $this->assertNotEmpty($this->user->getBoard(2)); } + + public function testCreateOverdueTask() + { + $this->assertNotFalse($this->user->createTask(array( + 'title' => 'overdue task', + 'project_id' => 2, + 'date_due' => date('Y-m-d', strtotime('-2days')), + 'owner_id' => 2, + ))); + } + + public function testGetMyOverdueTasks() + { + $tasks = $this->user->getMyOverdueTasks(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('my project', $tasks[0]['project_name']); + } + + public function testGetOverdueTasksByProject() + { + $tasks = $this->user->getOverdueTasksByProject(2); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('my project', $tasks[0]['project_name']); + } } diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 9d7b6c0d..3373037d 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -133,6 +133,17 @@ class ProjectTest extends Base $this->assertGreaterThan($now, $project['last_modified']); } + public function testGetAllIds() + { + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + + $this->assertEmpty($p->getAllByIds(array())); + $this->assertNotEmpty($p->getAllByIds(array(1, 2))); + $this->assertCount(1, $p->getAllByIds(array(1))); + } + public function testIsLastModified() { $p = new Project($this->container); diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index da0db7a7..3601efdd 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -30,4 +30,55 @@ class TaskFinderTest extends Base $this->assertEquals(1, count($tasks)); $this->assertEquals('Task #1', $tasks[0]['title']); } + + public function testGetOverdueTasksByProject() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day')))); + $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day')))); + $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0))); + $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1))); + + $tasks = $tf->getOverdueTasksByProject(1); + $this->assertNotEmpty($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals(1, count($tasks)); + $this->assertEquals('Task #1', $tasks[0]['title']); + } + + public function testGetOverdueTasksByUser() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day')))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day')))); + $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day')))); + $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0))); + $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1))); + + $tasks = $tf->getOverdueTasksByUser(1); + $this->assertNotEmpty($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals(2, count($tasks)); + + $this->assertEquals(1, $tasks[0]['id']); + $this->assertEquals('Task #1', $tasks[0]['title']); + $this->assertEquals(1, $tasks[0]['owner_id']); + $this->assertEquals(1, $tasks[0]['project_id']); + $this->assertEquals('Project #1', $tasks[0]['project_name']); + $this->assertEquals('admin', $tasks[0]['assignee_username']); + $this->assertEquals('', $tasks[0]['assignee_name']); + + $this->assertEquals('Task #2', $tasks[1]['title']); + } } |