From 922e0fb6de06a98774418612e0b0f75af72b6dbb Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 25 Jun 2016 14:34:46 -0400 Subject: Rewrite integration tests to run with Docker containers --- doc/api-project-procedures.markdown | 4 +-- doc/tests.markdown | 49 +++++++++++++++---------------------- 2 files changed, 22 insertions(+), 31 deletions(-) (limited to 'doc') diff --git a/doc/api-project-procedures.markdown b/doc/api-project-procedures.markdown index 6cc1b15b..f8e2cc5e 100644 --- a/doc/api-project-procedures.markdown +++ b/doc/api-project-procedures.markdown @@ -183,7 +183,7 @@ Response example: - Purpose: **Update a project** - Parameters: - - **id** (integer, required) + - **project_id** (integer, required) - **name** (string, required) - **description** (string, optional) - Result on success: **true** @@ -197,7 +197,7 @@ Request example: "method": "updateProject", "id": 1853996288, "params": { - "id": 1, + "project_id": 1, "name": "PHP client update" } } diff --git a/doc/tests.markdown b/doc/tests.markdown index 5e3d71d2..59177f87 100644 --- a/doc/tests.markdown +++ b/doc/tests.markdown @@ -9,7 +9,7 @@ Requirements ------------ - Linux/Unix machine -- PHP cli +- PHP - PHPUnit installed - Mysql and Postgresql (optional) - Selenium (optional) @@ -85,46 +85,37 @@ From your Kanboard directory, run the command `phpunit -c tests/units.postgres.x Integration Tests ----------------- -Acceptance tests (also known as end-to-end tests and sometimes functional tests) allow us to test the actual functionality of the browser using Selenium and PHPUnit. +Integration tests are mainly used to test the API. +The test suites are making real HTTP calls to the application that run inside a container. -The PHPUnit config file is `tests/acceptance.xml`. -From your Kanboard directory, run the command `phpunit -c tests/units.sqlite.xml`. - -Actually only the API calls are tested. - -Real HTTP calls are made with those tests. -So a local instance of Kanboard is necessary and must listen on `http://localhost:8000/`. - -All data will be removed/altered by the test suite. -Moreover the script will reset and set a new API key. +### Requirements -1. Start a local instance of Kanboard `php -S 127.0.0.1:8000` -2. Run the test suite from another terminal +- PHP +- Composer +- Unix operating system (Mac OS or Linux) +- Docker +- Docker Compose -The same method as above is used to run tests across different databases: +### Running integration tests -- Sqlite: `phpunit -c tests/integration.sqlite.xml` -- Mysql: `phpunit -c tests/integration.mysql.xml` -- Postgresql: `phpunit -c tests/integration.postgres.xml` +Integration tests are using Docker containers. +There are 3 different environment available to run tests against each supported database. -Example: +You can use these commands to run each test suite: ```bash -phpunit -c tests/integration.sqlite.xml - -PHPUnit 5.0.0 by Sebastian Bergmann and contributors. +# Run tests with Sqlite +make integration-test-sqlite -............................................................... 63 / 135 ( 46%) -............................................................... 126 / 135 ( 93%) -......... 135 / 135 (100%) +# Run tests with Mysql +make integration-test-mysql -Time: 1.18 minutes, Memory: 14.75Mb - -OK (135 tests, 526 assertions) +# Run tests with Postgres +make integration-test-postgres ``` Acceptance Tests ------------------ +---------------- Acceptance tests (also sometimes known as end-to-end tests, and functional tests) test the actual functionality of the UI in a browser using Selenium. -- cgit v1.2.3 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 --- ChangeLog | 4 + app/Api/ActionApi.php | 87 ---- app/Api/AppApi.php | 49 -- app/Api/Authorization/ActionAuthorization.php | 19 + app/Api/Authorization/CategoryAuthorization.php | 19 + app/Api/Authorization/ColumnAuthorization.php | 19 + app/Api/Authorization/CommentAuthorization.php | 19 + app/Api/Authorization/ProcedureAuthorization.php | 32 ++ app/Api/Authorization/ProjectAuthorization.php | 35 ++ app/Api/Authorization/SubtaskAuthorization.php | 19 + app/Api/Authorization/TaskAuthorization.php | 19 + app/Api/Authorization/TaskFileAuthorization.php | 19 + app/Api/Authorization/TaskLinkAuthorization.php | 19 + app/Api/Authorization/UserAuthorization.php | 22 + app/Api/BaseApi.php | 85 ---- app/Api/BoardApi.php | 24 - app/Api/CategoryApi.php | 51 -- app/Api/ColumnApi.php | 42 -- app/Api/CommentApi.php | 54 --- app/Api/GroupApi.php | 51 -- app/Api/GroupMemberApi.php | 39 -- app/Api/LinkApi.php | 113 ----- app/Api/MeApi.php | 72 --- app/Api/Middleware/AuthenticationApiMiddleware.php | 137 ------ app/Api/Middleware/AuthenticationMiddleware.php | 82 ++++ app/Api/Procedure/ActionProcedure.php | 91 ++++ app/Api/Procedure/AppProcedure.php | 47 ++ app/Api/Procedure/BaseProcedure.php | 86 ++++ app/Api/Procedure/BoardProcedure.php | 25 + app/Api/Procedure/CategoryProcedure.php | 59 +++ app/Api/Procedure/ColumnProcedure.php | 51 ++ app/Api/Procedure/CommentProcedure.php | 62 +++ app/Api/Procedure/GroupMemberProcedure.php | 37 ++ app/Api/Procedure/GroupProcedure.php | 49 ++ app/Api/Procedure/LinkProcedure.php | 111 +++++ app/Api/Procedure/MeProcedure.php | 72 +++ app/Api/Procedure/ProjectPermissionProcedure.php | 69 +++ app/Api/Procedure/ProjectProcedure.php | 106 +++++ app/Api/Procedure/SubtaskProcedure.php | 74 +++ app/Api/Procedure/SubtaskTimeTrackingProcedure.php | 39 ++ app/Api/Procedure/SwimlaneProcedure.php | 91 ++++ app/Api/Procedure/TaskFileProcedure.php | 70 +++ app/Api/Procedure/TaskLinkProcedure.php | 85 ++++ app/Api/Procedure/TaskProcedure.php | 167 +++++++ app/Api/Procedure/UserProcedure.php | 131 +++++ app/Api/ProjectApi.php | 87 ---- app/Api/ProjectPermissionApi.php | 55 --- app/Api/SubtaskApi.php | 66 --- app/Api/SubtaskTimeTrackingApi.php | 34 -- app/Api/SwimlaneApi.php | 80 ---- app/Api/TaskApi.php | 163 ------- app/Api/TaskFileApi.php | 59 --- app/Api/TaskLinkApi.php | 79 --- app/Api/UserApi.php | 131 ----- app/Core/Base.php | 4 + app/Model/ActionModel.php | 12 + app/Model/CategoryModel.php | 12 + app/Model/ColumnModel.php | 12 + app/Model/CommentModel.php | 16 + app/Model/SubtaskModel.php | 16 + app/Model/TaskFileModel.php | 16 + app/Model/TaskLinkModel.php | 16 + app/ServiceProvider/ApiProvider.php | 83 ++-- app/ServiceProvider/AuthenticationProvider.php | 57 +++ composer.json | 2 +- composer.lock | 251 ++++++++-- doc/api-authentication.markdown | 55 +-- doc/api-json-rpc.markdown | 12 +- doc/api-project-permission-procedures.markdown | 33 ++ doc/api-project-procedures.markdown | 4 + tests/integration/ActionProcedureTest.php | 66 +++ tests/integration/ActionTest.php | 66 --- tests/integration/AppProcedureTest.php | 54 +++ tests/integration/AppTest.php | 54 --- tests/integration/BaseIntegrationTest.php | 122 ----- tests/integration/BaseProcedureTest.php | 122 +++++ tests/integration/BoardProcedureTest.php | 25 + tests/integration/BoardTest.php | 25 - tests/integration/CategoryProcedureTest.php | 76 +++ tests/integration/CategoryTest.php | 76 --- tests/integration/ColumnProcedureTest.php | 69 +++ tests/integration/ColumnTest.php | 69 --- tests/integration/CommentProcedureTest.php | 63 +++ tests/integration/CommentTest.php | 63 --- tests/integration/GroupMemberProcedureTest.php | 53 +++ tests/integration/GroupMemberTest.php | 53 --- tests/integration/GroupProcedureTest.php | 50 ++ tests/integration/GroupTest.php | 50 -- tests/integration/LinkProcedureTest.php | 70 +++ tests/integration/LinkTest.php | 70 --- tests/integration/MeProcedureTest.php | 68 +++ tests/integration/MeTest.php | 73 --- tests/integration/OverdueTaskProcedureTest.php | 43 ++ tests/integration/OverdueTaskTest.php | 43 -- tests/integration/ProcedureAuthorizationTest.php | 306 ++++++++++++ .../integration/ProjectPermissionProcedureTest.php | 89 ++++ tests/integration/ProjectPermissionTest.php | 89 ---- tests/integration/ProjectProcedureTest.php | 89 ++++ tests/integration/ProjectTest.php | 89 ---- tests/integration/SubtaskProcedureTest.php | 64 +++ tests/integration/SubtaskTest.php | 64 --- tests/integration/SwimlaneProcedureTest.php | 93 ++++ tests/integration/SwimlaneTest.php | 93 ---- tests/integration/TaskFileProcedureTest.php | 67 +++ tests/integration/TaskFileTest.php | 67 --- tests/integration/TaskLinkProcedureTest.php | 68 +++ tests/integration/TaskLinkTest.php | 68 --- tests/integration/TaskProcedureTest.php | 55 +++ tests/integration/TaskTest.php | 55 --- tests/integration/UserProcedureTest.php | 63 +++ tests/integration/UserTest.php | 63 --- tests/units/Model/ActionModelTest.php | 527 +++++++++++++++++++++ tests/units/Model/ActionTest.php | 509 -------------------- tests/units/Model/CategoryModelTest.php | 229 +++++++++ tests/units/Model/CategoryTest.php | 217 --------- tests/units/Model/CommentTest.php | 86 ++-- tests/units/Model/SubtaskModelTest.php | 400 ++++++++++++++++ tests/units/Model/SubtaskTest.php | 388 --------------- tests/units/Model/TaskFileModelTest.php | 458 ++++++++++++++++++ tests/units/Model/TaskFileTest.php | 445 ----------------- tests/units/Model/TaskLinkModelTest.php | 211 +++++++++ tests/units/Model/TaskLinkTest.php | 196 -------- 122 files changed, 5845 insertions(+), 4834 deletions(-) delete mode 100644 app/Api/ActionApi.php delete mode 100644 app/Api/AppApi.php create mode 100644 app/Api/Authorization/ActionAuthorization.php create mode 100644 app/Api/Authorization/CategoryAuthorization.php create mode 100644 app/Api/Authorization/ColumnAuthorization.php create mode 100644 app/Api/Authorization/CommentAuthorization.php create mode 100644 app/Api/Authorization/ProcedureAuthorization.php create mode 100644 app/Api/Authorization/ProjectAuthorization.php create mode 100644 app/Api/Authorization/SubtaskAuthorization.php create mode 100644 app/Api/Authorization/TaskAuthorization.php create mode 100644 app/Api/Authorization/TaskFileAuthorization.php create mode 100644 app/Api/Authorization/TaskLinkAuthorization.php create mode 100644 app/Api/Authorization/UserAuthorization.php delete mode 100644 app/Api/BaseApi.php delete mode 100644 app/Api/BoardApi.php delete mode 100644 app/Api/CategoryApi.php delete mode 100644 app/Api/ColumnApi.php delete mode 100644 app/Api/CommentApi.php delete mode 100644 app/Api/GroupApi.php delete mode 100644 app/Api/GroupMemberApi.php delete mode 100644 app/Api/LinkApi.php delete mode 100644 app/Api/MeApi.php delete mode 100644 app/Api/Middleware/AuthenticationApiMiddleware.php create mode 100644 app/Api/Middleware/AuthenticationMiddleware.php create mode 100644 app/Api/Procedure/ActionProcedure.php create mode 100644 app/Api/Procedure/AppProcedure.php create mode 100644 app/Api/Procedure/BaseProcedure.php create mode 100644 app/Api/Procedure/BoardProcedure.php create mode 100644 app/Api/Procedure/CategoryProcedure.php create mode 100644 app/Api/Procedure/ColumnProcedure.php create mode 100644 app/Api/Procedure/CommentProcedure.php create mode 100644 app/Api/Procedure/GroupMemberProcedure.php create mode 100644 app/Api/Procedure/GroupProcedure.php create mode 100644 app/Api/Procedure/LinkProcedure.php create mode 100644 app/Api/Procedure/MeProcedure.php create mode 100644 app/Api/Procedure/ProjectPermissionProcedure.php create mode 100644 app/Api/Procedure/ProjectProcedure.php create mode 100644 app/Api/Procedure/SubtaskProcedure.php create mode 100644 app/Api/Procedure/SubtaskTimeTrackingProcedure.php create mode 100644 app/Api/Procedure/SwimlaneProcedure.php create mode 100644 app/Api/Procedure/TaskFileProcedure.php create mode 100644 app/Api/Procedure/TaskLinkProcedure.php create mode 100644 app/Api/Procedure/TaskProcedure.php create mode 100644 app/Api/Procedure/UserProcedure.php delete mode 100644 app/Api/ProjectApi.php delete mode 100644 app/Api/ProjectPermissionApi.php delete mode 100644 app/Api/SubtaskApi.php delete mode 100644 app/Api/SubtaskTimeTrackingApi.php delete mode 100644 app/Api/SwimlaneApi.php delete mode 100644 app/Api/TaskApi.php delete mode 100644 app/Api/TaskFileApi.php delete mode 100644 app/Api/TaskLinkApi.php delete mode 100644 app/Api/UserApi.php create mode 100644 tests/integration/ActionProcedureTest.php delete mode 100644 tests/integration/ActionTest.php create mode 100644 tests/integration/AppProcedureTest.php delete mode 100644 tests/integration/AppTest.php delete mode 100644 tests/integration/BaseIntegrationTest.php create mode 100644 tests/integration/BaseProcedureTest.php create mode 100644 tests/integration/BoardProcedureTest.php delete mode 100644 tests/integration/BoardTest.php create mode 100644 tests/integration/CategoryProcedureTest.php delete mode 100644 tests/integration/CategoryTest.php create mode 100644 tests/integration/ColumnProcedureTest.php delete mode 100644 tests/integration/ColumnTest.php create mode 100644 tests/integration/CommentProcedureTest.php delete mode 100644 tests/integration/CommentTest.php create mode 100644 tests/integration/GroupMemberProcedureTest.php delete mode 100644 tests/integration/GroupMemberTest.php create mode 100644 tests/integration/GroupProcedureTest.php delete mode 100644 tests/integration/GroupTest.php create mode 100644 tests/integration/LinkProcedureTest.php delete mode 100644 tests/integration/LinkTest.php create mode 100644 tests/integration/MeProcedureTest.php delete mode 100644 tests/integration/MeTest.php create mode 100644 tests/integration/OverdueTaskProcedureTest.php delete mode 100644 tests/integration/OverdueTaskTest.php create mode 100644 tests/integration/ProcedureAuthorizationTest.php create mode 100644 tests/integration/ProjectPermissionProcedureTest.php delete mode 100644 tests/integration/ProjectPermissionTest.php create mode 100644 tests/integration/ProjectProcedureTest.php delete mode 100644 tests/integration/ProjectTest.php create mode 100644 tests/integration/SubtaskProcedureTest.php delete mode 100644 tests/integration/SubtaskTest.php create mode 100644 tests/integration/SwimlaneProcedureTest.php delete mode 100644 tests/integration/SwimlaneTest.php create mode 100644 tests/integration/TaskFileProcedureTest.php delete mode 100644 tests/integration/TaskFileTest.php create mode 100644 tests/integration/TaskLinkProcedureTest.php delete mode 100644 tests/integration/TaskLinkTest.php create mode 100644 tests/integration/TaskProcedureTest.php delete mode 100644 tests/integration/TaskTest.php create mode 100644 tests/integration/UserProcedureTest.php delete mode 100644 tests/integration/UserTest.php create mode 100644 tests/units/Model/ActionModelTest.php delete mode 100644 tests/units/Model/ActionTest.php create mode 100644 tests/units/Model/CategoryModelTest.php delete mode 100644 tests/units/Model/CategoryTest.php create mode 100644 tests/units/Model/SubtaskModelTest.php delete mode 100644 tests/units/Model/SubtaskTest.php create mode 100644 tests/units/Model/TaskFileModelTest.php delete mode 100644 tests/units/Model/TaskFileTest.php create mode 100644 tests/units/Model/TaskLinkModelTest.php delete mode 100644 tests/units/Model/TaskLinkTest.php (limited to 'doc') diff --git a/ChangeLog b/ChangeLog index b86fea57..42af8ee3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ Version 1.0.31 (unreleased) -------------- +New features: + +* Added application and project roles validation for API procedure calls + Improvements: * Rewrite integration tests to run with Docker containers diff --git a/app/Api/ActionApi.php b/app/Api/ActionApi.php deleted file mode 100644 index 116742d8..00000000 --- a/app/Api/ActionApi.php +++ /dev/null @@ -1,87 +0,0 @@ -actionManager->getAvailableActions(); - } - - public function getAvailableActionEvents() - { - return $this->eventManager->getAll(); - } - - public function getCompatibleActionEvents($action_name) - { - return $this->actionManager->getCompatibleEvents($action_name); - } - - public function removeAction($action_id) - { - return $this->actionModel->remove($action_id); - } - - public function getActions($project_id) - { - return $this->actionModel->getAllByProject($project_id); - } - - public function createAction($project_id, $event_name, $action_name, array $params) - { - $values = array( - 'project_id' => $project_id, - 'event_name' => $event_name, - 'action_name' => $action_name, - 'params' => $params, - ); - - list($valid, ) = $this->actionValidator->validateCreation($values); - - if (! $valid) { - return false; - } - - // Check if the action exists - $actions = $this->actionManager->getAvailableActions(); - - if (! isset($actions[$action_name])) { - return false; - } - - // Check the event - $action = $this->actionManager->getAction($action_name); - - if (! in_array($event_name, $action->getEvents())) { - return false; - } - - $required_params = $action->getActionRequiredParameters(); - - // Check missing parameters - foreach ($required_params as $param => $value) { - if (! isset($params[$param])) { - return false; - } - } - - // Check extra parameters - foreach ($params as $param => $value) { - if (! isset($required_params[$param])) { - return false; - } - } - - return $this->actionModel->create($values); - } -} diff --git a/app/Api/AppApi.php b/app/Api/AppApi.php deleted file mode 100644 index 637de5c5..00000000 --- a/app/Api/AppApi.php +++ /dev/null @@ -1,49 +0,0 @@ -timezoneModel->getCurrentTimezone(); - } - - public function getVersion() - { - return APP_VERSION; - } - - public function getDefaultTaskColor() - { - return $this->colorModel->getDefaultColor(); - } - - public function getDefaultTaskColors() - { - return $this->colorModel->getDefaultColors(); - } - - public function getColorList() - { - return $this->colorModel->getList(); - } - - public function getApplicationRoles() - { - return $this->role->getApplicationRoles(); - } - - public function getProjectRoles() - { - return $this->role->getProjectRoles(); - } -} diff --git a/app/Api/Authorization/ActionAuthorization.php b/app/Api/Authorization/ActionAuthorization.php new file mode 100644 index 00000000..4b41ad82 --- /dev/null +++ b/app/Api/Authorization/ActionAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->actionModel->getProjectId($action_id)); + } + } +} diff --git a/app/Api/Authorization/CategoryAuthorization.php b/app/Api/Authorization/CategoryAuthorization.php new file mode 100644 index 00000000..f17265a2 --- /dev/null +++ b/app/Api/Authorization/CategoryAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->categoryModel->getProjectId($category_id)); + } + } +} diff --git a/app/Api/Authorization/ColumnAuthorization.php b/app/Api/Authorization/ColumnAuthorization.php new file mode 100644 index 00000000..37aecda2 --- /dev/null +++ b/app/Api/Authorization/ColumnAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->columnModel->getProjectId($column_id)); + } + } +} diff --git a/app/Api/Authorization/CommentAuthorization.php b/app/Api/Authorization/CommentAuthorization.php new file mode 100644 index 00000000..ed15512e --- /dev/null +++ b/app/Api/Authorization/CommentAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->commentModel->getProjectId($comment_id)); + } + } +} diff --git a/app/Api/Authorization/ProcedureAuthorization.php b/app/Api/Authorization/ProcedureAuthorization.php new file mode 100644 index 00000000..070a6371 --- /dev/null +++ b/app/Api/Authorization/ProcedureAuthorization.php @@ -0,0 +1,32 @@ +userSession->isLogged() && in_array($procedure, $this->userSpecificProcedures)) { + throw new AccessDeniedException('This procedure is not available with the API credentials'); + } + } +} diff --git a/app/Api/Authorization/ProjectAuthorization.php b/app/Api/Authorization/ProjectAuthorization.php new file mode 100644 index 00000000..21ecf311 --- /dev/null +++ b/app/Api/Authorization/ProjectAuthorization.php @@ -0,0 +1,35 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $project_id); + } + } + + protected function checkProjectPermission($class, $method, $project_id) + { + if (empty($project_id)) { + throw new AccessDeniedException('Project not found'); + } + + $role = $this->projectUserRoleModel->getUserRole($project_id, $this->userSession->getId()); + + if (! $this->apiProjectAuthorization->isAllowed($class, $method, $role)) { + throw new AccessDeniedException('Project access denied'); + } + } +} diff --git a/app/Api/Authorization/SubtaskAuthorization.php b/app/Api/Authorization/SubtaskAuthorization.php new file mode 100644 index 00000000..fcb57929 --- /dev/null +++ b/app/Api/Authorization/SubtaskAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->subtaskModel->getProjectId($subtask_id)); + } + } +} diff --git a/app/Api/Authorization/TaskAuthorization.php b/app/Api/Authorization/TaskAuthorization.php new file mode 100644 index 00000000..db93b76b --- /dev/null +++ b/app/Api/Authorization/TaskAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->taskFinderModel->getProjectId($category_id)); + } + } +} diff --git a/app/Api/Authorization/TaskFileAuthorization.php b/app/Api/Authorization/TaskFileAuthorization.php new file mode 100644 index 00000000..e40783eb --- /dev/null +++ b/app/Api/Authorization/TaskFileAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->taskFileModel->getProjectId($file_id)); + } + } +} diff --git a/app/Api/Authorization/TaskLinkAuthorization.php b/app/Api/Authorization/TaskLinkAuthorization.php new file mode 100644 index 00000000..2f5fc8d5 --- /dev/null +++ b/app/Api/Authorization/TaskLinkAuthorization.php @@ -0,0 +1,19 @@ +userSession->isLogged()) { + $this->checkProjectPermission($class, $method, $this->taskLinkModel->getProjectId($task_link_id)); + } + } +} diff --git a/app/Api/Authorization/UserAuthorization.php b/app/Api/Authorization/UserAuthorization.php new file mode 100644 index 00000000..3fd6865c --- /dev/null +++ b/app/Api/Authorization/UserAuthorization.php @@ -0,0 +1,22 @@ +userSession->isLogged() && ! $this->apiAuthorization->isAllowed($class, $method, $this->userSession->getRole())) { + throw new AccessDeniedException('You are not allowed to access to this resource'); + } + } +} diff --git a/app/Api/BaseApi.php b/app/Api/BaseApi.php deleted file mode 100644 index 8f18802c..00000000 --- a/app/Api/BaseApi.php +++ /dev/null @@ -1,85 +0,0 @@ -userSession->isLogged() && ! $this->projectPermissionModel->isUserAllowed($project_id, $this->userSession->getId())) { - throw new AccessDeniedException('Permission denied'); - } - } - - public function checkTaskPermission($task_id) - { - if ($this->userSession->isLogged()) { - $this->checkProjectPermission($this->taskFinderModel->getProjectId($task_id)); - } - } - - protected function formatTask($task) - { - if (! empty($task)) { - $task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); - $task['color'] = $this->colorModel->getColorProperties($task['color_id']); - } - - return $task; - } - - protected function formatTasks($tasks) - { - if (! empty($tasks)) { - foreach ($tasks as &$task) { - $task = $this->formatTask($task); - } - } - - return $tasks; - } - - protected function formatProject($project) - { - if (! empty($project)) { - $project['url'] = array( - 'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']), '', true), - 'calendar' => $this->helper->url->to('CalendarController', 'show', array('project_id' => $project['id']), '', true), - 'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $project['id']), '', true), - ); - } - - return $project; - } - - protected function formatProjects($projects) - { - if (! empty($projects)) { - foreach ($projects as &$project) { - $project = $this->formatProject($project); - } - } - - return $projects; - } - - protected function filterValues(array $values) - { - foreach ($values as $key => $value) { - if (is_null($value)) { - unset($values[$key]); - } - } - - return $values; - } -} diff --git a/app/Api/BoardApi.php b/app/Api/BoardApi.php deleted file mode 100644 index 70f21c0e..00000000 --- a/app/Api/BoardApi.php +++ /dev/null @@ -1,24 +0,0 @@ -checkProjectPermission($project_id); - - return BoardFormatter::getInstance($this->container) - ->withProjectId($project_id) - ->withQuery($this->taskFinderModel->getExtendedQuery()) - ->format(); - } -} diff --git a/app/Api/CategoryApi.php b/app/Api/CategoryApi.php deleted file mode 100644 index c56cfb35..00000000 --- a/app/Api/CategoryApi.php +++ /dev/null @@ -1,51 +0,0 @@ -categoryModel->getById($category_id); - } - - public function getAllCategories($project_id) - { - return $this->categoryModel->getAll($project_id); - } - - public function removeCategory($category_id) - { - return $this->categoryModel->remove($category_id); - } - - public function createCategory($project_id, $name) - { - $values = array( - 'project_id' => $project_id, - 'name' => $name, - ); - - list($valid, ) = $this->categoryValidator->validateCreation($values); - return $valid ? $this->categoryModel->create($values) : false; - } - - public function updateCategory($id, $name) - { - $values = array( - 'id' => $id, - 'name' => $name, - ); - - list($valid, ) = $this->categoryValidator->validateModification($values); - return $valid && $this->categoryModel->update($values); - } -} diff --git a/app/Api/ColumnApi.php b/app/Api/ColumnApi.php deleted file mode 100644 index aa4026f6..00000000 --- a/app/Api/ColumnApi.php +++ /dev/null @@ -1,42 +0,0 @@ -columnModel->getAll($project_id); - } - - public function getColumn($column_id) - { - return $this->columnModel->getById($column_id); - } - - public function updateColumn($column_id, $title, $task_limit = 0, $description = '') - { - return $this->columnModel->update($column_id, $title, $task_limit, $description); - } - - public function addColumn($project_id, $title, $task_limit = 0, $description = '') - { - return $this->columnModel->create($project_id, $title, $task_limit, $description); - } - - public function removeColumn($column_id) - { - return $this->columnModel->remove($column_id); - } - - public function changeColumnPosition($project_id, $column_id, $position) - { - return $this->columnModel->changePosition($project_id, $column_id, $position); - } -} diff --git a/app/Api/CommentApi.php b/app/Api/CommentApi.php deleted file mode 100644 index 8358efee..00000000 --- a/app/Api/CommentApi.php +++ /dev/null @@ -1,54 +0,0 @@ -commentModel->getById($comment_id); - } - - public function getAllComments($task_id) - { - return $this->commentModel->getAll($task_id); - } - - public function removeComment($comment_id) - { - return $this->commentModel->remove($comment_id); - } - - public function createComment($task_id, $user_id, $content, $reference = '') - { - $values = array( - 'task_id' => $task_id, - 'user_id' => $user_id, - 'comment' => $content, - 'reference' => $reference, - ); - - list($valid, ) = $this->commentValidator->validateCreation($values); - - return $valid ? $this->commentModel->create($values) : false; - } - - public function updateComment($id, $content) - { - $values = array( - 'id' => $id, - 'comment' => $content, - ); - - list($valid, ) = $this->commentValidator->validateModification($values); - return $valid && $this->commentModel->update($values); - } -} diff --git a/app/Api/GroupApi.php b/app/Api/GroupApi.php deleted file mode 100644 index 1701edc3..00000000 --- a/app/Api/GroupApi.php +++ /dev/null @@ -1,51 +0,0 @@ -groupModel->create($name, $external_id); - } - - public function updateGroup($group_id, $name = null, $external_id = null) - { - $values = array( - 'id' => $group_id, - 'name' => $name, - 'external_id' => $external_id, - ); - - foreach ($values as $key => $value) { - if (is_null($value)) { - unset($values[$key]); - } - } - - return $this->groupModel->update($values); - } - - public function removeGroup($group_id) - { - return $this->groupModel->remove($group_id); - } - - public function getGroup($group_id) - { - return $this->groupModel->getById($group_id); - } - - public function getAllGroups() - { - return $this->groupModel->getAll(); - } -} diff --git a/app/Api/GroupMemberApi.php b/app/Api/GroupMemberApi.php deleted file mode 100644 index e09f6975..00000000 --- a/app/Api/GroupMemberApi.php +++ /dev/null @@ -1,39 +0,0 @@ -groupMemberModel->getGroups($user_id); - } - - public function getGroupMembers($group_id) - { - return $this->groupMemberModel->getMembers($group_id); - } - - public function addGroupMember($group_id, $user_id) - { - return $this->groupMemberModel->addUser($group_id, $user_id); - } - - public function removeGroupMember($group_id, $user_id) - { - return $this->groupMemberModel->removeUser($group_id, $user_id); - } - - public function isGroupMember($group_id, $user_id) - { - return $this->groupMemberModel->isMember($group_id, $user_id); - } -} diff --git a/app/Api/LinkApi.php b/app/Api/LinkApi.php deleted file mode 100644 index d8e525e4..00000000 --- a/app/Api/LinkApi.php +++ /dev/null @@ -1,113 +0,0 @@ -linkModel->getById($link_id); - } - - /** - * Get a link by name - * - * @access public - * @param string $label - * @return array - */ - public function getLinkByLabel($label) - { - return $this->linkModel->getByLabel($label); - } - - /** - * Get the opposite link id - * - * @access public - * @param integer $link_id Link id - * @return integer - */ - public function getOppositeLinkId($link_id) - { - return $this->linkModel->getOppositeLinkId($link_id); - } - - /** - * Get all links - * - * @access public - * @return array - */ - public function getAllLinks() - { - return $this->linkModel->getAll(); - } - - /** - * Create a new link label - * - * @access public - * @param string $label - * @param string $opposite_label - * @return boolean|integer - */ - public function createLink($label, $opposite_label = '') - { - $values = array( - 'label' => $label, - 'opposite_label' => $opposite_label, - ); - - list($valid, ) = $this->linkValidator->validateCreation($values); - return $valid ? $this->linkModel->create($label, $opposite_label) : false; - } - - /** - * Update a link - * - * @access public - * @param integer $link_id - * @param integer $opposite_link_id - * @param string $label - * @return boolean - */ - public function updateLink($link_id, $opposite_link_id, $label) - { - $values = array( - 'id' => $link_id, - 'opposite_id' => $opposite_link_id, - 'label' => $label, - ); - - list($valid, ) = $this->linkValidator->validateModification($values); - return $valid && $this->linkModel->update($values); - } - - /** - * Remove a link a the relation to its opposite - * - * @access public - * @param integer $link_id - * @return boolean - */ - public function removeLink($link_id) - { - return $this->linkModel->remove($link_id); - } -} diff --git a/app/Api/MeApi.php b/app/Api/MeApi.php deleted file mode 100644 index 497749b6..00000000 --- a/app/Api/MeApi.php +++ /dev/null @@ -1,72 +0,0 @@ -sessionStorage->user; - } - - public function getMyDashboard() - { - $user_id = $this->userSession->getId(); - $projects = $this->projectModel->getQueryColumnStats($this->projectPermissionModel->getActiveProjectIds($user_id))->findAll(); - $tasks = $this->taskFinderModel->getUserQuery($user_id)->findAll(); - - return array( - 'projects' => $this->formatProjects($projects), - 'tasks' => $this->formatTasks($tasks), - 'subtasks' => $this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), - ); - } - - public function getMyActivityStream() - { - $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); - return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); - } - - public function createMyPrivateProject($name, $description = null) - { - if ($this->configModel->get('disable_private_project', 0) == 1) { - return false; - } - - $values = array( - 'name' => $name, - 'description' => $description, - 'is_private' => 1, - ); - - list($valid, ) = $this->projectValidator->validateCreation($values); - return $valid ? $this->projectModel->create($values, $this->userSession->getId(), true) : false; - } - - public function getMyProjectsList() - { - return $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); - } - - public function getMyOverdueTasks() - { - return $this->taskFinderModel->getOverdueTasksByUser($this->userSession->getId()); - } - - public function getMyProjects() - { - $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); - $projects = $this->projectModel->getAllByIds($project_ids); - - return $this->formatProjects($projects); - } -} diff --git a/app/Api/Middleware/AuthenticationApiMiddleware.php b/app/Api/Middleware/AuthenticationApiMiddleware.php deleted file mode 100644 index b16e10b8..00000000 --- a/app/Api/Middleware/AuthenticationApiMiddleware.php +++ /dev/null @@ -1,137 +0,0 @@ -dispatcher->dispatch('app.bootstrap'); - - if ($this->isUserAuthenticated($username, $password)) { - $this->checkProcedurePermission(true, $procedureName); - $this->userSession->initialize($this->userModel->getByUsername($username)); - } elseif ($this->isAppAuthenticated($username, $password)) { - $this->checkProcedurePermission(false, $procedureName); - } else { - $this->logger->error('API authentication failure for '.$username); - throw new AuthenticationFailureException('Wrong credentials'); - } - } - - /** - * Check user credentials - * - * @access public - * @param string $username - * @param string $password - * @return boolean - */ - private function isUserAuthenticated($username, $password) - { - return $username !== 'jsonrpc' && - ! $this->userLockingModel->isLocked($username) && - $this->authenticationManager->passwordAuthentication($username, $password); - } - - /** - * Check administrative credentials - * - * @access public - * @param string $username - * @param string $password - * @return boolean - */ - private function isAppAuthenticated($username, $password) - { - return $username === 'jsonrpc' && $password === $this->getApiToken(); - } - - /** - * Get API Token - * - * @access private - * @return string - */ - private function getApiToken() - { - if (defined('API_AUTHENTICATION_TOKEN')) { - return API_AUTHENTICATION_TOKEN; - } - - return $this->configModel->get('api_token'); - } - - public function checkProcedurePermission($is_user, $procedure) - { - $is_both_procedure = in_array($procedure, $this->both_allowed_procedures); - $is_user_procedure = in_array($procedure, $this->user_allowed_procedures); - - if ($is_user && ! $is_both_procedure && ! $is_user_procedure) { - throw new AccessDeniedException('Permission denied'); - } elseif (! $is_user && ! $is_both_procedure && $is_user_procedure) { - throw new AccessDeniedException('Permission denied'); - } - - $this->logger->debug('API call: '.$procedure); - } -} diff --git a/app/Api/Middleware/AuthenticationMiddleware.php b/app/Api/Middleware/AuthenticationMiddleware.php new file mode 100644 index 00000000..8e309593 --- /dev/null +++ b/app/Api/Middleware/AuthenticationMiddleware.php @@ -0,0 +1,82 @@ +dispatcher->dispatch('app.bootstrap'); + + if ($this->isUserAuthenticated($username, $password)) { + $this->userSession->initialize($this->userModel->getByUsername($username)); + } elseif (! $this->isAppAuthenticated($username, $password)) { + $this->logger->error('API authentication failure for '.$username); + throw new AuthenticationFailureException('Wrong credentials'); + } + } + + /** + * Check user credentials + * + * @access public + * @param string $username + * @param string $password + * @return boolean + */ + private function isUserAuthenticated($username, $password) + { + return $username !== 'jsonrpc' && + ! $this->userLockingModel->isLocked($username) && + $this->authenticationManager->passwordAuthentication($username, $password); + } + + /** + * Check administrative credentials + * + * @access public + * @param string $username + * @param string $password + * @return boolean + */ + private function isAppAuthenticated($username, $password) + { + return $username === 'jsonrpc' && $password === $this->getApiToken(); + } + + /** + * Get API Token + * + * @access private + * @return string + */ + private function getApiToken() + { + if (defined('API_AUTHENTICATION_TOKEN')) { + return API_AUTHENTICATION_TOKEN; + } + + return $this->configModel->get('api_token'); + } +} diff --git a/app/Api/Procedure/ActionProcedure.php b/app/Api/Procedure/ActionProcedure.php new file mode 100644 index 00000000..4043dbb9 --- /dev/null +++ b/app/Api/Procedure/ActionProcedure.php @@ -0,0 +1,91 @@ +actionManager->getAvailableActions(); + } + + public function getAvailableActionEvents() + { + return $this->eventManager->getAll(); + } + + public function getCompatibleActionEvents($action_name) + { + return $this->actionManager->getCompatibleEvents($action_name); + } + + public function removeAction($action_id) + { + ActionAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAction', $action_id); + return $this->actionModel->remove($action_id); + } + + public function getActions($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getActions', $project_id); + return $this->actionModel->getAllByProject($project_id); + } + + public function createAction($project_id, $event_name, $action_name, array $params) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createAction', $project_id); + $values = array( + 'project_id' => $project_id, + 'event_name' => $event_name, + 'action_name' => $action_name, + 'params' => $params, + ); + + list($valid, ) = $this->actionValidator->validateCreation($values); + + if (! $valid) { + return false; + } + + // Check if the action exists + $actions = $this->actionManager->getAvailableActions(); + + if (! isset($actions[$action_name])) { + return false; + } + + // Check the event + $action = $this->actionManager->getAction($action_name); + + if (! in_array($event_name, $action->getEvents())) { + return false; + } + + $required_params = $action->getActionRequiredParameters(); + + // Check missing parameters + foreach ($required_params as $param => $value) { + if (! isset($params[$param])) { + return false; + } + } + + // Check extra parameters + foreach ($params as $param => $value) { + if (! isset($required_params[$param])) { + return false; + } + } + + return $this->actionModel->create($values); + } +} diff --git a/app/Api/Procedure/AppProcedure.php b/app/Api/Procedure/AppProcedure.php new file mode 100644 index 00000000..60af4a60 --- /dev/null +++ b/app/Api/Procedure/AppProcedure.php @@ -0,0 +1,47 @@ +timezoneModel->getCurrentTimezone(); + } + + public function getVersion() + { + return APP_VERSION; + } + + public function getDefaultTaskColor() + { + return $this->colorModel->getDefaultColor(); + } + + public function getDefaultTaskColors() + { + return $this->colorModel->getDefaultColors(); + } + + public function getColorList() + { + return $this->colorModel->getList(); + } + + public function getApplicationRoles() + { + return $this->role->getApplicationRoles(); + } + + public function getProjectRoles() + { + return $this->role->getProjectRoles(); + } +} diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php new file mode 100644 index 00000000..0aa43428 --- /dev/null +++ b/app/Api/Procedure/BaseProcedure.php @@ -0,0 +1,86 @@ +container)->check($procedure); + UserAuthorization::getInstance($this->container)->check($this->getClassName(), $procedure); + } + + protected function formatTask($task) + { + if (! empty($task)) { + $task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); + $task['color'] = $this->colorModel->getColorProperties($task['color_id']); + } + + return $task; + } + + protected function formatTasks($tasks) + { + if (! empty($tasks)) { + foreach ($tasks as &$task) { + $task = $this->formatTask($task); + } + } + + return $tasks; + } + + protected function formatProject($project) + { + if (! empty($project)) { + $project['url'] = array( + 'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']), '', true), + 'calendar' => $this->helper->url->to('CalendarController', 'show', array('project_id' => $project['id']), '', true), + 'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $project['id']), '', true), + ); + } + + return $project; + } + + protected function formatProjects($projects) + { + if (! empty($projects)) { + foreach ($projects as &$project) { + $project = $this->formatProject($project); + } + } + + return $projects; + } + + protected function filterValues(array $values) + { + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $values; + } + + protected function getClassName() + { + $reflection = new ReflectionClass(get_called_class()); + return $reflection->getShortName(); + } +} diff --git a/app/Api/Procedure/BoardProcedure.php b/app/Api/Procedure/BoardProcedure.php new file mode 100644 index 00000000..674b5466 --- /dev/null +++ b/app/Api/Procedure/BoardProcedure.php @@ -0,0 +1,25 @@ +container)->check($this->getClassName(), 'getBoard', $project_id); + + return BoardFormatter::getInstance($this->container) + ->withProjectId($project_id) + ->withQuery($this->taskFinderModel->getExtendedQuery()) + ->format(); + } +} diff --git a/app/Api/Procedure/CategoryProcedure.php b/app/Api/Procedure/CategoryProcedure.php new file mode 100644 index 00000000..3ebbd908 --- /dev/null +++ b/app/Api/Procedure/CategoryProcedure.php @@ -0,0 +1,59 @@ +container)->check($this->getClassName(), 'getCategory', $category_id); + return $this->categoryModel->getById($category_id); + } + + public function getAllCategories($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllCategories', $project_id); + return $this->categoryModel->getAll($project_id); + } + + public function removeCategory($category_id) + { + CategoryAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeCategory', $category_id); + return $this->categoryModel->remove($category_id); + } + + public function createCategory($project_id, $name) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createCategory', $project_id); + + $values = array( + 'project_id' => $project_id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateCreation($values); + return $valid ? $this->categoryModel->create($values) : false; + } + + public function updateCategory($id, $name) + { + CategoryAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateCategory', $id); + + $values = array( + 'id' => $id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateModification($values); + return $valid && $this->categoryModel->update($values); + } +} diff --git a/app/Api/Procedure/ColumnProcedure.php b/app/Api/Procedure/ColumnProcedure.php new file mode 100644 index 00000000..ab9d173b --- /dev/null +++ b/app/Api/Procedure/ColumnProcedure.php @@ -0,0 +1,51 @@ +container)->check($this->getClassName(), 'getColumns', $project_id); + return $this->columnModel->getAll($project_id); + } + + public function getColumn($column_id) + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'getColumn', $column_id); + return $this->columnModel->getById($column_id); + } + + public function updateColumn($column_id, $title, $task_limit = 0, $description = '') + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateColumn', $column_id); + return $this->columnModel->update($column_id, $title, $task_limit, $description); + } + + public function addColumn($project_id, $title, $task_limit = 0, $description = '') + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addColumn', $project_id); + return $this->columnModel->create($project_id, $title, $task_limit, $description); + } + + public function removeColumn($column_id) + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeColumn', $column_id); + return $this->columnModel->remove($column_id); + } + + public function changeColumnPosition($project_id, $column_id, $position) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeColumnPosition', $project_id); + return $this->columnModel->changePosition($project_id, $column_id, $position); + } +} diff --git a/app/Api/Procedure/CommentProcedure.php b/app/Api/Procedure/CommentProcedure.php new file mode 100644 index 00000000..019a49bb --- /dev/null +++ b/app/Api/Procedure/CommentProcedure.php @@ -0,0 +1,62 @@ +container)->check($this->getClassName(), 'getComment', $comment_id); + return $this->commentModel->getById($comment_id); + } + + public function getAllComments($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllComments', $task_id); + return $this->commentModel->getAll($task_id); + } + + public function removeComment($comment_id) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeComment', $comment_id); + return $this->commentModel->remove($comment_id); + } + + public function createComment($task_id, $user_id, $content, $reference = '') + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createComment', $task_id); + + $values = array( + 'task_id' => $task_id, + 'user_id' => $user_id, + 'comment' => $content, + 'reference' => $reference, + ); + + list($valid, ) = $this->commentValidator->validateCreation($values); + + return $valid ? $this->commentModel->create($values) : false; + } + + public function updateComment($id, $content) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateComment', $id); + + $values = array( + 'id' => $id, + 'comment' => $content, + ); + + list($valid, ) = $this->commentValidator->validateModification($values); + return $valid && $this->commentModel->update($values); + } +} diff --git a/app/Api/Procedure/GroupMemberProcedure.php b/app/Api/Procedure/GroupMemberProcedure.php new file mode 100644 index 00000000..081d6ac8 --- /dev/null +++ b/app/Api/Procedure/GroupMemberProcedure.php @@ -0,0 +1,37 @@ +groupMemberModel->getGroups($user_id); + } + + public function getGroupMembers($group_id) + { + return $this->groupMemberModel->getMembers($group_id); + } + + public function addGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->addUser($group_id, $user_id); + } + + public function removeGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->removeUser($group_id, $user_id); + } + + public function isGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->isMember($group_id, $user_id); + } +} diff --git a/app/Api/Procedure/GroupProcedure.php b/app/Api/Procedure/GroupProcedure.php new file mode 100644 index 00000000..804940a2 --- /dev/null +++ b/app/Api/Procedure/GroupProcedure.php @@ -0,0 +1,49 @@ +groupModel->create($name, $external_id); + } + + public function updateGroup($group_id, $name = null, $external_id = null) + { + $values = array( + 'id' => $group_id, + 'name' => $name, + 'external_id' => $external_id, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $this->groupModel->update($values); + } + + public function removeGroup($group_id) + { + return $this->groupModel->remove($group_id); + } + + public function getGroup($group_id) + { + return $this->groupModel->getById($group_id); + } + + public function getAllGroups() + { + return $this->groupModel->getAll(); + } +} diff --git a/app/Api/Procedure/LinkProcedure.php b/app/Api/Procedure/LinkProcedure.php new file mode 100644 index 00000000..b4cecf3a --- /dev/null +++ b/app/Api/Procedure/LinkProcedure.php @@ -0,0 +1,111 @@ +linkModel->getById($link_id); + } + + /** + * Get a link by name + * + * @access public + * @param string $label + * @return array + */ + public function getLinkByLabel($label) + { + return $this->linkModel->getByLabel($label); + } + + /** + * Get the opposite link id + * + * @access public + * @param integer $link_id Link id + * @return integer + */ + public function getOppositeLinkId($link_id) + { + return $this->linkModel->getOppositeLinkId($link_id); + } + + /** + * Get all links + * + * @access public + * @return array + */ + public function getAllLinks() + { + return $this->linkModel->getAll(); + } + + /** + * Create a new link label + * + * @access public + * @param string $label + * @param string $opposite_label + * @return boolean|integer + */ + public function createLink($label, $opposite_label = '') + { + $values = array( + 'label' => $label, + 'opposite_label' => $opposite_label, + ); + + list($valid, ) = $this->linkValidator->validateCreation($values); + return $valid ? $this->linkModel->create($label, $opposite_label) : false; + } + + /** + * Update a link + * + * @access public + * @param integer $link_id + * @param integer $opposite_link_id + * @param string $label + * @return boolean + */ + public function updateLink($link_id, $opposite_link_id, $label) + { + $values = array( + 'id' => $link_id, + 'opposite_id' => $opposite_link_id, + 'label' => $label, + ); + + list($valid, ) = $this->linkValidator->validateModification($values); + return $valid && $this->linkModel->update($values); + } + + /** + * Remove a link a the relation to its opposite + * + * @access public + * @param integer $link_id + * @return boolean + */ + public function removeLink($link_id) + { + return $this->linkModel->remove($link_id); + } +} diff --git a/app/Api/Procedure/MeProcedure.php b/app/Api/Procedure/MeProcedure.php new file mode 100644 index 00000000..e59e6522 --- /dev/null +++ b/app/Api/Procedure/MeProcedure.php @@ -0,0 +1,72 @@ +sessionStorage->user; + } + + public function getMyDashboard() + { + $user_id = $this->userSession->getId(); + $projects = $this->projectModel->getQueryColumnStats($this->projectPermissionModel->getActiveProjectIds($user_id))->findAll(); + $tasks = $this->taskFinderModel->getUserQuery($user_id)->findAll(); + + return array( + 'projects' => $this->formatProjects($projects), + 'tasks' => $this->formatTasks($tasks), + 'subtasks' => $this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), + ); + } + + public function getMyActivityStream() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); + } + + public function createMyPrivateProject($name, $description = null) + { + if ($this->configModel->get('disable_private_project', 0) == 1) { + return false; + } + + $values = array( + 'name' => $name, + 'description' => $description, + 'is_private' => 1, + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $this->userSession->getId(), true) : false; + } + + public function getMyProjectsList() + { + return $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); + } + + public function getMyOverdueTasks() + { + return $this->taskFinderModel->getOverdueTasksByUser($this->userSession->getId()); + } + + public function getMyProjects() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + $projects = $this->projectModel->getAllByIds($project_ids); + + return $this->formatProjects($projects); + } +} diff --git a/app/Api/Procedure/ProjectPermissionProcedure.php b/app/Api/Procedure/ProjectPermissionProcedure.php new file mode 100644 index 00000000..e22e1d62 --- /dev/null +++ b/app/Api/Procedure/ProjectPermissionProcedure.php @@ -0,0 +1,69 @@ +container)->check($this->getClassName(), 'getProjectUsers', $project_id); + return $this->projectUserRoleModel->getAllUsers($project_id); + } + + public function getAssignableUsers($project_id, $prepend_unassigned = false) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAssignableUsers', $project_id); + return $this->projectUserRoleModel->getAssignableUsersList($project_id, $prepend_unassigned); + } + + public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addProjectUser', $project_id); + return $this->projectUserRoleModel->addUser($project_id, $user_id, $role); + } + + public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addProjectGroup', $project_id); + return $this->projectGroupRoleModel->addGroup($project_id, $group_id, $role); + } + + public function removeProjectUser($project_id, $user_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProjectUser', $project_id); + return $this->projectUserRoleModel->removeUser($project_id, $user_id); + } + + public function removeProjectGroup($project_id, $group_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProjectGroup', $project_id); + return $this->projectGroupRoleModel->removeGroup($project_id, $group_id); + } + + public function changeProjectUserRole($project_id, $user_id, $role) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeProjectUserRole', $project_id); + return $this->projectUserRoleModel->changeUserRole($project_id, $user_id, $role); + } + + public function changeProjectGroupRole($project_id, $group_id, $role) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeProjectGroupRole', $project_id); + return $this->projectGroupRoleModel->changeGroupRole($project_id, $group_id, $role); + } + + public function getProjectUserRole($project_id, $user_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectUserRole', $project_id); + return $this->projectUserRoleModel->getUserRole($project_id, $user_id); + } +} diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php new file mode 100644 index 00000000..9187f221 --- /dev/null +++ b/app/Api/Procedure/ProjectProcedure.php @@ -0,0 +1,106 @@ +container)->check($this->getClassName(), 'getProjectById', $project_id); + return $this->formatProject($this->projectModel->getById($project_id)); + } + + public function getProjectByName($name) + { + $project = $this->projectModel->getByName($name); + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByName', $project['id']); + return $this->formatProject($project); + } + + public function getAllProjects() + { + return $this->formatProjects($this->projectModel->getAll()); + } + + public function removeProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProject', $project_id); + return $this->projectModel->remove($project_id); + } + + public function enableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProject', $project_id); + return $this->projectModel->enable($project_id); + } + + public function disableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProject', $project_id); + return $this->projectModel->disable($project_id); + } + + public function enableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProjectPublicAccess', $project_id); + return $this->projectModel->enablePublicAccess($project_id); + } + + public function disableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProjectPublicAccess', $project_id); + return $this->projectModel->disablePublicAccess($project_id); + } + + public function getProjectActivities(array $project_ids) + { + foreach ($project_ids as $project_id) { + ProjectAuthorization::getInstance($this->container) + ->check($this->getClassName(), 'getProjectActivities', $project_id); + } + + return $this->helper->projectActivity->getProjectsEvents($project_ids); + } + + public function getProjectActivity($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectActivity', $project_id); + return $this->helper->projectActivity->getProjectEvents($project_id); + } + + public function createProject($name, $description = null, $owner_id = 0, $identifier = null) + { + $values = array( + 'name' => $name, + 'description' => $description, + 'identifier' => $identifier, + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $owner_id, $this->userSession->isLogged()) : false; + } + + public function updateProject($project_id, $name, $description = null, $owner_id = null, $identifier = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateProject', $project_id); + + $values = $this->filterValues(array( + 'id' => $project_id, + 'name' => $name, + 'description' => $description, + 'owner_id' => $owner_id, + 'identifier' => $identifier, + )); + + list($valid, ) = $this->projectValidator->validateModification($values); + return $valid && $this->projectModel->update($values); + } +} diff --git a/app/Api/Procedure/SubtaskProcedure.php b/app/Api/Procedure/SubtaskProcedure.php new file mode 100644 index 00000000..e2400912 --- /dev/null +++ b/app/Api/Procedure/SubtaskProcedure.php @@ -0,0 +1,74 @@ +container)->check($this->getClassName(), 'getSubtask', $subtask_id); + return $this->subtaskModel->getById($subtask_id); + } + + public function getAllSubtasks($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSubtasks', $task_id); + return $this->subtaskModel->getAll($task_id); + } + + public function removeSubtask($subtask_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSubtask', $subtask_id); + return $this->subtaskModel->remove($subtask_id); + } + + public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createSubtask', $task_id); + + $values = array( + 'title' => $title, + 'task_id' => $task_id, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + list($valid, ) = $this->subtaskValidator->validateCreation($values); + return $valid ? $this->subtaskModel->create($values) : false; + } + + public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateSubtask', $task_id); + + $values = array( + 'id' => $id, + 'task_id' => $task_id, + 'title' => $title, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid, ) = $this->subtaskValidator->validateApiModification($values); + return $valid && $this->subtaskModel->update($values); + } +} diff --git a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php new file mode 100644 index 00000000..5d1988d6 --- /dev/null +++ b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php @@ -0,0 +1,39 @@ +container)->check($this->getClassName(), 'hasSubtaskTimer', $subtask_id); + return $this->subtaskTimeTrackingModel->hasTimer($subtask_id, $user_id); + } + + public function logSubtaskStartTime($subtask_id, $user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskStartTime', $subtask_id); + return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); + } + + public function logSubtaskEndTime($subtask_id,$user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskEndTime', $subtask_id); + return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); + } + + public function getSubtaskTimeSpent($subtask_id,$user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSubtaskTimeSpent', $subtask_id); + return $this->subtaskTimeTrackingModel->getTimeSpent($subtask_id, $user_id); + } +} diff --git a/app/Api/Procedure/SwimlaneProcedure.php b/app/Api/Procedure/SwimlaneProcedure.php new file mode 100644 index 00000000..9b7d181d --- /dev/null +++ b/app/Api/Procedure/SwimlaneProcedure.php @@ -0,0 +1,91 @@ +container)->check($this->getClassName(), 'getActiveSwimlanes', $project_id); + return $this->swimlaneModel->getSwimlanes($project_id); + } + + public function getAllSwimlanes($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSwimlanes', $project_id); + return $this->swimlaneModel->getAll($project_id); + } + + public function getSwimlaneById($swimlane_id) + { + $swimlane = $this->swimlaneModel->getById($swimlane_id); + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneById', $swimlane['project_id']); + return $swimlane; + } + + public function getSwimlaneByName($project_id, $name) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneByName', $project_id); + return $this->swimlaneModel->getByName($project_id, $name); + } + + public function getSwimlane($swimlane_id) + { + return $this->swimlaneModel->getById($swimlane_id); + } + + public function getDefaultSwimlane($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getDefaultSwimlane', $project_id); + return $this->swimlaneModel->getDefault($project_id); + } + + public function addSwimlane($project_id, $name, $description = '') + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addSwimlane', $project_id); + return $this->swimlaneModel->create(array('project_id' => $project_id, 'name' => $name, 'description' => $description)); + } + + public function updateSwimlane($swimlane_id, $name, $description = null) + { + $values = array('id' => $swimlane_id, 'name' => $name); + + if (!is_null($description)) { + $values['description'] = $description; + } + + return $this->swimlaneModel->update($values); + } + + public function removeSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSwimlane', $project_id); + return $this->swimlaneModel->remove($project_id, $swimlane_id); + } + + public function disableSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableSwimlane', $project_id); + return $this->swimlaneModel->disable($project_id, $swimlane_id); + } + + public function enableSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableSwimlane', $project_id); + return $this->swimlaneModel->enable($project_id, $swimlane_id); + } + + public function changeSwimlanePosition($project_id, $swimlane_id, $position) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeSwimlanePosition', $project_id); + return $this->swimlaneModel->changePosition($project_id, $swimlane_id, $position); + } +} diff --git a/app/Api/Procedure/TaskFileProcedure.php b/app/Api/Procedure/TaskFileProcedure.php new file mode 100644 index 00000000..5aa7ea0b --- /dev/null +++ b/app/Api/Procedure/TaskFileProcedure.php @@ -0,0 +1,70 @@ +container)->check($this->getClassName(), 'getTaskFile', $file_id); + return $this->taskFileModel->getById($file_id); + } + + public function getAllTaskFiles($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTaskFiles', $task_id); + return $this->taskFileModel->getAll($task_id); + } + + public function downloadTaskFile($file_id) + { + TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'downloadTaskFile', $file_id); + + try { + $file = $this->taskFileModel->getById($file_id); + + if (! empty($file)) { + return base64_encode($this->objectStorage->get($file['path'])); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + + return ''; + } + + public function createTaskFile($project_id, $task_id, $filename, $blob) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTaskFile', $project_id); + + try { + return $this->taskFileModel->uploadContent($task_id, $filename, $blob); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function removeTaskFile($file_id) + { + TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTaskFile', $file_id); + return $this->taskFileModel->remove($file_id); + } + + public function removeAllTaskFiles($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAllTaskFiles', $task_id); + return $this->taskFileModel->removeAll($task_id); + } +} diff --git a/app/Api/Procedure/TaskLinkProcedure.php b/app/Api/Procedure/TaskLinkProcedure.php new file mode 100644 index 00000000..375266fb --- /dev/null +++ b/app/Api/Procedure/TaskLinkProcedure.php @@ -0,0 +1,85 @@ +container)->check($this->getClassName(), 'getTaskLinkById', $task_link_id); + return $this->taskLinkModel->getById($task_link_id); + } + + /** + * Get all links attached to a task + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAllTaskLinks($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTaskLinks', $task_id); + return $this->taskLinkModel->getAll($task_id); + } + + /** + * Create a new link + * + * @access public + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return integer Task link id + */ + public function createTaskLink($task_id, $opposite_task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTaskLink', $task_id); + return $this->taskLinkModel->create($task_id, $opposite_task_id, $link_id); + } + + /** + * Update a task link + * + * @access public + * @param integer $task_link_id Task link id + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return boolean + */ + public function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTaskLink', $task_id); + return $this->taskLinkModel->update($task_link_id, $task_id, $opposite_task_id, $link_id); + } + + /** + * Remove a link between two tasks + * + * @access public + * @param integer $task_link_id + * @return boolean + */ + public function removeTaskLink($task_link_id) + { + TaskLinkAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTaskLink', $task_link_id); + return $this->taskLinkModel->remove($task_link_id); + } +} diff --git a/app/Api/Procedure/TaskProcedure.php b/app/Api/Procedure/TaskProcedure.php new file mode 100644 index 00000000..2d29a4ef --- /dev/null +++ b/app/Api/Procedure/TaskProcedure.php @@ -0,0 +1,167 @@ +container)->check($this->getClassName(), 'searchTasks', $project_id); + return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); + } + + public function getTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id); + return $this->formatTask($this->taskFinderModel->getById($task_id)); + } + + public function getTaskByReference($project_id, $reference) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTaskByReference', $project_id); + return $this->formatTask($this->taskFinderModel->getByReference($project_id, $reference)); + } + + public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTasks', $project_id); + return $this->formatTasks($this->taskFinderModel->getAll($project_id, $status_id)); + } + + public function getOverdueTasks() + { + return $this->taskFinderModel->getOverdueTasks(); + } + + public function getOverdueTasksByProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getOverdueTasksByProject', $project_id); + return $this->taskFinderModel->getOverdueTasksByProject($project_id); + } + + public function openTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'openTask', $task_id); + return $this->taskStatusModel->open($task_id); + } + + public function closeTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'closeTask', $task_id); + return $this->taskStatusModel->close($task_id); + } + + public function removeTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTask', $task_id); + return $this->taskModel->remove($task_id); + } + + public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskPosition', $project_id); + return $this->taskPositionModel->movePosition($project_id, $task_id, $column_id, $position, $swimlane_id); + } + + public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskToProject', $project_id); + return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + } + + public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'duplicateTaskToProject', $project_id); + return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + } + + public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, + $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0, $priority = 0, + $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, + $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; + } + + if ($this->userSession->isLogged()) { + $creator_id = $this->userSession->getId(); + } + + $values = array( + '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, + 'recurrence_timeframe' => $recurrence_timeframe, + 'recurrence_basedate' => $recurrence_basedate, + 'reference' => $reference, + 'priority' => $priority, + ); + + list($valid, ) = $this->taskValidator->validateCreation($values); + + return $valid ? $this->taskCreationModel->create($values) : false; + } + + public function updateTask($id, $title = null, $color_id = null, $owner_id = null, + $date_due = null, $description = null, $category_id = null, $score = null, $priority = null, + $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, + $recurrence_timeframe = null, $recurrence_basedate = null, $reference = null) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $id); + $project_id = $this->taskFinderModel->getProjectId($id); + + if ($project_id === 0) { + return false; + } + + if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { + return false; + } + + $values = $this->filterValues(array( + 'id' => $id, + 'title' => $title, + 'color_id' => $color_id, + 'owner_id' => $owner_id, + 'date_due' => $date_due, + 'description' => $description, + 'category_id' => $category_id, + 'score' => $score, + 'recurrence_status' => $recurrence_status, + 'recurrence_trigger' => $recurrence_trigger, + 'recurrence_factor' => $recurrence_factor, + 'recurrence_timeframe' => $recurrence_timeframe, + 'recurrence_basedate' => $recurrence_basedate, + 'reference' => $reference, + 'priority' => $priority, + )); + + list($valid) = $this->taskValidator->validateApiModification($values); + return $valid && $this->taskModificationModel->update($values); + } +} diff --git a/app/Api/Procedure/UserProcedure.php b/app/Api/Procedure/UserProcedure.php new file mode 100644 index 00000000..145f85bf --- /dev/null +++ b/app/Api/Procedure/UserProcedure.php @@ -0,0 +1,131 @@ +userModel->getById($user_id); + } + + public function getUserByName($username) + { + return $this->userModel->getByUsername($username); + } + + public function getAllUsers() + { + return $this->userModel->getAll(); + } + + public function removeUser($user_id) + { + return $this->userModel->remove($user_id); + } + + public function disableUser($user_id) + { + return $this->userModel->disable($user_id); + } + + public function enableUser($user_id) + { + return $this->userModel->enable($user_id); + } + + public function isActiveUser($user_id) + { + return $this->userModel->isActive($user_id); + } + + public function createUser($username, $password, $name = '', $email = '', $role = Role::APP_USER) + { + $values = array( + 'username' => $username, + 'password' => $password, + 'confirmation' => $password, + 'name' => $name, + 'email' => $email, + 'role' => $role, + ); + + list($valid, ) = $this->userValidator->validateCreation($values); + return $valid ? $this->userModel->create($values) : false; + } + + /** + * Create LDAP user in the database + * + * Only "anonymous" and "proxy" LDAP authentication are supported by this method + * + * User information will be fetched from the LDAP server + * + * @access public + * @param string $username + * @return bool|int + */ + public function createLdapUser($username) + { + if (LDAP_BIND_TYPE === 'user') { + $this->logger->error('LDAP authentication "user" is not supported by this API call'); + return false; + } + + try { + + $ldap = LdapClient::connect(); + $ldap->setLogger($this->logger); + $user = LdapUser::getUser($ldap, $username); + + if ($user === null) { + $this->logger->info('User not found in LDAP server'); + return false; + } + + if ($user->getUsername() === '') { + throw new LogicException('Username not found in LDAP profile, check the parameter LDAP_USER_ATTRIBUTE_USERNAME'); + } + + $values = array( + 'username' => $user->getUsername(), + 'name' => $user->getName(), + 'email' => $user->getEmail(), + 'role' => $user->getRole(), + 'is_ldap_user' => 1, + ); + + return $this->userModel->create($values); + + } catch (LdapException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function updateUser($id, $username = null, $name = null, $email = null, $role = null) + { + $values = $this->filterValues(array( + 'id' => $id, + 'username' => $username, + 'name' => $name, + 'email' => $email, + 'role' => $role, + )); + + list($valid, ) = $this->userValidator->validateApiModification($values); + return $valid && $this->userModel->update($values); + } +} diff --git a/app/Api/ProjectApi.php b/app/Api/ProjectApi.php deleted file mode 100644 index a726d4eb..00000000 --- a/app/Api/ProjectApi.php +++ /dev/null @@ -1,87 +0,0 @@ -checkProjectPermission($project_id); - return $this->formatProject($this->projectModel->getById($project_id)); - } - - public function getProjectByName($name) - { - return $this->formatProject($this->projectModel->getByName($name)); - } - - public function getAllProjects() - { - return $this->formatProjects($this->projectModel->getAll()); - } - - public function removeProject($project_id) - { - return $this->projectModel->remove($project_id); - } - - public function enableProject($project_id) - { - return $this->projectModel->enable($project_id); - } - - public function disableProject($project_id) - { - return $this->projectModel->disable($project_id); - } - - public function enableProjectPublicAccess($project_id) - { - return $this->projectModel->enablePublicAccess($project_id); - } - - public function disableProjectPublicAccess($project_id) - { - return $this->projectModel->disablePublicAccess($project_id); - } - - public function getProjectActivities(array $project_ids) - { - return $this->helper->projectActivity->getProjectsEvents($project_ids); - } - - public function getProjectActivity($project_id) - { - $this->checkProjectPermission($project_id); - return $this->helper->projectActivity->getProjectEvents($project_id); - } - - public function createProject($name, $description = null) - { - $values = array( - 'name' => $name, - 'description' => $description - ); - - list($valid, ) = $this->projectValidator->validateCreation($values); - return $valid ? $this->projectModel->create($values) : false; - } - - public function updateProject($project_id, $name, $description = null) - { - $values = $this->filterValues(array( - 'id' => $project_id, - 'name' => $name, - 'description' => $description - )); - - list($valid, ) = $this->projectValidator->validateModification($values); - return $valid && $this->projectModel->update($values); - } -} diff --git a/app/Api/ProjectPermissionApi.php b/app/Api/ProjectPermissionApi.php deleted file mode 100644 index 37c5e13c..00000000 --- a/app/Api/ProjectPermissionApi.php +++ /dev/null @@ -1,55 +0,0 @@ -projectUserRoleModel->getAllUsers($project_id); - } - - public function getAssignableUsers($project_id, $prepend_unassigned = false) - { - return $this->projectUserRoleModel->getAssignableUsersList($project_id, $prepend_unassigned); - } - - public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) - { - return $this->projectUserRoleModel->addUser($project_id, $user_id, $role); - } - - public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) - { - return $this->projectGroupRoleModel->addGroup($project_id, $group_id, $role); - } - - public function removeProjectUser($project_id, $user_id) - { - return $this->projectUserRoleModel->removeUser($project_id, $user_id); - } - - public function removeProjectGroup($project_id, $group_id) - { - return $this->projectGroupRoleModel->removeGroup($project_id, $group_id); - } - - public function changeProjectUserRole($project_id, $user_id, $role) - { - return $this->projectUserRoleModel->changeUserRole($project_id, $user_id, $role); - } - - public function changeProjectGroupRole($project_id, $group_id, $role) - { - return $this->projectGroupRoleModel->changeGroupRole($project_id, $group_id, $role); - } -} diff --git a/app/Api/SubtaskApi.php b/app/Api/SubtaskApi.php deleted file mode 100644 index 5764ff7d..00000000 --- a/app/Api/SubtaskApi.php +++ /dev/null @@ -1,66 +0,0 @@ -subtaskModel->getById($subtask_id); - } - - public function getAllSubtasks($task_id) - { - return $this->subtaskModel->getAll($task_id); - } - - public function removeSubtask($subtask_id) - { - return $this->subtaskModel->remove($subtask_id); - } - - public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) - { - $values = array( - 'title' => $title, - 'task_id' => $task_id, - 'user_id' => $user_id, - 'time_estimated' => $time_estimated, - 'time_spent' => $time_spent, - 'status' => $status, - ); - - list($valid, ) = $this->subtaskValidator->validateCreation($values); - return $valid ? $this->subtaskModel->create($values) : false; - } - - public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) - { - $values = array( - 'id' => $id, - 'task_id' => $task_id, - 'title' => $title, - 'user_id' => $user_id, - 'time_estimated' => $time_estimated, - 'time_spent' => $time_spent, - 'status' => $status, - ); - - foreach ($values as $key => $value) { - if (is_null($value)) { - unset($values[$key]); - } - } - - list($valid, ) = $this->subtaskValidator->validateApiModification($values); - return $valid && $this->subtaskModel->update($values); - } -} diff --git a/app/Api/SubtaskTimeTrackingApi.php b/app/Api/SubtaskTimeTrackingApi.php deleted file mode 100644 index 0e700b31..00000000 --- a/app/Api/SubtaskTimeTrackingApi.php +++ /dev/null @@ -1,34 +0,0 @@ -subtaskTimeTrackingModel->hasTimer($subtask_id,$user_id); - } - - public function logStartTime($subtask_id,$user_id) - { - return $this->subtaskTimeTrackingModel->logStartTime($subtask_id,$user_id); - } - - public function logEndTime($subtask_id,$user_id) - { - return $this->subtaskTimeTrackingModel->logEndTime($subtask_id,$user_id); - } - - public function getTimeSpent($subtask_id,$user_id) - { - return $this->subtaskTimeTrackingModel->getTimeSpent($subtask_id,$user_id); - } -} diff --git a/app/Api/SwimlaneApi.php b/app/Api/SwimlaneApi.php deleted file mode 100644 index c3c56a71..00000000 --- a/app/Api/SwimlaneApi.php +++ /dev/null @@ -1,80 +0,0 @@ -swimlaneModel->getSwimlanes($project_id); - } - - public function getAllSwimlanes($project_id) - { - return $this->swimlaneModel->getAll($project_id); - } - - public function getSwimlaneById($swimlane_id) - { - return $this->swimlaneModel->getById($swimlane_id); - } - - public function getSwimlaneByName($project_id, $name) - { - return $this->swimlaneModel->getByName($project_id, $name); - } - - public function getSwimlane($swimlane_id) - { - return $this->swimlaneModel->getById($swimlane_id); - } - - public function getDefaultSwimlane($project_id) - { - return $this->swimlaneModel->getDefault($project_id); - } - - public function addSwimlane($project_id, $name, $description = '') - { - return $this->swimlaneModel->create(array('project_id' => $project_id, 'name' => $name, 'description' => $description)); - } - - public function updateSwimlane($swimlane_id, $name, $description = null) - { - $values = array('id' => $swimlane_id, 'name' => $name); - - if (!is_null($description)) { - $values['description'] = $description; - } - - return $this->swimlaneModel->update($values); - } - - public function removeSwimlane($project_id, $swimlane_id) - { - return $this->swimlaneModel->remove($project_id, $swimlane_id); - } - - public function disableSwimlane($project_id, $swimlane_id) - { - return $this->swimlaneModel->disable($project_id, $swimlane_id); - } - - public function enableSwimlane($project_id, $swimlane_id) - { - return $this->swimlaneModel->enable($project_id, $swimlane_id); - } - - public function changeSwimlanePosition($project_id, $swimlane_id, $position) - { - return $this->swimlaneModel->changePosition($project_id, $swimlane_id, $position); - } -} diff --git a/app/Api/TaskApi.php b/app/Api/TaskApi.php deleted file mode 100644 index 523bfaa0..00000000 --- a/app/Api/TaskApi.php +++ /dev/null @@ -1,163 +0,0 @@ -checkProjectPermission($project_id); - return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); - } - - public function getTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->formatTask($this->taskFinderModel->getById($task_id)); - } - - public function getTaskByReference($project_id, $reference) - { - $this->checkProjectPermission($project_id); - return $this->formatTask($this->taskFinderModel->getByReference($project_id, $reference)); - } - - public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) - { - $this->checkProjectPermission($project_id); - return $this->formatTasks($this->taskFinderModel->getAll($project_id, $status_id)); - } - - public function getOverdueTasks() - { - return $this->taskFinderModel->getOverdueTasks(); - } - - public function getOverdueTasksByProject($project_id) - { - $this->checkProjectPermission($project_id); - return $this->taskFinderModel->getOverdueTasksByProject($project_id); - } - - public function openTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->taskStatusModel->open($task_id); - } - - public function closeTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->taskStatusModel->close($task_id); - } - - public function removeTask($task_id) - { - return $this->taskModel->remove($task_id); - } - - public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) - { - $this->checkProjectPermission($project_id); - return $this->taskPositionModel->movePosition($project_id, $task_id, $column_id, $position, $swimlane_id); - } - - public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) - { - return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); - } - - public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) - { - return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); - } - - public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, - $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0, $priority = 0, - $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, - $recurrence_basedate = 0, $reference = '') - { - $this->checkProjectPermission($project_id); - - if ($owner_id !== 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { - return false; - } - - if ($this->userSession->isLogged()) { - $creator_id = $this->userSession->getId(); - } - - $values = array( - '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, - 'recurrence_timeframe' => $recurrence_timeframe, - 'recurrence_basedate' => $recurrence_basedate, - 'reference' => $reference, - 'priority' => $priority, - ); - - list($valid, ) = $this->taskValidator->validateCreation($values); - - return $valid ? $this->taskCreationModel->create($values) : false; - } - - public function updateTask($id, $title = null, $color_id = null, $owner_id = null, - $date_due = null, $description = null, $category_id = null, $score = null, $priority = null, - $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, - $recurrence_timeframe = null, $recurrence_basedate = null, $reference = null) - { - $this->checkTaskPermission($id); - - $project_id = $this->taskFinderModel->getProjectId($id); - - if ($project_id === 0) { - return false; - } - - if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { - return false; - } - - $values = $this->filterValues(array( - 'id' => $id, - 'title' => $title, - 'color_id' => $color_id, - 'owner_id' => $owner_id, - 'date_due' => $date_due, - 'description' => $description, - 'category_id' => $category_id, - 'score' => $score, - 'recurrence_status' => $recurrence_status, - 'recurrence_trigger' => $recurrence_trigger, - 'recurrence_factor' => $recurrence_factor, - 'recurrence_timeframe' => $recurrence_timeframe, - 'recurrence_basedate' => $recurrence_basedate, - 'reference' => $reference, - 'priority' => $priority, - )); - - list($valid) = $this->taskValidator->validateApiModification($values); - return $valid && $this->taskModificationModel->update($values); - } -} diff --git a/app/Api/TaskFileApi.php b/app/Api/TaskFileApi.php deleted file mode 100644 index 7b27477c..00000000 --- a/app/Api/TaskFileApi.php +++ /dev/null @@ -1,59 +0,0 @@ -taskFileModel->getById($file_id); - } - - public function getAllTaskFiles($task_id) - { - return $this->taskFileModel->getAll($task_id); - } - - public function downloadTaskFile($file_id) - { - try { - $file = $this->taskFileModel->getById($file_id); - - if (! empty($file)) { - return base64_encode($this->objectStorage->get($file['path'])); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - - return ''; - } - - public function createTaskFile($project_id, $task_id, $filename, $blob) - { - try { - return $this->taskFileModel->uploadContent($task_id, $filename, $blob); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - public function removeTaskFile($file_id) - { - return $this->taskFileModel->remove($file_id); - } - - public function removeAllTaskFiles($task_id) - { - return $this->taskFileModel->removeAll($task_id); - } -} diff --git a/app/Api/TaskLinkApi.php b/app/Api/TaskLinkApi.php deleted file mode 100644 index bb809133..00000000 --- a/app/Api/TaskLinkApi.php +++ /dev/null @@ -1,79 +0,0 @@ -taskLinkModel->getById($task_link_id); - } - - /** - * Get all links attached to a task - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getAllTaskLinks($task_id) - { - return $this->taskLinkModel->getAll($task_id); - } - - /** - * Create a new link - * - * @access public - * @param integer $task_id Task id - * @param integer $opposite_task_id Opposite task id - * @param integer $link_id Link id - * @return integer Task link id - */ - public function createTaskLink($task_id, $opposite_task_id, $link_id) - { - return $this->taskLinkModel->create($task_id, $opposite_task_id, $link_id); - } - - /** - * Update a task link - * - * @access public - * @param integer $task_link_id Task link id - * @param integer $task_id Task id - * @param integer $opposite_task_id Opposite task id - * @param integer $link_id Link id - * @return boolean - */ - public function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id) - { - return $this->taskLinkModel->update($task_link_id, $task_id, $opposite_task_id, $link_id); - } - - /** - * Remove a link between two tasks - * - * @access public - * @param integer $task_link_id - * @return boolean - */ - public function removeTaskLink($task_link_id) - { - return $this->taskLinkModel->remove($task_link_id); - } -} diff --git a/app/Api/UserApi.php b/app/Api/UserApi.php deleted file mode 100644 index 6cb9df1c..00000000 --- a/app/Api/UserApi.php +++ /dev/null @@ -1,131 +0,0 @@ -userModel->getById($user_id); - } - - public function getUserByName($username) - { - return $this->userModel->getByUsername($username); - } - - public function getAllUsers() - { - return $this->userModel->getAll(); - } - - public function removeUser($user_id) - { - return $this->userModel->remove($user_id); - } - - public function disableUser($user_id) - { - return $this->userModel->disable($user_id); - } - - public function enableUser($user_id) - { - return $this->userModel->enable($user_id); - } - - public function isActiveUser($user_id) - { - return $this->userModel->isActive($user_id); - } - - public function createUser($username, $password, $name = '', $email = '', $role = Role::APP_USER) - { - $values = array( - 'username' => $username, - 'password' => $password, - 'confirmation' => $password, - 'name' => $name, - 'email' => $email, - 'role' => $role, - ); - - list($valid, ) = $this->userValidator->validateCreation($values); - return $valid ? $this->userModel->create($values) : false; - } - - /** - * Create LDAP user in the database - * - * Only "anonymous" and "proxy" LDAP authentication are supported by this method - * - * User information will be fetched from the LDAP server - * - * @access public - * @param string $username - * @return bool|int - */ - public function createLdapUser($username) - { - if (LDAP_BIND_TYPE === 'user') { - $this->logger->error('LDAP authentication "user" is not supported by this API call'); - return false; - } - - try { - - $ldap = LdapClient::connect(); - $ldap->setLogger($this->logger); - $user = LdapUser::getUser($ldap, $username); - - if ($user === null) { - $this->logger->info('User not found in LDAP server'); - return false; - } - - if ($user->getUsername() === '') { - throw new LogicException('Username not found in LDAP profile, check the parameter LDAP_USER_ATTRIBUTE_USERNAME'); - } - - $values = array( - 'username' => $user->getUsername(), - 'name' => $user->getName(), - 'email' => $user->getEmail(), - 'role' => $user->getRole(), - 'is_ldap_user' => 1, - ); - - return $this->userModel->create($values); - - } catch (LdapException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - public function updateUser($id, $username = null, $name = null, $email = null, $role = null) - { - $values = $this->filterValues(array( - 'id' => $id, - 'username' => $username, - 'name' => $name, - 'email' => $email, - 'role' => $role, - )); - - list($valid, ) = $this->userValidator->validateApiModification($values); - return $valid && $this->userModel->update($values); - } -} diff --git a/app/Core/Base.php b/app/Core/Base.php index e5dd6ad9..eacca65d 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -35,8 +35,12 @@ use Pimple\Container; * @property \Kanboard\Core\Security\AuthenticationManager $authenticationManager * @property \Kanboard\Core\Security\AccessMap $applicationAccessMap * @property \Kanboard\Core\Security\AccessMap $projectAccessMap + * @property \Kanboard\Core\Security\AccessMap $apiAccessMap + * @property \Kanboard\Core\Security\AccessMap $apiProjectAccessMap * @property \Kanboard\Core\Security\Authorization $applicationAuthorization * @property \Kanboard\Core\Security\Authorization $projectAuthorization + * @property \Kanboard\Core\Security\Authorization $apiAuthorization + * @property \Kanboard\Core\Security\Authorization $apiProjectAuthorization * @property \Kanboard\Core\Security\Role $role * @property \Kanboard\Core\Security\Token $token * @property \Kanboard\Core\Session\FlashMessage $flash diff --git a/app/Model/ActionModel.php b/app/Model/ActionModel.php index 53393ed5..b5d2bd06 100644 --- a/app/Model/ActionModel.php +++ b/app/Model/ActionModel.php @@ -85,6 +85,18 @@ class ActionModel extends Base return $action; } + /** + * Get the projectId by the actionId + * + * @access public + * @param integer $action_id + * @return integer + */ + public function getProjectId($action_id) + { + return $this->db->table(self::TABLE)->eq('id', $action_id)->findOneColumn('project_id') ?: 0; + } + /** * Attach parameters to actions * diff --git a/app/Model/CategoryModel.php b/app/Model/CategoryModel.php index 62fb5611..024d0026 100644 --- a/app/Model/CategoryModel.php +++ b/app/Model/CategoryModel.php @@ -55,6 +55,18 @@ class CategoryModel extends Base return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('name') ?: ''; } + /** + * Get the projectId by the category id + * + * @access public + * @param integer $category_id Category id + * @return integer + */ + public function getProjectId($category_id) + { + return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('project_id') ?: 0; + } + /** * Get a category id by the category name and project id * diff --git a/app/Model/ColumnModel.php b/app/Model/ColumnModel.php index 1adac0f2..795fe692 100644 --- a/app/Model/ColumnModel.php +++ b/app/Model/ColumnModel.php @@ -31,6 +31,18 @@ class ColumnModel extends Base return $this->db->table(self::TABLE)->eq('id', $column_id)->findOne(); } + /** + * Get projectId by the columnId + * + * @access public + * @param integer $column_id Column id + * @return integer + */ + public function getProjectId($column_id) + { + return $this->db->table(self::TABLE)->eq('id', $column_id)->findOneColumn('project_id'); + } + /** * Get the first column id for a given project * diff --git a/app/Model/CommentModel.php b/app/Model/CommentModel.php index 36e1fc48..4231f29d 100644 --- a/app/Model/CommentModel.php +++ b/app/Model/CommentModel.php @@ -29,6 +29,22 @@ class CommentModel extends Base const EVENT_CREATE = 'comment.create'; const EVENT_USER_MENTION = 'comment.user.mention'; + /** + * Get projectId from commentId + * + * @access public + * @param integer $comment_id + * @return integer + */ + public function getProjectId($comment_id) + { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.id', $comment_id) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0; + } + /** * Get all comments for a given task * diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php index 019064ad..a97bddbf 100644 --- a/app/Model/SubtaskModel.php +++ b/app/Model/SubtaskModel.php @@ -51,6 +51,22 @@ class SubtaskModel extends Base const EVENT_CREATE = 'subtask.create'; const EVENT_DELETE = 'subtask.delete'; + /** + * Get projectId from subtaskId + * + * @access public + * @param integer $subtask_id + * @return integer + */ + public function getProjectId($subtask_id) + { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.id', $subtask_id) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0; + } + /** * Get available status * diff --git a/app/Model/TaskFileModel.php b/app/Model/TaskFileModel.php index 24c1ad4b..7603019a 100644 --- a/app/Model/TaskFileModel.php +++ b/app/Model/TaskFileModel.php @@ -72,6 +72,22 @@ class TaskFileModel extends FileModel return self::EVENT_CREATE; } + /** + * Get projectId from fileId + * + * @access public + * @param integer $file_id + * @return integer + */ + public function getProjectId($file_id) + { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.id', $file_id) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0; + } + /** * Handle screenshot upload * diff --git a/app/Model/TaskLinkModel.php b/app/Model/TaskLinkModel.php index 45225e35..09978eae 100644 --- a/app/Model/TaskLinkModel.php +++ b/app/Model/TaskLinkModel.php @@ -28,6 +28,22 @@ class TaskLinkModel extends Base */ const EVENT_CREATE_UPDATE = 'tasklink.create_update'; + /** + * Get projectId from $task_link_id + * + * @access public + * @param integer $task_link_id + * @return integer + */ + public function getProjectId($task_link_id) + { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.id', $task_link_id) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0; + } + /** * Get a task link * diff --git a/app/ServiceProvider/ApiProvider.php b/app/ServiceProvider/ApiProvider.php index e0312056..f88d9b4f 100644 --- a/app/ServiceProvider/ApiProvider.php +++ b/app/ServiceProvider/ApiProvider.php @@ -3,26 +3,26 @@ namespace Kanboard\ServiceProvider; use JsonRPC\Server; -use Kanboard\Api\ActionApi; -use Kanboard\Api\AppApi; -use Kanboard\Api\BoardApi; -use Kanboard\Api\CategoryApi; -use Kanboard\Api\ColumnApi; -use Kanboard\Api\CommentApi; -use Kanboard\Api\TaskFileApi; -use Kanboard\Api\GroupApi; -use Kanboard\Api\GroupMemberApi; -use Kanboard\Api\LinkApi; -use Kanboard\Api\MeApi; -use Kanboard\Api\Middleware\AuthenticationApiMiddleware; -use Kanboard\Api\ProjectApi; -use Kanboard\Api\ProjectPermissionApi; -use Kanboard\Api\SubtaskApi; -use Kanboard\Api\SubtaskTimeTrackingApi; -use Kanboard\Api\SwimlaneApi; -use Kanboard\Api\TaskApi; -use Kanboard\Api\TaskLinkApi; -use Kanboard\Api\UserApi; +use Kanboard\Api\Procedure\ActionProcedure; +use Kanboard\Api\Procedure\AppProcedure; +use Kanboard\Api\Procedure\BoardProcedure; +use Kanboard\Api\Procedure\CategoryProcedure; +use Kanboard\Api\Procedure\ColumnProcedure; +use Kanboard\Api\Procedure\CommentProcedure; +use Kanboard\Api\Procedure\TaskFileProcedure; +use Kanboard\Api\Procedure\GroupProcedure; +use Kanboard\Api\Procedure\GroupMemberProcedure; +use Kanboard\Api\Procedure\LinkProcedure; +use Kanboard\Api\Procedure\MeProcedure; +use Kanboard\Api\Middleware\AuthenticationMiddleware; +use Kanboard\Api\Procedure\ProjectProcedure; +use Kanboard\Api\Procedure\ProjectPermissionProcedure; +use Kanboard\Api\Procedure\SubtaskProcedure; +use Kanboard\Api\Procedure\SubtaskTimeTrackingProcedure; +use Kanboard\Api\Procedure\SwimlaneProcedure; +use Kanboard\Api\Procedure\TaskProcedure; +use Kanboard\Api\Procedure\TaskLinkProcedure; +use Kanboard\Api\Procedure\UserProcedure; use Pimple\Container; use Pimple\ServiceProviderInterface; @@ -45,31 +45,32 @@ class ApiProvider implements ServiceProviderInterface $server = new Server(); $server->setAuthenticationHeader(API_AUTHENTICATION_HEADER); $server->getMiddlewareHandler() - ->withMiddleware(new AuthenticationApiMiddleware($container)) + ->withMiddleware(new AuthenticationMiddleware($container)) ; $server->getProcedureHandler() - ->withObject(new MeApi($container)) - ->withObject(new ActionApi($container)) - ->withObject(new AppApi($container)) - ->withObject(new BoardApi($container)) - ->withObject(new ColumnApi($container)) - ->withObject(new CategoryApi($container)) - ->withObject(new CommentApi($container)) - ->withObject(new TaskFileApi($container)) - ->withObject(new LinkApi($container)) - ->withObject(new ProjectApi($container)) - ->withObject(new ProjectPermissionApi($container)) - ->withObject(new SubtaskApi($container)) - ->withObject(new SubtaskTimeTrackingApi($container)) - ->withObject(new SwimlaneApi($container)) - ->withObject(new TaskApi($container)) - ->withObject(new TaskLinkApi($container)) - ->withObject(new UserApi($container)) - ->withObject(new GroupApi($container)) - ->withObject(new GroupMemberApi($container)) + ->withObject(new MeProcedure($container)) + ->withObject(new ActionProcedure($container)) + ->withObject(new AppProcedure($container)) + ->withObject(new BoardProcedure($container)) + ->withObject(new ColumnProcedure($container)) + ->withObject(new CategoryProcedure($container)) + ->withObject(new CommentProcedure($container)) + ->withObject(new TaskFileProcedure($container)) + ->withObject(new LinkProcedure($container)) + ->withObject(new ProjectProcedure($container)) + ->withObject(new ProjectPermissionProcedure($container)) + ->withObject(new SubtaskProcedure($container)) + ->withObject(new SubtaskTimeTrackingProcedure($container)) + ->withObject(new SwimlaneProcedure($container)) + ->withObject(new TaskProcedure($container)) + ->withObject(new TaskLinkProcedure($container)) + ->withObject(new UserProcedure($container)) + ->withObject(new GroupProcedure($container)) + ->withObject(new GroupMemberProcedure($container)) + ->withBeforeMethod('beforeProcedure') ; - + $container['api'] = $server; return $container; } diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index 84e4354d..751fe514 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -46,9 +46,13 @@ class AuthenticationProvider implements ServiceProviderInterface $container['projectAccessMap'] = $this->getProjectAccessMap(); $container['applicationAccessMap'] = $this->getApplicationAccessMap(); + $container['apiAccessMap'] = $this->getApiAccessMap(); + $container['apiProjectAccessMap'] = $this->getApiProjectAccessMap(); $container['projectAuthorization'] = new Authorization($container['projectAccessMap']); $container['applicationAuthorization'] = new Authorization($container['applicationAccessMap']); + $container['apiAuthorization'] = new Authorization($container['apiAccessMap']); + $container['apiProjectAuthorization'] = new Authorization($container['apiProjectAccessMap']); return $container; } @@ -151,4 +155,57 @@ class AuthenticationProvider implements ServiceProviderInterface return $acl; } + + /** + * Get ACL for the API + * + * @access public + * @return AccessMap + */ + public function getApiAccessMap() + { + $acl = new AccessMap; + $acl->setDefaultRole(Role::APP_USER); + $acl->setRoleHierarchy(Role::APP_ADMIN, array(Role::APP_MANAGER, Role::APP_USER, Role::APP_PUBLIC)); + $acl->setRoleHierarchy(Role::APP_MANAGER, array(Role::APP_USER, Role::APP_PUBLIC)); + + $acl->add('UserProcedure', '*', Role::APP_ADMIN); + $acl->add('GroupMemberProcedure', '*', Role::APP_ADMIN); + $acl->add('GroupProcedure', '*', Role::APP_ADMIN); + $acl->add('LinkProcedure', '*', Role::APP_ADMIN); + $acl->add('TaskProcedure', array('getOverdueTasks'), Role::APP_ADMIN); + $acl->add('ProjectProcedure', array('getAllProjects'), Role::APP_ADMIN); + $acl->add('ProjectProcedure', array('createProject'), Role::APP_MANAGER); + + return $acl; + } + + /** + * Get ACL for the API + * + * @access public + * @return AccessMap + */ + public function getApiProjectAccessMap() + { + $acl = new AccessMap; + $acl->setDefaultRole(Role::PROJECT_VIEWER); + $acl->setRoleHierarchy(Role::PROJECT_MANAGER, array(Role::PROJECT_MEMBER, Role::PROJECT_VIEWER)); + $acl->setRoleHierarchy(Role::PROJECT_MEMBER, array(Role::PROJECT_VIEWER)); + + $acl->add('ActionProcedure', array('removeAction', 'getActions', 'createAction'), Role::PROJECT_MANAGER); + $acl->add('CategoryProcedure', '*', Role::PROJECT_MANAGER); + $acl->add('ColumnProcedure', '*', Role::PROJECT_MANAGER); + $acl->add('CommentProcedure', array('removeComment', 'createComment', 'updateComment'), Role::PROJECT_MEMBER); + $acl->add('ProjectPermissionProcedure', '*', Role::PROJECT_MANAGER); + $acl->add('ProjectProcedure', array('updateProject', 'removeProject', 'enableProject', 'disableProject', 'enableProjectPublicAccess', 'disableProjectPublicAccess'), Role::PROJECT_MANAGER); + $acl->add('SubtaskProcedure', '*', Role::PROJECT_MEMBER); + $acl->add('SubtaskTimeTrackingProcedure', '*', Role::PROJECT_MEMBER); + $acl->add('SwimlaneProcedure', '*', Role::PROJECT_MANAGER); + $acl->add('TaskFileProcedure', '*', Role::PROJECT_MEMBER); + $acl->add('TaskLinkProcedure', '*', Role::PROJECT_MEMBER); + $acl->add('TaskProcedure', '*', Role::PROJECT_MEMBER); + + return $acl; + } } diff --git a/composer.json b/composer.json index 85fdb5ad..bcac020e 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "christian-riesen/otp" : "1.4", "eluceo/ical": "0.8.0", "erusev/parsedown" : "1.6.0", - "fguillot/json-rpc" : "1.2.0", + "fguillot/json-rpc" : "1.2.1", "fguillot/picodb" : "1.0.12", "fguillot/simpleLogger" : "1.0.1", "fguillot/simple-validator" : "1.0.0", diff --git a/composer.lock b/composer.lock index e0177ed5..e6a72582 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2de2026649db7bc41653bef80f974c6a", - "content-hash": "ea8ef74f1f1cf53b9f96b7609d756873", + "hash": "283af0b856598f5bc3d8ee0b226959e5", + "content-hash": "18c0bbff5406ceb8b567d9655de26746", "packages": [ { "name": "christian-riesen/base32", @@ -203,16 +203,16 @@ }, { "name": "fguillot/json-rpc", - "version": "v1.2.0", + "version": "v1.2.1", "source": { "type": "git", "url": "https://github.com/fguillot/JsonRPC.git", - "reference": "b002320b10aa1eeb7aee83f7b703cd6a6e99ff78" + "reference": "d491bb549bfa11aff4c37abcea2ffb28c9523f69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/b002320b10aa1eeb7aee83f7b703cd6a6e99ff78", - "reference": "b002320b10aa1eeb7aee83f7b703cd6a6e99ff78", + "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/d491bb549bfa11aff4c37abcea2ffb28c9523f69", + "reference": "d491bb549bfa11aff4c37abcea2ffb28c9523f69", "shasum": "" }, "require": { @@ -238,7 +238,7 @@ ], "description": "Simple Json-RPC client/server library that just works", "homepage": "https://github.com/fguillot/JsonRPC", - "time": "2016-05-29 13:06:36" + "time": "2016-06-25 23:11:10" }, { "name": "fguillot/picodb", @@ -682,16 +682,16 @@ }, { "name": "symfony/console", - "version": "v2.8.6", + "version": "v2.8.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "48221d3de4dc22d2cd57c97e8b9361821da86609" + "reference": "5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/48221d3de4dc22d2cd57c97e8b9361821da86609", - "reference": "48221d3de4dc22d2cd57c97e8b9361821da86609", + "url": "https://api.github.com/repos/symfony/console/zipball/5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3", + "reference": "5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3", "shasum": "" }, "require": { @@ -738,20 +738,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-04-26 12:00:47" + "time": "2016-06-06 15:06:25" }, { "name": "symfony/event-dispatcher", - "version": "v2.8.6", + "version": "v2.8.7", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "a158f13992a3147d466af7a23b564ac719a4ddd8" + "reference": "2a6b8713f8bdb582058cfda463527f195b066110" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a158f13992a3147d466af7a23b564ac719a4ddd8", - "reference": "a158f13992a3147d466af7a23b564ac719a4ddd8", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2a6b8713f8bdb582058cfda463527f195b066110", + "reference": "2a6b8713f8bdb582058cfda463527f195b066110", "shasum": "" }, "require": { @@ -798,7 +798,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-05-03 18:59:18" + "time": "2016-06-06 11:11:27" }, { "name": "symfony/polyfill-mbstring", @@ -915,39 +915,136 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, { "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-06-10 09:48:41" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ + "psr-4": { + "phpDocumentor\\Reflection\\": [ "src/" ] } @@ -959,39 +1056,39 @@ "authors": [ { "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "email": "me@mikevanriel.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2016-06-10 07:14:17" }, { "name": "phpspec/prophecy", - "version": "v1.6.0", + "version": "v1.6.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972" + "reference": "58a8137754bc24b25740d4281399a4a3596058e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", + "reference": "58a8137754bc24b25740d4281399a4a3596058e0", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1", - "sebastian/recursion-context": "~1.0" + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "phpspec/phpspec": "^2.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -1024,7 +1121,7 @@ "spy", "stub" ], - "time": "2016-02-15 07:46:21" + "time": "2016-06-07 08:13:47" }, { "name": "phpunit/php-code-coverage", @@ -1629,16 +1726,16 @@ }, { "name": "sebastian/exporter", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", "shasum": "" }, "require": { @@ -1646,12 +1743,13 @@ "sebastian/recursion-context": "~1.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -1691,7 +1789,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2016-06-17 09:04:28" }, { "name": "sebastian/global-state", @@ -1834,16 +1932,16 @@ }, { "name": "symfony/stopwatch", - "version": "v2.8.6", + "version": "v2.8.7", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "9e24824b2a9a16e17ab997f61d70bc03948e434e" + "reference": "5e628055488bcc42dbace3af65be435d094e37e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/9e24824b2a9a16e17ab997f61d70bc03948e434e", - "reference": "9e24824b2a9a16e17ab997f61d70bc03948e434e", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5e628055488bcc42dbace3af65be435d094e37e4", + "reference": "5e628055488bcc42dbace3af65be435d094e37e4", "shasum": "" }, "require": { @@ -1879,7 +1977,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:54:35" + "time": "2016-06-06 11:11:27" }, { "name": "symfony/yaml", @@ -1927,6 +2025,55 @@ "description": "Symfony Yaml Component", "homepage": "http://symfony.com", "time": "2012-08-22 13:48:41" + }, + { + "name": "webmozart/assert", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", + "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2015-08-24 13:29:44" } ], "aliases": [], diff --git a/doc/api-authentication.markdown b/doc/api-authentication.markdown index 962e5b1b..3ba1e8f5 100644 --- a/doc/api-authentication.markdown +++ b/doc/api-authentication.markdown @@ -1,48 +1,26 @@ API Authentication ================== -Default method (HTTP Basic) ---------------------------- +API endpoint +------------ + +URL: `https://YOUR_SERVER/jsonrpc.php` -The API credentials are available on the settings page. -- API end-point: `https://YOUR_SERVER/jsonrpc.php` +Default method (HTTP Basic) +--------------------------- -If you want to use the "application api": +### Application credentials - Username: `jsonrpc` - Password: API token on the settings page -Otherwise for the "user api", just use the real username/passsword. +### User credentials + +- Use the real username and password The API use the [HTTP Basic Authentication Scheme described in the RFC2617](http://www.ietf.org/rfc/rfc2617.txt). -If there is an authentication error, you will receive the HTTP status code `401 Not Authorized`. - -### Authorized User API procedures - -- getMe -- getMyDashboard -- getMyActivityStream -- createMyPrivateProject -- getMyProjectsList -- getMyProjects -- getTimezone -- getVersion -- getDefaultTaskColor -- getDefaultTaskColors -- getColorList -- getProjectById -- getTask -- getTaskByReference -- getAllTasks -- openTask -- closeTask -- moveTaskPosition -- createTask -- updateTask -- getBoard -- getProjectActivity -- getMyOverdueTasks + Custom HTTP header ------------------ @@ -64,3 +42,14 @@ curl \ -d '{"jsonrpc": "2.0", "method": "getAllProjects", "id": 1}' \ http://localhost/kanboard/jsonrpc.php ``` + +Authentication error +-------------------- + +If the credentials are wrong, you will receive a `401 Not Authorized` and the corresponding JSON response. + + +Authorization error +------------------- + +If the connected user is not allowed to access to the resource, you will receive a `403 Forbidden`. diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown index bb14b008..0f922a7c 100644 --- a/doc/api-json-rpc.markdown +++ b/doc/api-json-rpc.markdown @@ -8,25 +8,25 @@ There are two types of API access: ### Application API -- Access to the API with the user "jsonrpc" and the token available in settings +- Access to the API with the user "jsonrpc" and the token available on the settings page - Access to all procedures - No permission checked - There is no user session on the server +- No access to procedures that starts with "My..." (example: "getMe" or "getMyProjects") - Example of possible clients: tools to migrate/import data, create tasks from another system, etc... ### User API - Access to the API with the user credentials (username and password) -- Access to a restricted set of procedures -- The project permissions are checked +- Application role and project permissions are checked for each procedure - A user session is created on the server -- Example of possible clients: mobile/desktop application, command line utility, etc... +- Example of possible clients: native mobile/desktop application, command line utility, etc... Security -------- -- Always use HTTPS with a valid certificate -- If you make a mobile application, it's your job to store securely the user credentials on the device +- Always use HTTPS with a valid certificate (avoid clear text communication) +- If you make a mobile application, it's your responsability to store securely the user credentials on the device - After 3 authentication failure on the user api, the end-user have to unlock his account by using the login form - Two factor authentication is not yet available through the API diff --git a/doc/api-project-permission-procedures.markdown b/doc/api-project-permission-procedures.markdown index 2844ae3c..d5e9b066 100644 --- a/doc/api-project-permission-procedures.markdown +++ b/doc/api-project-permission-procedures.markdown @@ -272,3 +272,36 @@ Response example: "result": true } ``` + +## getProjectUserRole + +- Purpose: **Get the role of a user for a given project** +- Parameters: + - **project_id** (integer, required) + - **user_id** (integer, required) +- Result on success: **role name** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getProjectUserRole", + "id": 2114673298, + "params": [ + "2", + "3" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 2114673298, + "result": "project-viewer" +} +``` diff --git a/doc/api-project-procedures.markdown b/doc/api-project-procedures.markdown index f8e2cc5e..3f8d33c2 100644 --- a/doc/api-project-procedures.markdown +++ b/doc/api-project-procedures.markdown @@ -7,6 +7,8 @@ API Project Procedures - Parameters: - **name** (string, required) - **description** (string, optional) + - **owner_id** (integer, optional) + - **identifier** (string, optional) - Result on success: **project_id** - Result on failure: **false** @@ -186,6 +188,8 @@ Response example: - **project_id** (integer, required) - **name** (string, required) - **description** (string, optional) + - **owner_id** (integer, optional) + - **identifier** (string, optional) - Result on success: **true** - Result on failure: **false** diff --git a/tests/integration/ActionProcedureTest.php b/tests/integration/ActionProcedureTest.php new file mode 100644 index 00000000..432de3d3 --- /dev/null +++ b/tests/integration/ActionProcedureTest.php @@ -0,0 +1,66 @@ +app->getAvailableActions(); + $this->assertNotEmpty($actions); + $this->assertInternalType('array', $actions); + $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions); + } + + public function testGetAvailableActionEvents() + { + $events = $this->app->getAvailableActionEvents(); + $this->assertNotEmpty($events); + $this->assertInternalType('array', $events); + $this->assertArrayHasKey('task.move.column', $events); + } + + public function testGetCompatibleActionEvents() + { + $events = $this->app->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn'); + $this->assertNotEmpty($events); + $this->assertInternalType('array', $events); + $this->assertArrayHasKey('task.move.column', $events); + } + + public function testCRUD() + { + $this->assertCreateTeamProject(); + $this->assertCreateAction(); + $this->assertGetActions(); + $this->assertRemoveAction(); + } + + public function assertCreateAction() + { + $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertNotFalse($actionId); + $this->assertTrue($actionId > 0); + } + + public function assertGetActions() + { + $actions = $this->app->getActions($this->projectId); + $this->assertNotEmpty($actions); + $this->assertInternalType('array', $actions); + $this->assertArrayHasKey('id', $actions[0]); + $this->assertArrayHasKey('project_id', $actions[0]); + $this->assertArrayHasKey('event_name', $actions[0]); + $this->assertArrayHasKey('action_name', $actions[0]); + $this->assertArrayHasKey('params', $actions[0]); + $this->assertArrayHasKey('column_id', $actions[0]['params']); + } + + public function assertRemoveAction() + { + $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertTrue($this->app->removeAction($actionId)); + } +} diff --git a/tests/integration/ActionTest.php b/tests/integration/ActionTest.php deleted file mode 100644 index 7a5adc4a..00000000 --- a/tests/integration/ActionTest.php +++ /dev/null @@ -1,66 +0,0 @@ -app->getAvailableActions(); - $this->assertNotEmpty($actions); - $this->assertInternalType('array', $actions); - $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions); - } - - public function testGetAvailableActionEvents() - { - $events = $this->app->getAvailableActionEvents(); - $this->assertNotEmpty($events); - $this->assertInternalType('array', $events); - $this->assertArrayHasKey('task.move.column', $events); - } - - public function testGetCompatibleActionEvents() - { - $events = $this->app->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn'); - $this->assertNotEmpty($events); - $this->assertInternalType('array', $events); - $this->assertArrayHasKey('task.move.column', $events); - } - - public function testCRUD() - { - $this->assertCreateTeamProject(); - $this->assertCreateAction(); - $this->assertGetActions(); - $this->assertRemoveAction(); - } - - public function assertCreateAction() - { - $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); - $this->assertNotFalse($actionId); - $this->assertTrue($actionId > 0); - } - - public function assertGetActions() - { - $actions = $this->app->getActions($this->projectId); - $this->assertNotEmpty($actions); - $this->assertInternalType('array', $actions); - $this->assertArrayHasKey('id', $actions[0]); - $this->assertArrayHasKey('project_id', $actions[0]); - $this->assertArrayHasKey('event_name', $actions[0]); - $this->assertArrayHasKey('action_name', $actions[0]); - $this->assertArrayHasKey('params', $actions[0]); - $this->assertArrayHasKey('column_id', $actions[0]['params']); - } - - public function assertRemoveAction() - { - $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); - $this->assertTrue($this->app->removeAction($actionId)); - } -} diff --git a/tests/integration/AppProcedureTest.php b/tests/integration/AppProcedureTest.php new file mode 100644 index 00000000..06135dac --- /dev/null +++ b/tests/integration/AppProcedureTest.php @@ -0,0 +1,54 @@ +assertEquals('UTC', $this->app->getTimezone()); + } + + public function testGetVersion() + { + $this->assertEquals('master', $this->app->getVersion()); + } + + public function testGetApplicationRoles() + { + $roles = $this->app->getApplicationRoles(); + $this->assertCount(3, $roles); + $this->assertEquals('Administrator', $roles['app-admin']); + $this->assertEquals('Manager', $roles['app-manager']); + $this->assertEquals('User', $roles['app-user']); + } + + public function testGetProjectRoles() + { + $roles = $this->app->getProjectRoles(); + $this->assertCount(3, $roles); + $this->assertEquals('Project Manager', $roles['project-manager']); + $this->assertEquals('Project Member', $roles['project-member']); + $this->assertEquals('Project Viewer', $roles['project-viewer']); + } + + public function testGetDefaultColor() + { + $this->assertEquals('yellow', $this->user->getDefaultTaskColor()); + } + + public function testGetDefaultColors() + { + $colors = $this->user->getDefaultTaskColors(); + $this->assertNotEmpty($colors); + $this->assertArrayHasKey('red', $colors); + } + + public function testGetColorList() + { + $colors = $this->user->getColorList(); + $this->assertNotEmpty($colors); + $this->assertArrayHasKey('red', $colors); + $this->assertEquals('Red', $colors['red']); + } +} diff --git a/tests/integration/AppTest.php b/tests/integration/AppTest.php deleted file mode 100644 index 287e6299..00000000 --- a/tests/integration/AppTest.php +++ /dev/null @@ -1,54 +0,0 @@ -assertEquals('UTC', $this->app->getTimezone()); - } - - public function testGetVersion() - { - $this->assertEquals('master', $this->app->getVersion()); - } - - public function testGetApplicationRoles() - { - $roles = $this->app->getApplicationRoles(); - $this->assertCount(3, $roles); - $this->assertEquals('Administrator', $roles['app-admin']); - $this->assertEquals('Manager', $roles['app-manager']); - $this->assertEquals('User', $roles['app-user']); - } - - public function testGetProjectRoles() - { - $roles = $this->app->getProjectRoles(); - $this->assertCount(3, $roles); - $this->assertEquals('Project Manager', $roles['project-manager']); - $this->assertEquals('Project Member', $roles['project-member']); - $this->assertEquals('Project Viewer', $roles['project-viewer']); - } - - public function testGetDefaultColor() - { - $this->assertEquals('yellow', $this->user->getDefaultTaskColor()); - } - - public function testGetDefaultColors() - { - $colors = $this->user->getDefaultTaskColors(); - $this->assertNotEmpty($colors); - $this->assertArrayHasKey('red', $colors); - } - - public function testGetColorList() - { - $colors = $this->user->getColorList(); - $this->assertNotEmpty($colors); - $this->assertArrayHasKey('red', $colors); - $this->assertEquals('Red', $colors['red']); - } -} diff --git a/tests/integration/BaseIntegrationTest.php b/tests/integration/BaseIntegrationTest.php deleted file mode 100644 index cd837173..00000000 --- a/tests/integration/BaseIntegrationTest.php +++ /dev/null @@ -1,122 +0,0 @@ -setUpAppClient(); - $this->setUpAdminUser(); - $this->setUpManagerUser(); - $this->setUpStandardUser(); - } - - public function setUpAppClient() - { - $this->app = new JsonRPC\Client(API_URL); - $this->app->authentication('jsonrpc', API_KEY); - $this->app->getHttpClient()->withDebug()->withTimeout(10); - } - - public function setUpAdminUser() - { - $this->adminUserId = $this->getUserId('superuser'); - - if (! $this->adminUserId) { - $this->adminUserId = $this->app->createUser('superuser', 'password', 'Admin User', 'user@localhost', 'app-admin'); - $this->assertNotFalse($this->adminUserId); - } - - $this->admin = new JsonRPC\Client(API_URL); - $this->admin->authentication('superuser', 'password'); - $this->admin->getHttpClient()->withDebug(); - } - - public function setUpManagerUser() - { - $this->managerUserId = $this->getUserId('manager'); - - if (! $this->managerUserId) { - $this->managerUserId = $this->app->createUser('manager', 'password', 'Manager User', 'user@localhost', 'app-manager'); - $this->assertNotFalse($this->managerUserId); - } - - $this->manager = new JsonRPC\Client(API_URL); - $this->manager->authentication('manager', 'password'); - $this->manager->getHttpClient()->withDebug(); - } - - public function setUpStandardUser() - { - $this->userUserId = $this->getUserId('user'); - - if (! $this->userUserId) { - $this->userUserId = $this->app->createUser('user', 'password', 'Standard User', 'user@localhost', 'app-user'); - $this->assertNotFalse($this->userUserId); - } - - $this->user = new JsonRPC\Client(API_URL); - $this->user->authentication('user', 'password'); - $this->user->getHttpClient()->withDebug(); - } - - public function getUserId($username) - { - $user = $this->app->getUserByName($username); - - if (! empty($user)) { - return $user['id']; - } - - return 0; - } - - public function assertCreateTeamProject() - { - $this->projectId = $this->app->createProject($this->projectName, 'Description'); - $this->assertNotFalse($this->projectId); - } - - public function assertCreateUser() - { - $this->userId = $this->app->createUser($this->username, 'password'); - $this->assertNotFalse($this->userId); - } - - public function assertCreateGroups() - { - $this->groupId1 = $this->app->createGroup($this->groupName1); - $this->groupId2 = $this->app->createGroup($this->groupName2, 'External ID'); - $this->assertNotFalse($this->groupId1); - $this->assertNotFalse($this->groupId2); - } - - public function assertCreateTask() - { - $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId)); - $this->assertNotFalse($this->taskId); - } -} diff --git a/tests/integration/BaseProcedureTest.php b/tests/integration/BaseProcedureTest.php new file mode 100644 index 00000000..e3382e82 --- /dev/null +++ b/tests/integration/BaseProcedureTest.php @@ -0,0 +1,122 @@ +setUpAppClient(); + $this->setUpAdminUser(); + $this->setUpManagerUser(); + $this->setUpStandardUser(); + } + + public function setUpAppClient() + { + $this->app = new JsonRPC\Client(API_URL); + $this->app->authentication('jsonrpc', API_KEY); + $this->app->getHttpClient()->withDebug()->withTimeout(10); + } + + public function setUpAdminUser() + { + $this->adminUserId = $this->getUserId('superuser'); + + if (! $this->adminUserId) { + $this->adminUserId = $this->app->createUser('superuser', 'password', 'Admin User', 'user@localhost', 'app-admin'); + $this->assertNotFalse($this->adminUserId); + } + + $this->admin = new JsonRPC\Client(API_URL); + $this->admin->authentication('superuser', 'password'); + $this->admin->getHttpClient()->withDebug(); + } + + public function setUpManagerUser() + { + $this->managerUserId = $this->getUserId('manager'); + + if (! $this->managerUserId) { + $this->managerUserId = $this->app->createUser('manager', 'password', 'Manager User', 'user@localhost', 'app-manager'); + $this->assertNotFalse($this->managerUserId); + } + + $this->manager = new JsonRPC\Client(API_URL); + $this->manager->authentication('manager', 'password'); + $this->manager->getHttpClient()->withDebug(); + } + + public function setUpStandardUser() + { + $this->userUserId = $this->getUserId('user'); + + if (! $this->userUserId) { + $this->userUserId = $this->app->createUser('user', 'password', 'Standard User', 'user@localhost', 'app-user'); + $this->assertNotFalse($this->userUserId); + } + + $this->user = new JsonRPC\Client(API_URL); + $this->user->authentication('user', 'password'); + $this->user->getHttpClient()->withDebug(); + } + + public function getUserId($username) + { + $user = $this->app->getUserByName($username); + + if (! empty($user)) { + return $user['id']; + } + + return 0; + } + + public function assertCreateTeamProject() + { + $this->projectId = $this->app->createProject($this->projectName, 'Description'); + $this->assertNotFalse($this->projectId); + } + + public function assertCreateUser() + { + $this->userId = $this->app->createUser($this->username, 'password'); + $this->assertNotFalse($this->userId); + } + + public function assertCreateGroups() + { + $this->groupId1 = $this->app->createGroup($this->groupName1); + $this->groupId2 = $this->app->createGroup($this->groupName2, 'External ID'); + $this->assertNotFalse($this->groupId1); + $this->assertNotFalse($this->groupId2); + } + + public function assertCreateTask() + { + $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId)); + $this->assertNotFalse($this->taskId); + } +} diff --git a/tests/integration/BoardProcedureTest.php b/tests/integration/BoardProcedureTest.php new file mode 100644 index 00000000..273e93c7 --- /dev/null +++ b/tests/integration/BoardProcedureTest.php @@ -0,0 +1,25 @@ +assertCreateTeamProject(); + $this->assertGetBoard(); + } + + public function assertGetBoard() + { + $board = $this->app->getBoard($this->projectId); + $this->assertNotNull($board); + $this->assertCount(1, $board); + $this->assertEquals('Default swimlane', $board[0]['name']); + + $this->assertCount(4, $board[0]['columns']); + $this->assertEquals('Ready', $board[0]['columns'][1]['title']); + } +} diff --git a/tests/integration/BoardTest.php b/tests/integration/BoardTest.php deleted file mode 100644 index aa0f61ff..00000000 --- a/tests/integration/BoardTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertCreateTeamProject(); - $this->assertGetBoard(); - } - - public function assertGetBoard() - { - $board = $this->app->getBoard($this->projectId); - $this->assertNotNull($board); - $this->assertCount(1, $board); - $this->assertEquals('Default swimlane', $board[0]['name']); - - $this->assertCount(4, $board[0]['columns']); - $this->assertEquals('Ready', $board[0]['columns'][1]['title']); - } -} diff --git a/tests/integration/CategoryProcedureTest.php b/tests/integration/CategoryProcedureTest.php new file mode 100644 index 00000000..2f5294ba --- /dev/null +++ b/tests/integration/CategoryProcedureTest.php @@ -0,0 +1,76 @@ +assertCreateTeamProject(); + $this->assertCreateCategory(); + $this->assertThatCategoriesAreUnique(); + $this->assertGetCategory(); + $this->assertGetAllCategories(); + $this->assertCategoryUpdate(); + $this->assertRemoveCategory(); + } + + public function assertCreateCategory() + { + $this->categoryId = $this->app->createCategory(array( + 'name' => 'Category', + 'project_id' => $this->projectId, + )); + + $this->assertNotFalse($this->categoryId); + } + + public function assertThatCategoriesAreUnique() + { + $this->assertFalse($this->app->execute('createCategory', array( + 'name' => 'Category', + 'project_id' => $this->projectId, + ))); + } + + public function assertGetCategory() + { + $category = $this->app->getCategory($this->categoryId); + + $this->assertInternalType('array', $category); + $this->assertEquals($this->categoryId, $category['id']); + $this->assertEquals('Category', $category['name']); + $this->assertEquals($this->projectId, $category['project_id']); + } + + public function assertGetAllCategories() + { + $categories = $this->app->getAllCategories($this->projectId); + + $this->assertCount(1, $categories); + $this->assertEquals($this->categoryId, $categories[0]['id']); + $this->assertEquals('Category', $categories[0]['name']); + $this->assertEquals($this->projectId, $categories[0]['project_id']); + } + + public function assertCategoryUpdate() + { + $this->assertTrue($this->app->execute('updateCategory', array( + 'id' => $this->categoryId, + 'name' => 'Renamed category', + ))); + + $category = $this->app->getCategory($this->categoryId); + $this->assertEquals('Renamed category', $category['name']); + } + + public function assertRemoveCategory() + { + $this->assertTrue($this->app->removeCategory($this->categoryId)); + $this->assertFalse($this->app->removeCategory($this->categoryId)); + $this->assertFalse($this->app->removeCategory(1111)); + } +} diff --git a/tests/integration/CategoryTest.php b/tests/integration/CategoryTest.php deleted file mode 100644 index c1aec0bc..00000000 --- a/tests/integration/CategoryTest.php +++ /dev/null @@ -1,76 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateCategory(); - $this->assertThatCategoriesAreUnique(); - $this->assertGetCategory(); - $this->assertGetAllCategories(); - $this->assertCategoryUpdate(); - $this->assertRemoveCategory(); - } - - public function assertCreateCategory() - { - $this->categoryId = $this->app->createCategory(array( - 'name' => 'Category', - 'project_id' => $this->projectId, - )); - - $this->assertNotFalse($this->categoryId); - } - - public function assertThatCategoriesAreUnique() - { - $this->assertFalse($this->app->execute('createCategory', array( - 'name' => 'Category', - 'project_id' => $this->projectId, - ))); - } - - public function assertGetCategory() - { - $category = $this->app->getCategory($this->categoryId); - - $this->assertInternalType('array', $category); - $this->assertEquals($this->categoryId, $category['id']); - $this->assertEquals('Category', $category['name']); - $this->assertEquals($this->projectId, $category['project_id']); - } - - public function assertGetAllCategories() - { - $categories = $this->app->getAllCategories($this->projectId); - - $this->assertCount(1, $categories); - $this->assertEquals($this->categoryId, $categories[0]['id']); - $this->assertEquals('Category', $categories[0]['name']); - $this->assertEquals($this->projectId, $categories[0]['project_id']); - } - - public function assertCategoryUpdate() - { - $this->assertTrue($this->app->execute('updateCategory', array( - 'id' => $this->categoryId, - 'name' => 'Renamed category', - ))); - - $category = $this->app->getCategory($this->categoryId); - $this->assertEquals('Renamed category', $category['name']); - } - - public function assertRemoveCategory() - { - $this->assertTrue($this->app->removeCategory($this->categoryId)); - $this->assertFalse($this->app->removeCategory($this->categoryId)); - $this->assertFalse($this->app->removeCategory(1111)); - } -} diff --git a/tests/integration/ColumnProcedureTest.php b/tests/integration/ColumnProcedureTest.php new file mode 100644 index 00000000..fb6a27c3 --- /dev/null +++ b/tests/integration/ColumnProcedureTest.php @@ -0,0 +1,69 @@ +assertCreateTeamProject(); + $this->assertGetColumns(); + $this->assertUpdateColumn(); + $this->assertAddColumn(); + $this->assertRemoveColumn(); + $this->assertChangeColumnPosition(); + } + + public function assertGetColumns() + { + $this->columns = $this->app->getColumns($this->projectId); + $this->assertCount(4, $this->columns); + $this->assertEquals('Done', $this->columns[3]['title']); + } + + public function assertUpdateColumn() + { + $this->assertTrue($this->app->updateColumn($this->columns[3]['id'], 'Another column', 2)); + + $this->columns = $this->app->getColumns($this->projectId); + $this->assertEquals('Another column', $this->columns[3]['title']); + $this->assertEquals(2, $this->columns[3]['task_limit']); + } + + public function assertAddColumn() + { + $column_id = $this->app->addColumn($this->projectId, 'New column'); + $this->assertNotFalse($column_id); + $this->assertTrue($column_id > 0); + + $this->columns = $this->app->getColumns($this->projectId); + $this->assertCount(5, $this->columns); + $this->assertEquals('New column', $this->columns[4]['title']); + } + + public function assertRemoveColumn() + { + $this->assertTrue($this->app->removeColumn($this->columns[3]['id'])); + + $this->columns = $this->app->getColumns($this->projectId); + $this->assertCount(4, $this->columns); + } + + public function assertChangeColumnPosition() + { + $this->assertTrue($this->app->changeColumnPosition($this->projectId, $this->columns[0]['id'], 3)); + + $this->columns = $this->app->getColumns($this->projectId); + $this->assertEquals('Ready', $this->columns[0]['title']); + $this->assertEquals(1, $this->columns[0]['position']); + $this->assertEquals('Work in progress', $this->columns[1]['title']); + $this->assertEquals(2, $this->columns[1]['position']); + $this->assertEquals('Backlog', $this->columns[2]['title']); + $this->assertEquals(3, $this->columns[2]['position']); + $this->assertEquals('New column', $this->columns[3]['title']); + $this->assertEquals(4, $this->columns[3]['position']); + } +} diff --git a/tests/integration/ColumnTest.php b/tests/integration/ColumnTest.php deleted file mode 100644 index 5a81badc..00000000 --- a/tests/integration/ColumnTest.php +++ /dev/null @@ -1,69 +0,0 @@ -assertCreateTeamProject(); - $this->assertGetColumns(); - $this->assertUpdateColumn(); - $this->assertAddColumn(); - $this->assertRemoveColumn(); - $this->assertChangeColumnPosition(); - } - - public function assertGetColumns() - { - $this->columns = $this->app->getColumns($this->projectId); - $this->assertCount(4, $this->columns); - $this->assertEquals('Done', $this->columns[3]['title']); - } - - public function assertUpdateColumn() - { - $this->assertTrue($this->app->updateColumn($this->columns[3]['id'], 'Another column', 2)); - - $this->columns = $this->app->getColumns($this->projectId); - $this->assertEquals('Another column', $this->columns[3]['title']); - $this->assertEquals(2, $this->columns[3]['task_limit']); - } - - public function assertAddColumn() - { - $column_id = $this->app->addColumn($this->projectId, 'New column'); - $this->assertNotFalse($column_id); - $this->assertTrue($column_id > 0); - - $this->columns = $this->app->getColumns($this->projectId); - $this->assertCount(5, $this->columns); - $this->assertEquals('New column', $this->columns[4]['title']); - } - - public function assertRemoveColumn() - { - $this->assertTrue($this->app->removeColumn($this->columns[3]['id'])); - - $this->columns = $this->app->getColumns($this->projectId); - $this->assertCount(4, $this->columns); - } - - public function assertChangeColumnPosition() - { - $this->assertTrue($this->app->changeColumnPosition($this->projectId, $this->columns[0]['id'], 3)); - - $this->columns = $this->app->getColumns($this->projectId); - $this->assertEquals('Ready', $this->columns[0]['title']); - $this->assertEquals(1, $this->columns[0]['position']); - $this->assertEquals('Work in progress', $this->columns[1]['title']); - $this->assertEquals(2, $this->columns[1]['position']); - $this->assertEquals('Backlog', $this->columns[2]['title']); - $this->assertEquals(3, $this->columns[2]['position']); - $this->assertEquals('New column', $this->columns[3]['title']); - $this->assertEquals(4, $this->columns[3]['position']); - } -} diff --git a/tests/integration/CommentProcedureTest.php b/tests/integration/CommentProcedureTest.php new file mode 100644 index 00000000..881d938c --- /dev/null +++ b/tests/integration/CommentProcedureTest.php @@ -0,0 +1,63 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertCreateComment(); + $this->assertUpdateComment(); + $this->assertGetAllComments(); + $this->assertRemoveComment(); + } + + public function assertCreateComment() + { + $this->commentId = $this->app->execute('createComment', array( + 'task_id' => $this->taskId, + 'user_id' => 1, + 'content' => 'foobar', + )); + + $this->assertNotFalse($this->commentId); + } + + public function assertGetComment() + { + $comment = $this->app->getComment($this->commentId); + $this->assertNotFalse($comment); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['user_id']); + $this->assertEquals('foobar', $comment['comment']); + } + + public function assertUpdateComment() + { + $this->assertTrue($this->app->execute('updateComment', array( + 'id' => $this->commentId, + 'content' => 'test', + ))); + + $comment = $this->app->getComment($this->commentId); + $this->assertEquals('test', $comment['comment']); + } + + public function assertGetAllComments() + { + $comments = $this->app->getAllComments($this->taskId); + $this->assertCount(1, $comments); + $this->assertEquals('test', $comments[0]['comment']); + } + + public function assertRemoveComment() + { + $this->assertTrue($this->app->removeComment($this->commentId)); + $this->assertFalse($this->app->removeComment($this->commentId)); + } +} diff --git a/tests/integration/CommentTest.php b/tests/integration/CommentTest.php deleted file mode 100644 index 34376838..00000000 --- a/tests/integration/CommentTest.php +++ /dev/null @@ -1,63 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateTask(); - $this->assertCreateComment(); - $this->assertUpdateComment(); - $this->assertGetAllComments(); - $this->assertRemoveComment(); - } - - public function assertCreateComment() - { - $this->commentId = $this->app->execute('createComment', array( - 'task_id' => $this->taskId, - 'user_id' => 1, - 'content' => 'foobar', - )); - - $this->assertNotFalse($this->commentId); - } - - public function assertGetComment() - { - $comment = $this->app->getComment($this->commentId); - $this->assertNotFalse($comment); - $this->assertNotEmpty($comment); - $this->assertEquals(1, $comment['user_id']); - $this->assertEquals('foobar', $comment['comment']); - } - - public function assertUpdateComment() - { - $this->assertTrue($this->app->execute('updateComment', array( - 'id' => $this->commentId, - 'content' => 'test', - ))); - - $comment = $this->app->getComment($this->commentId); - $this->assertEquals('test', $comment['comment']); - } - - public function assertGetAllComments() - { - $comments = $this->app->getAllComments($this->taskId); - $this->assertCount(1, $comments); - $this->assertEquals('test', $comments[0]['comment']); - } - - public function assertRemoveComment() - { - $this->assertTrue($this->app->removeComment($this->commentId)); - $this->assertFalse($this->app->removeComment($this->commentId)); - } -} diff --git a/tests/integration/GroupMemberProcedureTest.php b/tests/integration/GroupMemberProcedureTest.php new file mode 100644 index 00000000..fe243533 --- /dev/null +++ b/tests/integration/GroupMemberProcedureTest.php @@ -0,0 +1,53 @@ +assertCreateGroups(); + $this->assertCreateUser(); + $this->assertAddMember(); + $this->assertGetMembers(); + $this->assertIsGroupMember(); + $this->assertGetGroups(); + $this->assertRemove(); + } + + public function assertAddMember() + { + $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId)); + } + + public function assertGetMembers() + { + $members = $this->app->getGroupMembers($this->groupId1); + $this->assertCount(1, $members); + $this->assertEquals($this->username, $members[0]['username']); + } + + public function assertIsGroupMember() + { + $this->assertTrue($this->app->isGroupMember($this->groupId1, $this->userId)); + $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->adminUserId)); + } + + public function assertGetGroups() + { + $groups = $this->app->getMemberGroups($this->userId); + $this->assertCount(1, $groups); + $this->assertEquals($this->groupId1, $groups[0]['id']); + $this->assertEquals($this->groupName1, $groups[0]['name']); + } + + public function assertRemove() + { + $this->assertTrue($this->app->removeGroupMember($this->groupId1, $this->userId)); + $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->userId)); + } +} diff --git a/tests/integration/GroupMemberTest.php b/tests/integration/GroupMemberTest.php deleted file mode 100644 index f79499a4..00000000 --- a/tests/integration/GroupMemberTest.php +++ /dev/null @@ -1,53 +0,0 @@ -assertCreateGroups(); - $this->assertCreateUser(); - $this->assertAddMember(); - $this->assertGetMembers(); - $this->assertIsGroupMember(); - $this->assertGetGroups(); - $this->assertRemove(); - } - - public function assertAddMember() - { - $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId)); - } - - public function assertGetMembers() - { - $members = $this->app->getGroupMembers($this->groupId1); - $this->assertCount(1, $members); - $this->assertEquals($this->username, $members[0]['username']); - } - - public function assertIsGroupMember() - { - $this->assertTrue($this->app->isGroupMember($this->groupId1, $this->userId)); - $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->adminUserId)); - } - - public function assertGetGroups() - { - $groups = $this->app->getMemberGroups($this->userId); - $this->assertCount(1, $groups); - $this->assertEquals($this->groupId1, $groups[0]['id']); - $this->assertEquals($this->groupName1, $groups[0]['name']); - } - - public function assertRemove() - { - $this->assertTrue($this->app->removeGroupMember($this->groupId1, $this->userId)); - $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->userId)); - } -} diff --git a/tests/integration/GroupProcedureTest.php b/tests/integration/GroupProcedureTest.php new file mode 100644 index 00000000..610c121d --- /dev/null +++ b/tests/integration/GroupProcedureTest.php @@ -0,0 +1,50 @@ +assertCreateGroups(); + $this->assertGetAllGroups(); + $this->assertGetGroup(); + $this->assertUpdateGroup(); + $this->assertRemove(); + } + + public function assertGetAllGroups() + { + $groups = $this->app->getAllGroups(); + $this->assertNotEmpty($groups); + $this->assertArrayHasKey('name', $groups[0]); + $this->assertArrayHasKey('external_id', $groups[0]); + } + + public function assertGetGroup() + { + $group = $this->app->getGroup($this->groupId1); + $this->assertNotEmpty($group); + $this->assertEquals($this->groupName1, $group['name']); + $this->assertEquals('', $group['external_id']); + } + + public function assertUpdateGroup() + { + $this->assertTrue($this->app->updateGroup(array( + 'group_id' => $this->groupId2, + 'name' => 'My Group C', + 'external_id' => 'something else', + ))); + + $group = $this->app->getGroup($this->groupId2); + $this->assertNotEmpty($group); + $this->assertEquals('My Group C', $group['name']); + $this->assertEquals('something else', $group['external_id']); + } + + public function assertRemove() + { + $this->assertTrue($this->app->removeGroup($this->groupId1)); + } +} diff --git a/tests/integration/GroupTest.php b/tests/integration/GroupTest.php deleted file mode 100644 index ffcd7a71..00000000 --- a/tests/integration/GroupTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertCreateGroups(); - $this->assertGetAllGroups(); - $this->assertGetGroup(); - $this->assertUpdateGroup(); - $this->assertRemove(); - } - - public function assertGetAllGroups() - { - $groups = $this->app->getAllGroups(); - $this->assertNotEmpty($groups); - $this->assertArrayHasKey('name', $groups[0]); - $this->assertArrayHasKey('external_id', $groups[0]); - } - - public function assertGetGroup() - { - $group = $this->app->getGroup($this->groupId1); - $this->assertNotEmpty($group); - $this->assertEquals($this->groupName1, $group['name']); - $this->assertEquals('', $group['external_id']); - } - - public function assertUpdateGroup() - { - $this->assertTrue($this->app->updateGroup(array( - 'group_id' => $this->groupId2, - 'name' => 'My Group C', - 'external_id' => 'something else', - ))); - - $group = $this->app->getGroup($this->groupId2); - $this->assertNotEmpty($group); - $this->assertEquals('My Group C', $group['name']); - $this->assertEquals('something else', $group['external_id']); - } - - public function assertRemove() - { - $this->assertTrue($this->app->removeGroup($this->groupId1)); - } -} diff --git a/tests/integration/LinkProcedureTest.php b/tests/integration/LinkProcedureTest.php new file mode 100644 index 00000000..fb07e694 --- /dev/null +++ b/tests/integration/LinkProcedureTest.php @@ -0,0 +1,70 @@ +app->getAllLinks(); + $this->assertNotEmpty($links); + $this->assertArrayHasKey('id', $links[0]); + $this->assertArrayHasKey('label', $links[0]); + $this->assertArrayHasKey('opposite_id', $links[0]); + } + + public function testGetOppositeLink() + { + $link = $this->app->getOppositeLinkId(1); + $this->assertEquals(1, $link); + + $link = $this->app->getOppositeLinkId(2); + $this->assertEquals(3, $link); + } + + public function testGetLinkByLabel() + { + $link = $this->app->getLinkByLabel('blocks'); + $this->assertNotEmpty($link); + $this->assertEquals(2, $link['id']); + $this->assertEquals(3, $link['opposite_id']); + } + + public function testGetLinkById() + { + $link = $this->app->getLinkById(4); + $this->assertNotEmpty($link); + $this->assertEquals(4, $link['id']); + $this->assertEquals(5, $link['opposite_id']); + $this->assertEquals('duplicates', $link['label']); + } + + public function testCreateLink() + { + $link_id = $this->app->createLink(array('label' => 'test')); + $this->assertNotFalse($link_id); + $this->assertInternalType('int', $link_id); + + $link_id = $this->app->createLink(array('label' => 'foo', 'opposite_label' => 'bar')); + $this->assertNotFalse($link_id); + $this->assertInternalType('int', $link_id); + } + + public function testUpdateLink() + { + $link1 = $this->app->getLinkByLabel('bar'); + $this->assertNotEmpty($link1); + + $link2 = $this->app->getLinkByLabel('test'); + $this->assertNotEmpty($link2); + + $this->assertNotFalse($this->app->updateLink($link1['id'], $link2['id'], 'my link')); + + $link = $this->app->getLinkById($link1['id']); + $this->assertNotEmpty($link); + $this->assertEquals($link2['id'], $link['opposite_id']); + $this->assertEquals('my link', $link['label']); + + $this->assertTrue($this->app->removeLink($link1['id'])); + } +} diff --git a/tests/integration/LinkTest.php b/tests/integration/LinkTest.php deleted file mode 100644 index 16b16e50..00000000 --- a/tests/integration/LinkTest.php +++ /dev/null @@ -1,70 +0,0 @@ -app->getAllLinks(); - $this->assertNotEmpty($links); - $this->assertArrayHasKey('id', $links[0]); - $this->assertArrayHasKey('label', $links[0]); - $this->assertArrayHasKey('opposite_id', $links[0]); - } - - public function testGetOppositeLink() - { - $link = $this->app->getOppositeLinkId(1); - $this->assertEquals(1, $link); - - $link = $this->app->getOppositeLinkId(2); - $this->assertEquals(3, $link); - } - - public function testGetLinkByLabel() - { - $link = $this->app->getLinkByLabel('blocks'); - $this->assertNotEmpty($link); - $this->assertEquals(2, $link['id']); - $this->assertEquals(3, $link['opposite_id']); - } - - public function testGetLinkById() - { - $link = $this->app->getLinkById(4); - $this->assertNotEmpty($link); - $this->assertEquals(4, $link['id']); - $this->assertEquals(5, $link['opposite_id']); - $this->assertEquals('duplicates', $link['label']); - } - - public function testCreateLink() - { - $link_id = $this->app->createLink(array('label' => 'test')); - $this->assertNotFalse($link_id); - $this->assertInternalType('int', $link_id); - - $link_id = $this->app->createLink(array('label' => 'foo', 'opposite_label' => 'bar')); - $this->assertNotFalse($link_id); - $this->assertInternalType('int', $link_id); - } - - public function testUpdateLink() - { - $link1 = $this->app->getLinkByLabel('bar'); - $this->assertNotEmpty($link1); - - $link2 = $this->app->getLinkByLabel('test'); - $this->assertNotEmpty($link2); - - $this->assertNotFalse($this->app->updateLink($link1['id'], $link2['id'], 'my link')); - - $link = $this->app->getLinkById($link1['id']); - $this->assertNotEmpty($link); - $this->assertEquals($link2['id'], $link['opposite_id']); - $this->assertEquals('my link', $link['label']); - - $this->assertTrue($this->app->removeLink($link1['id'])); - } -} diff --git a/tests/integration/MeProcedureTest.php b/tests/integration/MeProcedureTest.php new file mode 100644 index 00000000..2106419c --- /dev/null +++ b/tests/integration/MeProcedureTest.php @@ -0,0 +1,68 @@ +assertGetMe(); + $this->assertCreateMyPrivateProject(); + $this->assertGetMyProjectsList(); + $this->assertGetMyProjects(); + $this->assertCreateTask(); + $this->assertGetMyDashboard(); + $this->assertGetMyActivityStream(); + } + + public function assertGetMe() + { + $profile = $this->user->getMe(); + $this->assertEquals('user', $profile['username']); + $this->assertEquals('app-user', $profile['role']); + } + + public function assertCreateMyPrivateProject() + { + $this->projectId = $this->user->createMyPrivateProject($this->projectName); + $this->assertNotFalse($this->projectId); + } + + public function assertGetMyProjectsList() + { + $projects = $this->user->getMyProjectsList(); + $this->assertNotEmpty($projects); + $this->assertEquals($this->projectName, $projects[$this->projectId]); + } + + public function assertGetMyProjects() + { + $projects = $this->user->getMyProjects(); + $this->assertNotEmpty($projects); + } + + public function assertCreateTask() + { + $taskId = $this->user->createTask(array('title' => 'My task', 'project_id' => $this->projectId, 'owner_id' => $this->userUserId)); + $this->assertNotFalse($taskId); + } + + public function assertGetMyDashboard() + { + $dashboard = $this->user->getMyDashboard(); + $this->assertNotEmpty($dashboard); + $this->assertArrayHasKey('projects', $dashboard); + $this->assertArrayHasKey('tasks', $dashboard); + $this->assertArrayHasKey('subtasks', $dashboard); + $this->assertNotEmpty($dashboard['projects']); + $this->assertNotEmpty($dashboard['tasks']); + } + + public function assertGetMyActivityStream() + { + $activity = $this->user->getMyActivityStream(); + $this->assertNotEmpty($activity); + } +} diff --git a/tests/integration/MeTest.php b/tests/integration/MeTest.php deleted file mode 100644 index 047ebf85..00000000 --- a/tests/integration/MeTest.php +++ /dev/null @@ -1,73 +0,0 @@ -assertGetMe(); - $this->assertCreateMyPrivateProject(); - $this->assertGetMyProjectsList(); - $this->assertGetMyProjects(); - $this->assertCreateTask(); - $this->assertGetMyDashboard(); - $this->assertGetMyActivityStream(); - } - - public function assertGetMe() - { - $profile = $this->user->getMe(); - $this->assertEquals('user', $profile['username']); - $this->assertEquals('app-user', $profile['role']); - } - - public function assertCreateMyPrivateProject() - { - $this->projectId = $this->user->createMyPrivateProject($this->projectName); - $this->assertNotFalse($this->projectId); - } - - public function assertGetMyProjectsList() - { - $projects = $this->user->getMyProjectsList(); - $this->assertNotEmpty($projects); - $this->assertEquals($this->projectName, $projects[$this->projectId]); - } - - public function assertGetMyProjects() - { - $projects = $this->user->getMyProjects(); - $this->assertNotEmpty($projects); - $this->assertCount(1, $projects); - $this->assertEquals($this->projectName, $projects[0]['name']); - $this->assertNotEmpty($projects[0]['url']['calendar']); - $this->assertNotEmpty($projects[0]['url']['board']); - $this->assertNotEmpty($projects[0]['url']['list']); - } - - public function assertCreateTask() - { - $taskId = $this->user->createTask(array('title' => 'My task', 'project_id' => $this->projectId, 'owner_id' => $this->userUserId)); - $this->assertNotFalse($taskId); - } - - public function assertGetMyDashboard() - { - $dashboard = $this->user->getMyDashboard(); - $this->assertNotEmpty($dashboard); - $this->assertArrayHasKey('projects', $dashboard); - $this->assertArrayHasKey('tasks', $dashboard); - $this->assertArrayHasKey('subtasks', $dashboard); - $this->assertNotEmpty($dashboard['projects']); - $this->assertNotEmpty($dashboard['tasks']); - } - - public function assertGetMyActivityStream() - { - $activity = $this->user->getMyActivityStream(); - $this->assertNotEmpty($activity); - } -} diff --git a/tests/integration/OverdueTaskProcedureTest.php b/tests/integration/OverdueTaskProcedureTest.php new file mode 100644 index 00000000..65f52301 --- /dev/null +++ b/tests/integration/OverdueTaskProcedureTest.php @@ -0,0 +1,43 @@ +assertCreateTeamProject(); + $this->assertCreateOverdueTask(); + $this->assertGetOverdueTasksByProject(); + $this->assertGetOverdueTasks(); + } + + public function assertCreateOverdueTask() + { + $this->assertNotFalse($this->app->createTask(array( + 'title' => 'overdue task', + 'project_id' => $this->projectId, + 'date_due' => date('Y-m-d', strtotime('-2days')), + ))); + } + + public function assertGetOverdueTasksByProject() + { + $tasks = $this->app->getOverdueTasksByProject($this->projectId); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals($this->projectName, $tasks[0]['project_name']); + } + + public function assertGetOverdueTasks() + { + $tasks = $this->app->getOverdueTasks(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals($this->projectName, $tasks[0]['project_name']); + } +} diff --git a/tests/integration/OverdueTaskTest.php b/tests/integration/OverdueTaskTest.php deleted file mode 100644 index 1dea5030..00000000 --- a/tests/integration/OverdueTaskTest.php +++ /dev/null @@ -1,43 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateOverdueTask(); - $this->assertGetOverdueTasksByProject(); - $this->assertGetOverdueTasks(); - } - - public function assertCreateOverdueTask() - { - $this->assertNotFalse($this->app->createTask(array( - 'title' => 'overdue task', - 'project_id' => $this->projectId, - 'date_due' => date('Y-m-d', strtotime('-2days')), - ))); - } - - public function assertGetOverdueTasksByProject() - { - $tasks = $this->app->getOverdueTasksByProject($this->projectId); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('overdue task', $tasks[0]['title']); - $this->assertEquals($this->projectName, $tasks[0]['project_name']); - } - - public function assertGetOverdueTasks() - { - $tasks = $this->app->getOverdueTasks(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('overdue task', $tasks[0]['title']); - $this->assertEquals($this->projectName, $tasks[0]['project_name']); - } -} diff --git a/tests/integration/ProcedureAuthorizationTest.php b/tests/integration/ProcedureAuthorizationTest.php new file mode 100644 index 00000000..a63e9d8c --- /dev/null +++ b/tests/integration/ProcedureAuthorizationTest.php @@ -0,0 +1,306 @@ +setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->app->getMe(); + } + + public function testUserCredentialDoNotHaveAccessToAdminProcedures() + { + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->getUser(1); + } + + public function testManagerCredentialDoNotHaveAccessToAdminProcedures() + { + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->getAllProjects(); + } + + public function testUserCredentialDoNotHaveAccessToManagerProcedures() + { + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->createProject('Team project creation are only for app managers'); + } + + public function testAppManagerCanCreateTeamProject() + { + $this->assertNotFalse($this->manager->createProject('Team project created by app manager')); + } + + public function testAdminManagerCanCreateTeamProject() + { + $projectId = $this->admin->createProject('Team project created by admin'); + $this->assertNotFalse($projectId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->assertNotNull($this->manager->getProjectById($projectId)); + } + + public function testProjectManagerCanUpdateHisProject() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Team project can be updated', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + $this->assertEquals('project-manager', $this->app->getProjectUserRole($projectId, $this->managerUserId)); + $this->assertNotNull($this->manager->getProjectById($projectId)); + + $this->assertTrue($this->manager->updateProject($projectId, 'My team project have been updated')); + } + + public function testProjectAuthorizationForbidden() + { + $projectId = $this->manager->createProject('A team project without members'); + $this->assertNotFalse($projectId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->getProjectById($projectId); + } + + public function testProjectAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'A team project with members', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId)); + $this->assertNotNull($this->user->getProjectById($projectId)); + } + + public function testActionAuthorizationForbidden() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertNotFalse($actionId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeAction($projectId); + } + + public function testActionAuthorizationForbiddenBecauseNotProjectManager() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertNotFalse($actionId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member')); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeAction($actionId); + } + + public function testActionAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertNotFalse($actionId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager')); + $this->assertTrue($this->user->removeAction($actionId)); + } + + public function testCategoryAuthorizationForbidden() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $categoryId = $this->manager->createCategory($projectId, 'Test'); + $this->assertNotFalse($categoryId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeCategory($categoryId); + } + + public function testCategoryAuthorizationForbiddenBecauseNotProjectManager() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $categoryId = $this->manager->createCategory($projectId, 'Test'); + $this->assertNotFalse($categoryId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member')); + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeCategory($categoryId); + } + + public function testCategoryAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $categoryId = $this->manager->createCategory($projectId, 'Test'); + $this->assertNotFalse($categoryId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager')); + $this->assertTrue($this->user->removeCategory($categoryId)); + } + + public function testColumnAuthorizationForbidden() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $columnId = $this->manager->addColumn($projectId, 'Test'); + $this->assertNotFalse($columnId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeColumn($columnId); + } + + public function testColumnAuthorizationForbiddenBecauseNotProjectManager() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $columnId = $this->manager->addColumn($projectId, 'Test'); + $this->assertNotFalse($columnId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member')); + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeColumn($columnId); + } + + public function testColumnAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + + $columnId = $this->manager->addColumn($projectId, 'Test'); + $this->assertNotFalse($columnId); + + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager')); + $this->assertTrue($this->user->removeColumn($columnId)); + } + + public function testCommentAuthorizationForbidden() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer')); + + $taskId = $this->manager->createTask('My Task', $projectId); + $this->assertNotFalse($taskId); + + $commentId = $this->manager->createComment($taskId, $this->userUserId, 'My comment'); + $this->assertNotFalse($commentId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->updateComment($commentId, 'something else'); + } + + public function testCommentAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member')); + + $taskId = $this->user->createTask('My Task', $projectId); + $this->assertNotFalse($taskId); + + $commentId = $this->user->createComment($taskId, $this->userUserId, 'My comment'); + $this->assertNotFalse($commentId); + + $this->assertTrue($this->user->updateComment($commentId, 'something else')); + } + + public function testSubtaskAuthorizationForbidden() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer')); + + $taskId = $this->manager->createTask('My Task', $projectId); + $this->assertNotFalse($taskId); + + $subtaskId = $this->manager->createSubtask($taskId, 'My subtask'); + $this->assertNotFalse($subtaskId); + + $this->setExpectedException('JsonRPC\Exception\AccessDeniedException'); + $this->user->removeSubtask($subtaskId); + } + + public function testSubtaskAuthorizationGranted() + { + $projectId = $this->manager->createProject(array( + 'name' => 'Test Project', + 'owner_id' => $this->managerUserId, + )); + + $this->assertNotFalse($projectId); + $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member')); + + $taskId = $this->user->createTask('My Task', $projectId); + $this->assertNotFalse($taskId); + + $subtaskId = $this->manager->createSubtask($taskId, 'My subtask'); + $this->assertNotFalse($subtaskId); + + $this->assertTrue($this->user->removeSubtask($subtaskId)); + } +} diff --git a/tests/integration/ProjectPermissionProcedureTest.php b/tests/integration/ProjectPermissionProcedureTest.php new file mode 100644 index 00000000..74313dc4 --- /dev/null +++ b/tests/integration/ProjectPermissionProcedureTest.php @@ -0,0 +1,89 @@ +assertCreateTeamProject(); + $this->assertCreateGroups(); + $this->assertCreateUser(); + + $this->assertAddProjectUser(); + $this->assertGetProjectUsers(); + $this->assertGetAssignableUsers(); + $this->assertChangeProjectUserRole(); + $this->assertRemoveProjectUser(); + + $this->assertAddProjectGroup(); + $this->assertGetProjectUsers(); + $this->assertGetAssignableUsers(); + $this->assertChangeProjectGroupRole(); + $this->assertRemoveProjectGroup(); + } + + public function assertAddProjectUser() + { + $this->assertTrue($this->app->addProjectUser($this->projectId, $this->userId)); + } + + public function assertGetProjectUsers() + { + $members = $this->app->getProjectUsers($this->projectId); + $this->assertCount(1, $members); + $this->assertArrayHasKey($this->userId, $members); + $this->assertEquals($this->username, $members[$this->userId]); + } + + public function assertGetAssignableUsers() + { + $members = $this->app->getAssignableUsers($this->projectId); + $this->assertCount(1, $members); + $this->assertArrayHasKey($this->userId, $members); + $this->assertEquals($this->username, $members[$this->userId]); + } + + public function assertChangeProjectUserRole() + { + $this->assertTrue($this->app->changeProjectUserRole($this->projectId, $this->userId, 'project-viewer')); + + $members = $this->app->getAssignableUsers($this->projectId); + $this->assertCount(0, $members); + } + + public function assertRemoveProjectUser() + { + $this->assertTrue($this->app->removeProjectUser($this->projectId, $this->userId)); + + $members = $this->app->getProjectUsers($this->projectId); + $this->assertCount(0, $members); + } + + public function assertAddProjectGroup() + { + $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId)); + $this->assertTrue($this->app->addProjectGroup($this->projectId, $this->groupId1)); + } + + public function assertChangeProjectGroupRole() + { + $this->assertTrue($this->app->changeProjectGroupRole($this->projectId, $this->groupId1, 'project-viewer')); + + $members = $this->app->getAssignableUsers($this->projectId); + $this->assertCount(0, $members); + } + + public function assertRemoveProjectGroup() + { + $this->assertTrue($this->app->removeProjectGroup($this->projectId, $this->groupId1)); + + $members = $this->app->getProjectUsers($this->projectId); + $this->assertCount(0, $members); + } +} diff --git a/tests/integration/ProjectPermissionTest.php b/tests/integration/ProjectPermissionTest.php deleted file mode 100644 index 3ceda07d..00000000 --- a/tests/integration/ProjectPermissionTest.php +++ /dev/null @@ -1,89 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateGroups(); - $this->assertCreateUser(); - - $this->assertAddProjectUser(); - $this->assertGetProjectUsers(); - $this->assertGetAssignableUsers(); - $this->assertChangeProjectUserRole(); - $this->assertRemoveProjectUser(); - - $this->assertAddProjectGroup(); - $this->assertGetProjectUsers(); - $this->assertGetAssignableUsers(); - $this->assertChangeProjectGroupRole(); - $this->assertRemoveProjectGroup(); - } - - public function assertAddProjectUser() - { - $this->assertTrue($this->app->addProjectUser($this->projectId, $this->userId)); - } - - public function assertGetProjectUsers() - { - $members = $this->app->getProjectUsers($this->projectId); - $this->assertCount(1, $members); - $this->assertArrayHasKey($this->userId, $members); - $this->assertEquals($this->username, $members[$this->userId]); - } - - public function assertGetAssignableUsers() - { - $members = $this->app->getAssignableUsers($this->projectId); - $this->assertCount(1, $members); - $this->assertArrayHasKey($this->userId, $members); - $this->assertEquals($this->username, $members[$this->userId]); - } - - public function assertChangeProjectUserRole() - { - $this->assertTrue($this->app->changeProjectUserRole($this->projectId, $this->userId, 'project-viewer')); - - $members = $this->app->getAssignableUsers($this->projectId); - $this->assertCount(0, $members); - } - - public function assertRemoveProjectUser() - { - $this->assertTrue($this->app->removeProjectUser($this->projectId, $this->userId)); - - $members = $this->app->getProjectUsers($this->projectId); - $this->assertCount(0, $members); - } - - public function assertAddProjectGroup() - { - $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId)); - $this->assertTrue($this->app->addProjectGroup($this->projectId, $this->groupId1)); - } - - public function assertChangeProjectGroupRole() - { - $this->assertTrue($this->app->changeProjectGroupRole($this->projectId, $this->groupId1, 'project-viewer')); - - $members = $this->app->getAssignableUsers($this->projectId); - $this->assertCount(0, $members); - } - - public function assertRemoveProjectGroup() - { - $this->assertTrue($this->app->removeProjectGroup($this->projectId, $this->groupId1)); - - $members = $this->app->getProjectUsers($this->projectId); - $this->assertCount(0, $members); - } -} diff --git a/tests/integration/ProjectProcedureTest.php b/tests/integration/ProjectProcedureTest.php new file mode 100644 index 00000000..1ebd48ae --- /dev/null +++ b/tests/integration/ProjectProcedureTest.php @@ -0,0 +1,89 @@ +assertCreateTeamProject(); + $this->assertGetProjectById(); + $this->assertGetProjectByName(); + $this->assertGetAllProjects(); + $this->assertUpdateProject(); + $this->assertGetProjectActivity(); + $this->assertGetProjectsActivity(); + $this->assertEnableDisableProject(); + $this->assertEnableDisablePublicAccess(); + $this->assertRemoveProject(); + } + + public function assertGetProjectById() + { + $project = $this->app->getProjectById($this->projectId); + $this->assertNotNull($project); + $this->assertEquals($this->projectName, $project['name']); + $this->assertEquals('Description', $project['description']); + } + + public function assertGetProjectByName() + { + $project = $this->app->getProjectByName($this->projectName); + $this->assertNotNull($project); + $this->assertEquals($this->projectId, $project['id']); + $this->assertEquals($this->projectName, $project['name']); + $this->assertEquals('Description', $project['description']); + } + + public function assertGetAllProjects() + { + $projects = $this->app->getAllProjects(); + $this->assertNotEmpty($projects); + } + + public function assertGetProjectActivity() + { + $activities = $this->app->getProjectActivity($this->projectId); + $this->assertInternalType('array', $activities); + $this->assertCount(0, $activities); + } + + public function assertGetProjectsActivity() + { + $activities = $this->app->getProjectActivities(array('project_ids' => array($this->projectId))); + $this->assertInternalType('array', $activities); + $this->assertCount(0, $activities); + } + + public function assertUpdateProject() + { + $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => 'test', 'description' => 'test'))); + + $project = $this->app->getProjectById($this->projectId); + $this->assertNotNull($project); + $this->assertEquals('test', $project['name']); + $this->assertEquals('test', $project['description']); + + $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => $this->projectName))); + } + + public function assertEnableDisableProject() + { + $this->assertTrue($this->app->disableProject($this->projectId)); + $this->assertTrue($this->app->enableProject($this->projectId)); + } + + public function assertEnableDisablePublicAccess() + { + $this->assertTrue($this->app->disableProjectPublicAccess($this->projectId)); + $this->assertTrue($this->app->enableProjectPublicAccess($this->projectId)); + } + + public function assertRemoveProject() + { + $this->assertTrue($this->app->removeProject($this->projectId)); + $this->assertNull($this->app->getProjectById($this->projectId)); + } +} diff --git a/tests/integration/ProjectTest.php b/tests/integration/ProjectTest.php deleted file mode 100644 index 50d4fc53..00000000 --- a/tests/integration/ProjectTest.php +++ /dev/null @@ -1,89 +0,0 @@ -assertCreateTeamProject(); - $this->assertGetProjectById(); - $this->assertGetProjectByName(); - $this->assertGetAllProjects(); - $this->assertUpdateProject(); - $this->assertGetProjectActivity(); - $this->assertGetProjectsActivity(); - $this->assertEnableDisableProject(); - $this->assertEnableDisablePublicAccess(); - $this->assertRemoveProject(); - } - - public function assertGetProjectById() - { - $project = $this->app->getProjectById($this->projectId); - $this->assertNotNull($project); - $this->assertEquals($this->projectName, $project['name']); - $this->assertEquals('Description', $project['description']); - } - - public function assertGetProjectByName() - { - $project = $this->app->getProjectByName($this->projectName); - $this->assertNotNull($project); - $this->assertEquals($this->projectId, $project['id']); - $this->assertEquals($this->projectName, $project['name']); - $this->assertEquals('Description', $project['description']); - } - - public function assertGetAllProjects() - { - $projects = $this->app->getAllProjects(); - $this->assertNotEmpty($projects); - } - - public function assertGetProjectActivity() - { - $activities = $this->app->getProjectActivity($this->projectId); - $this->assertInternalType('array', $activities); - $this->assertCount(0, $activities); - } - - public function assertGetProjectsActivity() - { - $activities = $this->app->getProjectActivities(array('project_ids' => array($this->projectId))); - $this->assertInternalType('array', $activities); - $this->assertCount(0, $activities); - } - - public function assertUpdateProject() - { - $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => 'test', 'description' => 'test'))); - - $project = $this->app->getProjectById($this->projectId); - $this->assertNotNull($project); - $this->assertEquals('test', $project['name']); - $this->assertEquals('test', $project['description']); - - $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => $this->projectName))); - } - - public function assertEnableDisableProject() - { - $this->assertTrue($this->app->disableProject($this->projectId)); - $this->assertTrue($this->app->enableProject($this->projectId)); - } - - public function assertEnableDisablePublicAccess() - { - $this->assertTrue($this->app->disableProjectPublicAccess($this->projectId)); - $this->assertTrue($this->app->enableProjectPublicAccess($this->projectId)); - } - - public function assertRemoveProject() - { - $this->assertTrue($this->app->removeProject($this->projectId)); - $this->assertNull($this->app->getProjectById($this->projectId)); - } -} diff --git a/tests/integration/SubtaskProcedureTest.php b/tests/integration/SubtaskProcedureTest.php new file mode 100644 index 00000000..7ab4ef0b --- /dev/null +++ b/tests/integration/SubtaskProcedureTest.php @@ -0,0 +1,64 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertCreateSubtask(); + $this->assertGetSubtask(); + $this->assertUpdateSubtask(); + $this->assertGetAllSubtasks(); + $this->assertRemoveSubtask(); + } + + public function assertCreateSubtask() + { + $this->subtaskId = $this->app->createSubtask(array( + 'task_id' => $this->taskId, + 'title' => 'subtask #1', + )); + + $this->assertNotFalse($this->subtaskId); + } + + public function assertGetSubtask() + { + $subtask = $this->app->getSubtask($this->subtaskId); + $this->assertEquals($this->taskId, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + } + + public function assertUpdateSubtask() + { + $this->assertTrue($this->app->execute('updateSubtask', array( + 'id' => $this->subtaskId, + 'task_id' => $this->taskId, + 'title' => 'test', + ))); + + $subtask = $this->app->getSubtask($this->subtaskId); + $this->assertEquals('test', $subtask['title']); + } + + public function assertGetAllSubtasks() + { + $subtasks = $this->app->getAllSubtasks($this->taskId); + $this->assertCount(1, $subtasks); + $this->assertEquals('test', $subtasks[0]['title']); + } + + public function assertRemoveSubtask() + { + $this->assertTrue($this->app->removeSubtask($this->subtaskId)); + + $subtasks = $this->app->getAllSubtasks($this->taskId); + $this->assertCount(0, $subtasks); + } +} diff --git a/tests/integration/SubtaskTest.php b/tests/integration/SubtaskTest.php deleted file mode 100644 index 10082e60..00000000 --- a/tests/integration/SubtaskTest.php +++ /dev/null @@ -1,64 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateTask(); - $this->assertCreateSubtask(); - $this->assertGetSubtask(); - $this->assertUpdateSubtask(); - $this->assertGetAllSubtasks(); - $this->assertRemoveSubtask(); - } - - public function assertCreateSubtask() - { - $this->subtaskId = $this->app->createSubtask(array( - 'task_id' => $this->taskId, - 'title' => 'subtask #1', - )); - - $this->assertNotFalse($this->subtaskId); - } - - public function assertGetSubtask() - { - $subtask = $this->app->getSubtask($this->subtaskId); - $this->assertEquals($this->taskId, $subtask['task_id']); - $this->assertEquals('subtask #1', $subtask['title']); - } - - public function assertUpdateSubtask() - { - $this->assertTrue($this->app->execute('updateSubtask', array( - 'id' => $this->subtaskId, - 'task_id' => $this->taskId, - 'title' => 'test', - ))); - - $subtask = $this->app->getSubtask($this->subtaskId); - $this->assertEquals('test', $subtask['title']); - } - - public function assertGetAllSubtasks() - { - $subtasks = $this->app->getAllSubtasks($this->taskId); - $this->assertCount(1, $subtasks); - $this->assertEquals('test', $subtasks[0]['title']); - } - - public function assertRemoveSubtask() - { - $this->assertTrue($this->app->removeSubtask($this->subtaskId)); - - $subtasks = $this->app->getAllSubtasks($this->taskId); - $this->assertCount(0, $subtasks); - } -} diff --git a/tests/integration/SwimlaneProcedureTest.php b/tests/integration/SwimlaneProcedureTest.php new file mode 100644 index 00000000..e64342b4 --- /dev/null +++ b/tests/integration/SwimlaneProcedureTest.php @@ -0,0 +1,93 @@ +assertCreateTeamProject(); + } + + public function assertGetDefaultSwimlane() + { + $swimlane = $this->app->getDefaultSwimlane($this->projectId); + $this->assertNotEmpty($swimlane); + $this->assertEquals('Default swimlane', $swimlane['default_swimlane']); + } + + public function assertAddSwimlane() + { + $this->swimlaneId = $this->app->addSwimlane($this->projectId, 'Swimlane 1'); + $this->assertNotFalse($this->swimlaneId); + $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane 2')); + } + + public function assertGetSwimlane() + { + $swimlane = $this->app->getSwimlane($this->swimlaneId); + $this->assertInternalType('array', $swimlane); + $this->assertEquals('Swimlane 1', $swimlane['name']); + } + + public function assertUpdateSwimlane() + { + $this->assertTrue($this->app->updateSwimlane($this->swimlaneId, 'Another swimlane')); + + $swimlane = $this->app->getSwimlaneById($this->swimlaneId); + $this->assertEquals('Another swimlane', $swimlane['name']); + } + + public function assertDisableSwimlane() + { + $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId)); + + $swimlane = $this->app->getSwimlaneById($this->swimlaneId); + $this->assertEquals(0, $swimlane['is_active']); + } + + public function assertEnableSwimlane() + { + $this->assertTrue($this->app->enableSwimlane($this->projectId, $this->swimlaneId)); + + $swimlane = $this->app->getSwimlaneById($this->swimlaneId); + $this->assertEquals(1, $swimlane['is_active']); + } + + public function assertGetAllSwimlanes() + { + $swimlanes = $this->app->getAllSwimlanes($this->projectId); + $this->assertCount(2, $swimlanes); + $this->assertEquals('Another swimlane', $swimlanes[0]['name']); + $this->assertEquals('Swimlane 2', $swimlanes[1]['name']); + } + + public function assertGetActiveSwimlane() + { + $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId)); + + $swimlanes = $this->app->getActiveSwimlanes($this->projectId); + $this->assertCount(2, $swimlanes); + $this->assertEquals('Default swimlane', $swimlanes[0]['name']); + $this->assertEquals('Swimlane 2', $swimlanes[1]['name']); + } + + public function assertRemoveSwimlane() + { + $this->assertTrue($this->app->removeSwimlane($this->projectId, $this->swimlaneId)); + } + + public function assertChangePosition() + { + $swimlaneId1 = $this->app->addSwimlane($this->projectId, 'Swimlane A'); + $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane B')); + + $swimlanes = $this->app->getAllSwimlanes($this->projectId); + $this->assertCount(3, $swimlanes); + + $this->assertTrue($this->app->changeSwimlanePosition($this->projectId, $swimlaneId1, 3)); + } +} diff --git a/tests/integration/SwimlaneTest.php b/tests/integration/SwimlaneTest.php deleted file mode 100644 index 4f703414..00000000 --- a/tests/integration/SwimlaneTest.php +++ /dev/null @@ -1,93 +0,0 @@ -assertCreateTeamProject(); - } - - public function assertGetDefaultSwimlane() - { - $swimlane = $this->app->getDefaultSwimlane($this->projectId); - $this->assertNotEmpty($swimlane); - $this->assertEquals('Default swimlane', $swimlane['default_swimlane']); - } - - public function assertAddSwimlane() - { - $this->swimlaneId = $this->app->addSwimlane($this->projectId, 'Swimlane 1'); - $this->assertNotFalse($this->swimlaneId); - $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane 2')); - } - - public function assertGetSwimlane() - { - $swimlane = $this->app->getSwimlane($this->swimlaneId); - $this->assertInternalType('array', $swimlane); - $this->assertEquals('Swimlane 1', $swimlane['name']); - } - - public function assertUpdateSwimlane() - { - $this->assertTrue($this->app->updateSwimlane($this->swimlaneId, 'Another swimlane')); - - $swimlane = $this->app->getSwimlaneById($this->swimlaneId); - $this->assertEquals('Another swimlane', $swimlane['name']); - } - - public function assertDisableSwimlane() - { - $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId)); - - $swimlane = $this->app->getSwimlaneById($this->swimlaneId); - $this->assertEquals(0, $swimlane['is_active']); - } - - public function assertEnableSwimlane() - { - $this->assertTrue($this->app->enableSwimlane($this->projectId, $this->swimlaneId)); - - $swimlane = $this->app->getSwimlaneById($this->swimlaneId); - $this->assertEquals(1, $swimlane['is_active']); - } - - public function assertGetAllSwimlanes() - { - $swimlanes = $this->app->getAllSwimlanes($this->projectId); - $this->assertCount(2, $swimlanes); - $this->assertEquals('Another swimlane', $swimlanes[0]['name']); - $this->assertEquals('Swimlane 2', $swimlanes[1]['name']); - } - - public function assertGetActiveSwimlane() - { - $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId)); - - $swimlanes = $this->app->getActiveSwimlanes($this->projectId); - $this->assertCount(2, $swimlanes); - $this->assertEquals('Default swimlane', $swimlanes[0]['name']); - $this->assertEquals('Swimlane 2', $swimlanes[1]['name']); - } - - public function assertRemoveSwimlane() - { - $this->assertTrue($this->app->removeSwimlane($this->projectId, $this->swimlaneId)); - } - - public function assertChangePosition() - { - $swimlaneId1 = $this->app->addSwimlane($this->projectId, 'Swimlane A'); - $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane B')); - - $swimlanes = $this->app->getAllSwimlanes($this->projectId); - $this->assertCount(3, $swimlanes); - - $this->assertTrue($this->app->changeSwimlanePosition($this->projectId, $swimlaneId1, 3)); - } -} diff --git a/tests/integration/TaskFileProcedureTest.php b/tests/integration/TaskFileProcedureTest.php new file mode 100644 index 00000000..61155555 --- /dev/null +++ b/tests/integration/TaskFileProcedureTest.php @@ -0,0 +1,67 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertCreateTaskFile(); + $this->assertGetTaskFile(); + $this->assertDownloadTaskFile(); + $this->assertGetAllFiles(); + $this->assertRemoveTaskFile(); + $this->assertRemoveAllTaskFiles(); + } + + public function assertCreateTaskFile() + { + $this->fileId = $this->app->createTaskFile(1, $this->taskId, 'My file', base64_encode('plain text file')); + $this->assertNotFalse($this->fileId); + } + + public function assertGetTaskFile() + { + $file = $this->app->getTaskFile($this->fileId); + $this->assertNotEmpty($file); + $this->assertEquals('My file', $file['name']); + } + + public function assertDownloadTaskFile() + { + $content = $this->app->downloadTaskFile($this->fileId); + $this->assertNotEmpty($content); + $this->assertEquals('plain text file', base64_decode($content)); + } + + public function assertGetAllFiles() + { + $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); + $this->assertCount(1, $files); + $this->assertEquals('My file', $files[0]['name']); + } + + public function assertRemoveTaskFile() + { + $this->assertTrue($this->app->removeTaskFile($this->fileId)); + + $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); + $this->assertEmpty($files); + } + + public function assertRemoveAllTaskFiles() + { + $this->assertCreateTaskFile(); + $this->assertCreateTaskFile(); + + $this->assertTrue($this->app->removeAllTaskFiles($this->taskId)); + + $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); + $this->assertEmpty($files); + } +} diff --git a/tests/integration/TaskFileTest.php b/tests/integration/TaskFileTest.php deleted file mode 100644 index 7e9e943b..00000000 --- a/tests/integration/TaskFileTest.php +++ /dev/null @@ -1,67 +0,0 @@ -assertCreateTeamProject(); - $this->assertCreateTask(); - $this->assertCreateTaskFile(); - $this->assertGetTaskFile(); - $this->assertDownloadTaskFile(); - $this->assertGetAllFiles(); - $this->assertRemoveTaskFile(); - $this->assertRemoveAllTaskFiles(); - } - - public function assertCreateTaskFile() - { - $this->fileId = $this->app->createTaskFile(1, $this->taskId, 'My file', base64_encode('plain text file')); - $this->assertNotFalse($this->fileId); - } - - public function assertGetTaskFile() - { - $file = $this->app->getTaskFile($this->fileId); - $this->assertNotEmpty($file); - $this->assertEquals('My file', $file['name']); - } - - public function assertDownloadTaskFile() - { - $content = $this->app->downloadTaskFile($this->fileId); - $this->assertNotEmpty($content); - $this->assertEquals('plain text file', base64_decode($content)); - } - - public function assertGetAllFiles() - { - $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); - $this->assertCount(1, $files); - $this->assertEquals('My file', $files[0]['name']); - } - - public function assertRemoveTaskFile() - { - $this->assertTrue($this->app->removeTaskFile($this->fileId)); - - $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); - $this->assertEmpty($files); - } - - public function assertRemoveAllTaskFiles() - { - $this->assertCreateTaskFile(); - $this->assertCreateTaskFile(); - - $this->assertTrue($this->app->removeAllTaskFiles($this->taskId)); - - $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId)); - $this->assertEmpty($files); - } -} diff --git a/tests/integration/TaskLinkProcedureTest.php b/tests/integration/TaskLinkProcedureTest.php new file mode 100644 index 00000000..a25fced5 --- /dev/null +++ b/tests/integration/TaskLinkProcedureTest.php @@ -0,0 +1,68 @@ +assertCreateTeamProject(); + + $this->taskId1 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 1')); + $this->taskId2 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 2')); + + $this->assertNotFalse($this->taskId1); + $this->assertNotFalse($this->taskId2); + + $this->assertCreateTaskLink(); + $this->assertGetTaskLink(); + $this->assertGetAllTaskLinks(); + $this->assertUpdateTaskLink(); + $this->assertRemoveTaskLink(); + } + + public function assertCreateTaskLink() + { + $this->taskLinkId = $this->app->createTaskLink($this->taskId1, $this->taskId2, 1); + $this->assertNotFalse($this->taskLinkId); + } + + public function assertGetTaskLink() + { + $link = $this->app->getTaskLinkById($this->taskLinkId); + $this->assertNotNull($link); + $this->assertEquals($this->taskId1, $link['task_id']); + $this->assertEquals($this->taskId2, $link['opposite_task_id']); + $this->assertEquals(1, $link['link_id']); + } + + public function assertGetAllTaskLinks() + { + $links = $this->app->getAllTaskLinks($this->taskId2); + $this->assertCount(1, $links); + } + + public function assertUpdateTaskLink() + { + $this->assertTrue($this->app->updateTaskLink($this->taskLinkId, $this->taskId1, $this->taskId2, 3)); + + $link = $this->app->getTaskLinkById($this->taskLinkId); + $this->assertNotNull($link); + $this->assertEquals($this->taskId1, $link['task_id']); + $this->assertEquals($this->taskId2, $link['opposite_task_id']); + $this->assertEquals(3, $link['link_id']); + } + + public function assertRemoveTaskLink() + { + $this->assertTrue($this->app->removeTaskLink($this->taskLinkId)); + + $links = $this->app->getAllTaskLinks($this->taskId2); + $this->assertCount(0, $links); + } +} diff --git a/tests/integration/TaskLinkTest.php b/tests/integration/TaskLinkTest.php deleted file mode 100644 index 03bc437b..00000000 --- a/tests/integration/TaskLinkTest.php +++ /dev/null @@ -1,68 +0,0 @@ -assertCreateTeamProject(); - - $this->taskId1 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 1')); - $this->taskId2 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 2')); - - $this->assertNotFalse($this->taskId1); - $this->assertNotFalse($this->taskId2); - - $this->assertCreateTaskLink(); - $this->assertGetTaskLink(); - $this->assertGetAllTaskLinks(); - $this->assertUpdateTaskLink(); - $this->assertRemoveTaskLink(); - } - - public function assertCreateTaskLink() - { - $this->taskLinkId = $this->app->createTaskLink($this->taskId1, $this->taskId2, 1); - $this->assertNotFalse($this->taskLinkId); - } - - public function assertGetTaskLink() - { - $link = $this->app->getTaskLinkById($this->taskLinkId); - $this->assertNotNull($link); - $this->assertEquals($this->taskId1, $link['task_id']); - $this->assertEquals($this->taskId2, $link['opposite_task_id']); - $this->assertEquals(1, $link['link_id']); - } - - public function assertGetAllTaskLinks() - { - $links = $this->app->getAllTaskLinks($this->taskId2); - $this->assertCount(1, $links); - } - - public function assertUpdateTaskLink() - { - $this->assertTrue($this->app->updateTaskLink($this->taskLinkId, $this->taskId1, $this->taskId2, 3)); - - $link = $this->app->getTaskLinkById($this->taskLinkId); - $this->assertNotNull($link); - $this->assertEquals($this->taskId1, $link['task_id']); - $this->assertEquals($this->taskId2, $link['opposite_task_id']); - $this->assertEquals(3, $link['link_id']); - } - - public function assertRemoveTaskLink() - { - $this->assertTrue($this->app->removeTaskLink($this->taskLinkId)); - - $links = $this->app->getAllTaskLinks($this->taskId2); - $this->assertCount(0, $links); - } -} 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)); + } +} diff --git a/tests/integration/TaskTest.php b/tests/integration/TaskTest.php deleted file mode 100644 index 6f1d9d62..00000000 --- a/tests/integration/TaskTest.php +++ /dev/null @@ -1,55 +0,0 @@ -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)); - } -} diff --git a/tests/integration/UserProcedureTest.php b/tests/integration/UserProcedureTest.php new file mode 100644 index 00000000..290f87fb --- /dev/null +++ b/tests/integration/UserProcedureTest.php @@ -0,0 +1,63 @@ +assertCreateUser(); + $this->assertGetUserById(); + $this->assertGetUserByName(); + $this->assertGetAllUsers(); + $this->assertEnableDisableUser(); + $this->assertUpdateUser(); + $this->assertRemoveUser(); + } + + public function assertGetUserById() + { + $user = $this->app->getUser($this->userId); + $this->assertNotNull($user); + $this->assertEquals($this->username, $user['username']); + } + + public function assertGetUserByName() + { + $user = $this->app->getUserByName($this->username); + $this->assertNotNull($user); + $this->assertEquals($this->username, $user['username']); + } + + public function assertGetAllUsers() + { + $users = $this->app->getAllUsers(); + $this->assertInternalType('array', $users); + $this->assertNotEmpty($users); + } + + public function assertEnableDisableUser() + { + $this->assertTrue($this->app->disableUser($this->userId)); + $this->assertFalse($this->app->isActiveUser($this->userId)); + $this->assertTrue($this->app->enableUser($this->userId)); + $this->assertTrue($this->app->isActiveUser($this->userId)); + } + + public function assertUpdateUser() + { + $this->assertTrue($this->app->updateUser(array( + 'id' => $this->userId, + 'name' => 'My user', + ))); + + $user = $this->app->getUser($this->userId); + $this->assertNotNull($user); + $this->assertEquals('My user', $user['name']); + } + + public function assertRemoveUser() + { + $this->assertTrue($this->app->removeUser($this->userId)); + } +} diff --git a/tests/integration/UserTest.php b/tests/integration/UserTest.php deleted file mode 100644 index c407c918..00000000 --- a/tests/integration/UserTest.php +++ /dev/null @@ -1,63 +0,0 @@ -assertCreateUser(); - $this->assertGetUserById(); - $this->assertGetUserByName(); - $this->assertGetAllUsers(); - $this->assertEnableDisableUser(); - $this->assertUpdateUser(); - $this->assertRemoveUser(); - } - - public function assertGetUserById() - { - $user = $this->app->getUser($this->userId); - $this->assertNotNull($user); - $this->assertEquals($this->username, $user['username']); - } - - public function assertGetUserByName() - { - $user = $this->app->getUserByName($this->username); - $this->assertNotNull($user); - $this->assertEquals($this->username, $user['username']); - } - - public function assertGetAllUsers() - { - $users = $this->app->getAllUsers(); - $this->assertInternalType('array', $users); - $this->assertNotEmpty($users); - } - - public function assertEnableDisableUser() - { - $this->assertTrue($this->app->disableUser($this->userId)); - $this->assertFalse($this->app->isActiveUser($this->userId)); - $this->assertTrue($this->app->enableUser($this->userId)); - $this->assertTrue($this->app->isActiveUser($this->userId)); - } - - public function assertUpdateUser() - { - $this->assertTrue($this->app->updateUser(array( - 'id' => $this->userId, - 'name' => 'My user', - ))); - - $user = $this->app->getUser($this->userId); - $this->assertNotNull($user); - $this->assertEquals('My user', $user['name']); - } - - public function assertRemoveUser() - { - $this->assertTrue($this->app->removeUser($this->userId)); - } -} diff --git a/tests/units/Model/ActionModelTest.php b/tests/units/Model/ActionModelTest.php new file mode 100644 index 00000000..4e21a999 --- /dev/null +++ b/tests/units/Model/ActionModelTest.php @@ -0,0 +1,527 @@ +container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + } + + public function testRemove() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertNotEmpty($actionModel->getById(1)); + $this->assertTrue($actionModel->remove(1)); + $this->assertEmpty($actionModel->getById(1)); + } + + public function testGetById() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $action = $actionModel->getById(1); + $this->assertNotEmpty($action); + $this->assertEquals(1, $action['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $action['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']); + } + + public function testGetProjectId() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(1, $actionModel->getProjectId(1)); + $this->assertSame(0, $actionModel->getProjectId(42)); + } + + public function testGetAll() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); + + $actions = $actionModel->getAll(); + $this->assertCount(2, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + $this->assertEquals(2, $actions[1]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[1]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']); + } + + public function testGetAllByProject() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); + + $actions = $actionModel->getAllByProject(1); + $this->assertCount(1, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); + } + + public function testGetAllByUser() + { + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'test4', 'is_active' => 0))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_VIEWER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 3, Role::PROJECT_MANAGER)); + $this->assertTrue($projectUserRoleModel->addUser(3, 3, Role::PROJECT_MANAGER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); + + $this->assertEquals(3, $actionModel->create(array( + 'project_id' => 3, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 10, 'color_id' => 'green'), + ))); + + $actions = $actionModel->getAllByUser(1); + $this->assertCount(0, $actions); + + $actions = $actionModel->getAllByUser(2); + $this->assertCount(1, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + $actions = $actionModel->getAllByUser(3); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); + } + + public function testDuplicateWithColumnAndColorParameter() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); + } + + public function testDuplicateWithColumnsParameter() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']); + } + + public function testDuplicateWithColumnParameterNotfound() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $columnModel = new ColumnModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertTrue($columnModel->update(2, 'My unique column')); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 2, 'color_id' => 'green'), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); + } + + public function testDuplicateWithProjectParameter() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CLOSE, + 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', + 'params' => array('column_id' => 1, 'project_id' => 3), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CLOSE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']); + } + + public function testDuplicateWithProjectParameterIdenticalToDestination() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CLOSE, + 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', + 'params' => array('column_id' => 1, 'project_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithUserParameter() + { + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'user_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']); + } + + public function testDuplicateWithUserParameterButNotAssignable() + { + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_VIEWER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'user_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithUserParameterButNotAvailable() + { + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'owner_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithCategoryParameter() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c1', 'project_id' => 2))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']); + $this->assertEquals(TaskModel::EVENT_CREATE_UPDATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']); + } + + public function testDuplicateWithCategoryParameterButDifferentName() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithCategoryParameterButNotFound() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } +} diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php deleted file mode 100644 index 5db18983..00000000 --- a/tests/units/Model/ActionTest.php +++ /dev/null @@ -1,509 +0,0 @@ -container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - } - - public function testRemove() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertNotEmpty($actionModel->getById(1)); - $this->assertTrue($actionModel->remove(1)); - $this->assertEmpty($actionModel->getById(1)); - } - - public function testGetById() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $action = $actionModel->getById(1); - $this->assertNotEmpty($action); - $this->assertEquals(1, $action['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $action['event_name']); - $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']); - } - - public function testGetAll() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertEquals(2, $actionModel->create(array( - 'project_id' => 2, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 6, 'color_id' => 'blue'), - ))); - - $actions = $actionModel->getAll(); - $this->assertCount(2, $actions); - - $this->assertEquals(1, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); - - $this->assertEquals(2, $actions[1]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']); - $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[1]['event_name']); - $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']); - } - - public function testGetAllByProject() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertEquals(2, $actionModel->create(array( - 'project_id' => 2, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 6, 'color_id' => 'blue'), - ))); - - $actions = $actionModel->getAllByProject(1); - $this->assertCount(1, $actions); - - $this->assertEquals(1, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); - - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); - } - - public function testGetAllByUser() - { - $projectModel = new ProjectModel($this->container); - $projectUserRoleModel = new ProjectUserRoleModel($this->container); - $userModel = new UserModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $this->assertEquals(3, $projectModel->create(array('name' => 'test4', 'is_active' => 0))); - - $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); - $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); - - $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_VIEWER)); - $this->assertTrue($projectUserRoleModel->addUser(2, 3, Role::PROJECT_MANAGER)); - $this->assertTrue($projectUserRoleModel->addUser(3, 3, Role::PROJECT_MANAGER)); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertEquals(2, $actionModel->create(array( - 'project_id' => 2, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 6, 'color_id' => 'blue'), - ))); - - $this->assertEquals(3, $actionModel->create(array( - 'project_id' => 3, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 10, 'color_id' => 'green'), - ))); - - $actions = $actionModel->getAllByUser(1); - $this->assertCount(0, $actions); - - $actions = $actionModel->getAllByUser(2); - $this->assertCount(1, $actions); - - $this->assertEquals(1, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); - - $actions = $actionModel->getAllByUser(3); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); - } - - public function testDuplicateWithColumnAndColorParameter() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); - } - - public function testDuplicateWithColumnsParameter() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']); - } - - public function testDuplicateWithColumnParameterNotfound() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - $columnModel = new ColumnModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertTrue($columnModel->update(2, 'My unique column')); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 1, 'color_id' => 'red'), - ))); - - $this->assertEquals(2, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', - 'params' => array('column_id' => 2, 'color_id' => 'green'), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); - } - - public function testDuplicateWithProjectParameter() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $this->assertEquals(3, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CLOSE, - 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', - 'params' => array('column_id' => 1, 'project_id' => 3), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CLOSE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']); - } - - public function testDuplicateWithProjectParameterIdenticalToDestination() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CLOSE, - 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', - 'params' => array('column_id' => 1, 'project_id' => 2), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(0, $actions); - } - - public function testDuplicateWithUserParameter() - { - $projectUserRoleModel = new ProjectUserRoleModel($this->container); - $userModel = new UserModel($this->container); - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); - - $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', - 'params' => array('column_id' => 1, 'user_id' => 2), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']); - } - - public function testDuplicateWithUserParameterButNotAssignable() - { - $projectUserRoleModel = new ProjectUserRoleModel($this->container); - $userModel = new UserModel($this->container); - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); - - $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_VIEWER)); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', - 'params' => array('column_id' => 1, 'user_id' => 2), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(0, $actions); - } - - public function testDuplicateWithUserParameterButNotAvailable() - { - $projectUserRoleModel = new ProjectUserRoleModel($this->container); - $userModel = new UserModel($this->container); - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); - - $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', - 'params' => array('column_id' => 1, 'owner_id' => 2), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(0, $actions); - } - - public function testDuplicateWithCategoryParameter() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'c1', 'project_id' => 2))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE_UPDATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', - 'params' => array('column_id' => 1, 'category_id' => 1), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(1, $actions); - - $this->assertEquals(2, $actions[0]['project_id']); - $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']); - $this->assertEquals(TaskModel::EVENT_CREATE_UPDATE, $actions[0]['event_name']); - $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']); - } - - public function testDuplicateWithCategoryParameterButDifferentName() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE_UPDATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', - 'params' => array('column_id' => 1, 'category_id' => 1), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(0, $actions); - } - - public function testDuplicateWithCategoryParameterButNotFound() - { - $projectModel = new ProjectModel($this->container); - $actionModel = new ActionModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - - $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); - - $this->assertEquals(1, $actionModel->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE_UPDATE, - 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', - 'params' => array('column_id' => 1, 'category_id' => 1), - ))); - - $this->assertTrue($actionModel->duplicate(1, 2)); - - $actions = $actionModel->getAllByProject(2); - $this->assertCount(0, $actions); - } -} diff --git a/tests/units/Model/CategoryModelTest.php b/tests/units/Model/CategoryModelTest.php new file mode 100644 index 00000000..80a20af6 --- /dev/null +++ b/tests/units/Model/CategoryModelTest.php @@ -0,0 +1,229 @@ +container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + + $task = $taskFinderModel->getById(1); + $this->assertEquals(2, $task['category_id']); + + $category = $categoryModel->getById(2); + $this->assertEquals(2, $category['id']); + $this->assertEquals('Category #2', $category['name']); + $this->assertEquals(1, $category['project_id']); + } + + public function testExists() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertFalse($categoryModel->exists(2)); + } + + public function testGetById() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $category = $categoryModel->getById(1); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); + } + + public function testGetNameById() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertEquals('Category #1', $categoryModel->getNameById(1)); + $this->assertEquals('', $categoryModel->getNameById(2)); + } + + public function testGetIdByName() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertSame(1, $categoryModel->getIdByName(1, 'Category #1')); + $this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2')); + } + + public function testGetProjectId() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertEquals(1, $categoryModel->getProjectId(1)); + $this->assertSame(0, $categoryModel->getProjectId(2)); + } + + public function testGetList() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + + $categories = $categoryModel->getList(1, false, false); + $this->assertCount(2, $categories); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + + $categories = $categoryModel->getList(1, true, false); + $this->assertCount(3, $categories); + $this->assertEquals('No category', $categories[0]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + + $categories = $categoryModel->getList(1, false, true); + $this->assertCount(3, $categories); + $this->assertEquals('All categories', $categories[-1]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + + $categories = $categoryModel->getList(1, true, true); + $this->assertCount(4, $categories); + $this->assertEquals('All categories', $categories[-1]); + $this->assertEquals('No category', $categories[0]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + } + + public function testGetAll() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + + $categories = $categoryModel->getAll(1); + $this->assertCount(2, $categories); + + $this->assertEquals('Category #1', $categories[0]['name']); + $this->assertEquals('test', $categories[0]['description']); + $this->assertEquals(1, $categories[0]['project_id']); + $this->assertEquals(1, $categories[0]['id']); + + $this->assertEquals('Category #2', $categories[1]['name']); + $this->assertEquals('', $categories[1]['description']); + $this->assertEquals(1, $categories[1]['project_id']); + $this->assertEquals(2, $categories[1]['id']); + } + + public function testCreateDefaultCategories() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + $configModel = new ConfigModel($this->container); + + $this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertTrue($categoryModel->createDefaultCategories(1)); + + $categories = $categoryModel->getAll(1); + $this->assertCount(3, $categories); + $this->assertEquals('C1', $categories[0]['name']); + $this->assertEquals('C2', $categories[1]['name']); + $this->assertEquals('C3', $categories[2]['name']); + } + + public function testUpdate() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertTrue($categoryModel->update(array('id' => 1, 'description' => 'test'))); + + $category = $categoryModel->getById(1); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); + } + + public function testRemove() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + + $task = $taskFinderModel->getById(1); + $this->assertEquals(2, $task['category_id']); + + $this->assertTrue($categoryModel->remove(1)); + $this->assertTrue($categoryModel->remove(2)); + + // Make sure tasks assigned with that category are reseted + $task = $taskFinderModel->getById(1); + $this->assertEquals(0, $task['category_id']); + } + + public function testDuplicate() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertTrue($categoryModel->duplicate(1, 2)); + + $category = $categoryModel->getById(1); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); + + $category = $categoryModel->getById(2); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(2, $category['project_id']); + $this->assertEquals('test', $category['description']); + } +} diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php deleted file mode 100644 index 1fdc51f6..00000000 --- a/tests/units/Model/CategoryTest.php +++ /dev/null @@ -1,217 +0,0 @@ -container); - $taskFinderModel = new TaskFinderModel($this->container); - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - - $task = $taskFinderModel->getById(1); - $this->assertEquals(2, $task['category_id']); - - $category = $categoryModel->getById(2); - $this->assertEquals(2, $category['id']); - $this->assertEquals('Category #2', $category['name']); - $this->assertEquals(1, $category['project_id']); - } - - public function testExists() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertTrue($categoryModel->exists(1)); - $this->assertFalse($categoryModel->exists(2)); - } - - public function testGetById() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - - $category = $categoryModel->getById(1); - $this->assertEquals(1, $category['id']); - $this->assertEquals('Category #1', $category['name']); - $this->assertEquals(1, $category['project_id']); - $this->assertEquals('test', $category['description']); - } - - public function testGetNameById() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - - $this->assertEquals('Category #1', $categoryModel->getNameById(1)); - $this->assertEquals('', $categoryModel->getNameById(2)); - } - - public function testGetIdByName() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - - $this->assertSame(1, $categoryModel->getIdByName(1, 'Category #1')); - $this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2')); - } - - public function testGetList() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); - - $categories = $categoryModel->getList(1, false, false); - $this->assertCount(2, $categories); - $this->assertEquals('Category #1', $categories[1]); - $this->assertEquals('Category #2', $categories[2]); - - $categories = $categoryModel->getList(1, true, false); - $this->assertCount(3, $categories); - $this->assertEquals('No category', $categories[0]); - $this->assertEquals('Category #1', $categories[1]); - $this->assertEquals('Category #2', $categories[2]); - - $categories = $categoryModel->getList(1, false, true); - $this->assertCount(3, $categories); - $this->assertEquals('All categories', $categories[-1]); - $this->assertEquals('Category #1', $categories[1]); - $this->assertEquals('Category #2', $categories[2]); - - $categories = $categoryModel->getList(1, true, true); - $this->assertCount(4, $categories); - $this->assertEquals('All categories', $categories[-1]); - $this->assertEquals('No category', $categories[0]); - $this->assertEquals('Category #1', $categories[1]); - $this->assertEquals('Category #2', $categories[2]); - } - - public function testGetAll() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); - - $categories = $categoryModel->getAll(1); - $this->assertCount(2, $categories); - - $this->assertEquals('Category #1', $categories[0]['name']); - $this->assertEquals('test', $categories[0]['description']); - $this->assertEquals(1, $categories[0]['project_id']); - $this->assertEquals(1, $categories[0]['id']); - - $this->assertEquals('Category #2', $categories[1]['name']); - $this->assertEquals('', $categories[1]['description']); - $this->assertEquals(1, $categories[1]['project_id']); - $this->assertEquals(2, $categories[1]['id']); - } - - public function testCreateDefaultCategories() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - $configModel = new ConfigModel($this->container); - - $this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3'))); - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertTrue($categoryModel->createDefaultCategories(1)); - - $categories = $categoryModel->getAll(1); - $this->assertCount(3, $categories); - $this->assertEquals('C1', $categories[0]['name']); - $this->assertEquals('C2', $categories[1]['name']); - $this->assertEquals('C3', $categories[2]['name']); - } - - public function testUpdate() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertTrue($categoryModel->update(array('id' => 1, 'description' => 'test'))); - - $category = $categoryModel->getById(1); - $this->assertEquals('Category #1', $category['name']); - $this->assertEquals(1, $category['project_id']); - $this->assertEquals('test', $category['description']); - } - - public function testRemove() - { - $taskCreationModel = new TaskCreationModel($this->container); - $taskFinderModel = new TaskFinderModel($this->container); - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - - $task = $taskFinderModel->getById(1); - $this->assertEquals(2, $task['category_id']); - - $this->assertTrue($categoryModel->remove(1)); - $this->assertTrue($categoryModel->remove(2)); - - // Make sure tasks assigned with that category are reseted - $task = $taskFinderModel->getById(1); - $this->assertEquals(0, $task['category_id']); - } - - public function testDuplicate() - { - $projectModel = new ProjectModel($this->container); - $categoryModel = new CategoryModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); - $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); - - $this->assertTrue($categoryModel->duplicate(1, 2)); - - $category = $categoryModel->getById(1); - $this->assertEquals('Category #1', $category['name']); - $this->assertEquals(1, $category['project_id']); - $this->assertEquals('test', $category['description']); - - $category = $categoryModel->getById(2); - $this->assertEquals('Category #1', $category['name']); - $this->assertEquals(2, $category['project_id']); - $this->assertEquals('test', $category['description']); - } -} diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php index 7250ae0b..574b5a87 100644 --- a/tests/units/Model/CommentTest.php +++ b/tests/units/Model/CommentTest.php @@ -10,16 +10,16 @@ class CommentTest extends Base { public function testCreate() { - $c = new CommentModel($this->container); - $tc = new TaskCreationModel($this->container); - $p = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertEquals(1, $c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1))); - $this->assertEquals(2, $c->create(array('task_id' => 1, 'comment' => 'bla bla'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1))); + $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla'))); - $comment = $c->getById(1); + $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals('bla bla', $comment['comment']); $this->assertEquals(1, $comment['task_id']); @@ -27,7 +27,7 @@ class CommentTest extends Base $this->assertEquals('admin', $comment['username']); $this->assertEquals(time(), $comment['date_creation'], '', 3); - $comment = $c->getById(2); + $comment = $commentModel->getById(2); $this->assertNotEmpty($comment); $this->assertEquals('bla bla', $comment['comment']); $this->assertEquals(1, $comment['task_id']); @@ -38,17 +38,17 @@ class CommentTest extends Base public function testGetAll() { - $c = new CommentModel($this->container); - $tc = new TaskCreationModel($this->container); - $p = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); - $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); - $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); + $this->assertEquals(3, $commentModel->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); - $comments = $c->getAll(1); + $comments = $commentModel->getAll(1); $this->assertNotEmpty($comments); $this->assertEquals(3, count($comments)); @@ -56,37 +56,51 @@ class CommentTest extends Base $this->assertEquals(2, $comments[1]['id']); $this->assertEquals(3, $comments[2]['id']); - $this->assertEquals(3, $c->count(1)); + $this->assertEquals(3, $commentModel->count(1)); } public function testUpdate() { - $c = new CommentModel($this->container); - $tc = new TaskCreationModel($this->container); - $p = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); - $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'bla'))); - $comment = $c->getById(1); + $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals('bla', $comment['comment']); } public function validateRemove() { - $c = new CommentModel($this->container); - $tc = new TaskCreationModel($this->container); - $p = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); - $this->assertTrue($c->remove(1)); - $this->assertFalse($c->remove(1)); - $this->assertFalse($c->remove(1111)); + $this->assertTrue($commentModel->remove(1)); + $this->assertFalse($commentModel->remove(1)); + $this->assertFalse($commentModel->remove(1111)); + } + + public function testGetProjectId() + { + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + + $this->assertEquals(1, $commentModel->getProjectId(1)); + $this->assertSame(0, $commentModel->getProjectId(2)); } } diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php new file mode 100644 index 00000000..6451189d --- /dev/null +++ b/tests/units/Model/SubtaskModelTest.php @@ -0,0 +1,400 @@ +assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function onSubtaskUpdated($event) + { + $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertArrayHasKey('changes', $data); + $this->assertArrayHasKey('user_id', $data['changes']); + $this->assertArrayHasKey('status', $data['changes']); + + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']); + $this->assertEquals(1, $data['changes']['user_id']); + } + + public function onSubtaskDeleted($event) + { + $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function testCreation() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated')); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testModification() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertTrue($subtaskModel->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS))); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testRemove() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted')); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + + $this->assertTrue($subtaskModel->remove(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertEmpty($subtask); + } + + public function testToggleStatusWithoutSession() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + } + + public function testToggleStatusWithSession() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + // Set the current logged user + $this->container['sessionStorage']->user = array('id' => 1); + + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1)); + + $subtask = $subtaskModel->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['task_id']); + } + + public function testCloseAll() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1))); + + $this->assertTrue($subtaskModel->closeAll(1)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertNotEmpty($subtasks); + + foreach ($subtasks as $subtask) { + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); + } + } + + public function testDuplicate() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + // We create a project + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + // We create 2 tasks + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0))); + + // We create many subtasks for the first task + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on'))); + $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1))); + + // We duplicate our subtasks + $this->assertTrue($subtaskModel->duplicate(1, 2)); + $subtasks = $subtaskModel->getAll(2); + + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertEquals(2, count($subtasks)); + + $this->assertEquals('subtask #1', $subtasks[0]['title']); + $this->assertEquals('subtask #2', $subtasks[1]['title']); + + $this->assertEquals(2, $subtasks[0]['task_id']); + $this->assertEquals(2, $subtasks[1]['task_id']); + + $this->assertEquals(5, $subtasks[0]['time_estimated']); + $this->assertEquals(0, $subtasks[1]['time_estimated']); + + $this->assertEquals(0, $subtasks[0]['time_spent']); + $this->assertEquals(0, $subtasks[1]['time_spent']); + + $this->assertEquals(0, $subtasks[0]['status']); + $this->assertEquals(0, $subtasks[1]['status']); + + $this->assertEquals(0, $subtasks[0]['user_id']); + $this->assertEquals(0, $subtasks[1]['user_id']); + + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(2, $subtasks[1]['position']); + } + + public function testChangePosition() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1))); + $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1))); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(2, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 3, 2)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(3, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(2, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 2, 1)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(2, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(1, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 2, 2)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(2, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 1, 3)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(2, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(3, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(1, $subtasks[2]['id']); + + $this->assertFalse($subtaskModel->changePosition(1, 2, 0)); + $this->assertFalse($subtaskModel->changePosition(1, 2, 4)); + } + + public function testConvertToTask() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3))); + $task_id = $subtaskModel->convertToTask(1, 1); + + $this->assertNotFalse($task_id); + $this->assertEmpty($subtaskModel->getById(1)); + + $task = $taskFinderModel->getById($task_id); + $this->assertEquals('subtask #1', $task['title']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(2, $task['time_spent']); + $this->assertEquals(3, $task['time_estimated']); + } + + public function testGetProjectId() + { + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $this->assertEquals(1, $subtaskModel->getProjectId(1)); + $this->assertEquals(0, $subtaskModel->getProjectId(2)); + } +} diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php deleted file mode 100644 index b65ee609..00000000 --- a/tests/units/Model/SubtaskTest.php +++ /dev/null @@ -1,388 +0,0 @@ -assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); - $data = $event->getAll(); - - $this->assertArrayHasKey('id', $data); - $this->assertArrayHasKey('title', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('time_estimated', $data); - $this->assertArrayHasKey('time_spent', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('task_id', $data); - $this->assertArrayHasKey('user_id', $data); - $this->assertArrayHasKey('position', $data); - $this->assertNotEmpty($data['task_id']); - $this->assertNotEmpty($data['id']); - } - - public function onSubtaskUpdated($event) - { - $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); - $data = $event->getAll(); - - $this->assertArrayHasKey('id', $data); - $this->assertArrayHasKey('title', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('time_estimated', $data); - $this->assertArrayHasKey('time_spent', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('task_id', $data); - $this->assertArrayHasKey('user_id', $data); - $this->assertArrayHasKey('position', $data); - $this->assertArrayHasKey('changes', $data); - $this->assertArrayHasKey('user_id', $data['changes']); - $this->assertArrayHasKey('status', $data['changes']); - - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']); - $this->assertEquals(1, $data['changes']['user_id']); - } - - public function onSubtaskDeleted($event) - { - $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event); - $data = $event->getAll(); - - $this->assertArrayHasKey('id', $data); - $this->assertArrayHasKey('title', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('time_estimated', $data); - $this->assertArrayHasKey('time_spent', $data); - $this->assertArrayHasKey('status', $data); - $this->assertArrayHasKey('task_id', $data); - $this->assertArrayHasKey('user_id', $data); - $this->assertArrayHasKey('position', $data); - $this->assertNotEmpty($data['task_id']); - $this->assertNotEmpty($data['id']); - } - - public function testCreation() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated')); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['id']); - $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); - $this->assertEquals(0, $subtask['time_estimated']); - $this->assertEquals(0, $subtask['time_spent']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['position']); - } - - public function testModification() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS))); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['id']); - $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); - $this->assertEquals(0, $subtask['time_estimated']); - $this->assertEquals(0, $subtask['time_spent']); - $this->assertEquals(1, $subtask['user_id']); - $this->assertEquals(1, $subtask['position']); - } - - public function testRemove() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - - $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted')); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - - $this->assertTrue($s->remove(1)); - - $subtask = $s->getById(1); - $this->assertEmpty($subtask); - } - - public function testToggleStatusWithoutSession() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - } - - public function testToggleStatusWithSession() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - $us = new UserSession($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); - $this->assertEquals(0, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - // Set the current logged user - $this->container['sessionStorage']->user = array('id' => 1); - - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); - $this->assertEquals(1, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); - $this->assertEquals(1, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - - $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); - - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); - $this->assertEquals(1, $subtask['user_id']); - $this->assertEquals(1, $subtask['task_id']); - } - - public function testCloseAll() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1))); - - $this->assertTrue($s->closeAll(1)); - - $subtasks = $s->getAll(1); - $this->assertNotEmpty($subtasks); - - foreach ($subtasks as $subtask) { - $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); - } - } - - public function testDuplicate() - { - $tc = new TaskCreationModel($this->container); - $s = new SubtaskModel($this->container); - $p = new ProjectModel($this->container); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - - // We create 2 tasks - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0))); - - // We create many subtasks for the first task - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on'))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1))); - - // We duplicate our subtasks - $this->assertTrue($s->duplicate(1, 2)); - $subtasks = $s->getAll(2); - - $this->assertNotFalse($subtasks); - $this->assertNotEmpty($subtasks); - $this->assertEquals(2, count($subtasks)); - - $this->assertEquals('subtask #1', $subtasks[0]['title']); - $this->assertEquals('subtask #2', $subtasks[1]['title']); - - $this->assertEquals(2, $subtasks[0]['task_id']); - $this->assertEquals(2, $subtasks[1]['task_id']); - - $this->assertEquals(5, $subtasks[0]['time_estimated']); - $this->assertEquals(0, $subtasks[1]['time_estimated']); - - $this->assertEquals(0, $subtasks[0]['time_spent']); - $this->assertEquals(0, $subtasks[1]['time_spent']); - - $this->assertEquals(0, $subtasks[0]['status']); - $this->assertEquals(0, $subtasks[1]['status']); - - $this->assertEquals(0, $subtasks[0]['user_id']); - $this->assertEquals(0, $subtasks[1]['user_id']); - - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(2, $subtasks[1]['position']); - } - - public function testChangePosition() - { - $taskCreationModel = new TaskCreationModel($this->container); - $subtaskModel = new SubtaskModel($this->container); - $projectModel = new ProjectModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1))); - $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1))); - - $subtasks = $subtaskModel->getAll(1); - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(1, $subtasks[0]['id']); - $this->assertEquals(2, $subtasks[1]['position']); - $this->assertEquals(2, $subtasks[1]['id']); - $this->assertEquals(3, $subtasks[2]['position']); - $this->assertEquals(3, $subtasks[2]['id']); - - $this->assertTrue($subtaskModel->changePosition(1, 3, 2)); - - $subtasks = $subtaskModel->getAll(1); - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(1, $subtasks[0]['id']); - $this->assertEquals(2, $subtasks[1]['position']); - $this->assertEquals(3, $subtasks[1]['id']); - $this->assertEquals(3, $subtasks[2]['position']); - $this->assertEquals(2, $subtasks[2]['id']); - - $this->assertTrue($subtaskModel->changePosition(1, 2, 1)); - - $subtasks = $subtaskModel->getAll(1); - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(2, $subtasks[0]['id']); - $this->assertEquals(2, $subtasks[1]['position']); - $this->assertEquals(1, $subtasks[1]['id']); - $this->assertEquals(3, $subtasks[2]['position']); - $this->assertEquals(3, $subtasks[2]['id']); - - $this->assertTrue($subtaskModel->changePosition(1, 2, 2)); - - $subtasks = $subtaskModel->getAll(1); - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(1, $subtasks[0]['id']); - $this->assertEquals(2, $subtasks[1]['position']); - $this->assertEquals(2, $subtasks[1]['id']); - $this->assertEquals(3, $subtasks[2]['position']); - $this->assertEquals(3, $subtasks[2]['id']); - - $this->assertTrue($subtaskModel->changePosition(1, 1, 3)); - - $subtasks = $subtaskModel->getAll(1); - $this->assertEquals(1, $subtasks[0]['position']); - $this->assertEquals(2, $subtasks[0]['id']); - $this->assertEquals(2, $subtasks[1]['position']); - $this->assertEquals(3, $subtasks[1]['id']); - $this->assertEquals(3, $subtasks[2]['position']); - $this->assertEquals(1, $subtasks[2]['id']); - - $this->assertFalse($subtaskModel->changePosition(1, 2, 0)); - $this->assertFalse($subtaskModel->changePosition(1, 2, 4)); - } - - public function testConvertToTask() - { - $taskCreationModel = new TaskCreationModel($this->container); - $taskFinderModel = new TaskFinderModel($this->container); - $subtaskModel = new SubtaskModel($this->container); - $projectModel = new ProjectModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3))); - $task_id = $subtaskModel->convertToTask(1, 1); - - $this->assertNotFalse($task_id); - $this->assertEmpty($subtaskModel->getById(1)); - - $task = $taskFinderModel->getById($task_id); - $this->assertEquals('subtask #1', $task['title']); - $this->assertEquals(1, $task['project_id']); - $this->assertEquals(1, $task['owner_id']); - $this->assertEquals(2, $task['time_spent']); - $this->assertEquals(3, $task['time_estimated']); - } -} diff --git a/tests/units/Model/TaskFileModelTest.php b/tests/units/Model/TaskFileModelTest.php new file mode 100644 index 00000000..de12553f --- /dev/null +++ b/tests/units/Model/TaskFileModelTest.php @@ -0,0 +1,458 @@ +container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals('/tmp/foo', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + + $this->assertEquals(2, $fileModel->create(1, 'test2.png', '/tmp/foobar', 10)); + + $file = $fileModel->getById(2); + $this->assertEquals('test2.png', $file['name']); + $this->assertEquals('/tmp/foobar', $file['path']); + $this->assertEquals(1, $file['is_image']); + } + + public function testCreationWithFileNameTooLong() + { + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertNotFalse($fileModel->create(1, 'test', '/tmp/foo', 10)); + $this->assertNotFalse($fileModel->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); + + $files = $fileModel->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertEquals(str_repeat('a', 255), $files[0]['name']); + $this->assertEquals('test', $files[1]['name']); + } + + public function testCreationWithSessionOpen() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals(1, $file['user_id']); + } + + public function testGetAll() + { + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $fileModel->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(4, $fileModel->create(1, 'C.JPG', '/tmp/foo', 10)); + + $fileModeliles = $fileModel->getAll(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(4, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('B.pdf', $fileModeliles[1]['name']); + $this->assertEquals('C.JPG', $fileModeliles[2]['name']); + $this->assertEquals('D.doc', $fileModeliles[3]['name']); + + $fileModeliles = $fileModel->getAllImages(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('C.JPG', $fileModeliles[1]['name']); + + $fileModeliles = $fileModel->getAllDocuments(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('B.pdf', $fileModeliles[0]['name']); + $this->assertEquals('D.doc', $fileModeliles[1]['name']); + } + + public function testIsImage() + { + $fileModel = new TaskFileModel($this->container); + + $this->assertTrue($fileModel->isImage('test.png')); + $this->assertTrue($fileModel->isImage('test.jpeg')); + $this->assertTrue($fileModel->isImage('test.gif')); + $this->assertTrue($fileModel->isImage('test.jpg')); + $this->assertTrue($fileModel->isImage('test.JPG')); + + $this->assertFalse($fileModel->isImage('test.bmp')); + $this->assertFalse($fileModel->isImage('test')); + $this->assertFalse($fileModel->isImage('test.pdf')); + } + + public function testGetThumbnailPath() + { + $fileModel = new TaskFileModel($this->container); + $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); + } + + public function testGeneratePath() + { + $fileModel = new TaskFileModel($this->container); + + $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); + $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); + } + + public function testUploadFiles() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFileModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + + $this->assertTrue($fileModel->uploadFiles(1, $files)); + + $files = $fileModel->getAll(1); + $this->assertCount(2, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('file1.png', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(123, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + + $this->assertEquals(2, $files[1]['id']); + $this->assertEquals('file2.doc', $files[1]['name']); + $this->assertEquals(0, $files[1]['is_image']); + $this->assertEquals(1, $files[1]['task_id']); + $this->assertEquals(0, $files[1]['user_id']); + $this->assertEquals(456, $files[1]['size']); + $this->assertEquals(time(), $files[1]['date'], '', 2); + } + + public function testUploadFilesWithEmptyFiles() + { + $fileModel = new TaskFileModel($this->container); + $this->assertFalse($fileModel->uploadFiles(1, array())); + } + + public function testUploadFilesWithUploadError() + { + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_CANT_WRITE, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel = new TaskFileModel($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFilesWithObjectStorageError() + { + $files = array( + 'name' => array( + 'file1.csv', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $fileModel = new TaskFileModel($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFileContent() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFileModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('test.doc', $files[0]['name']); + $this->assertEquals(0, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testUploadFileContentWithObjectStorageError() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFileModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + } + + public function testUploadScreenshot() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFileModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromData')) + ->getMock(); + + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromData'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadScreenshot(1, base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertStringStartsWith('Screenshot taken ', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testRemove() + { + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveWithObjectStorageError() + { + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo') + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->remove(1)); + } + + public function testRemoveImage() + { + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'image.gif', 'tmp/image.gif', 10)); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('remove') + ->with('tmp/image.gif'); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('remove') + ->with('thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveAll() + { + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->exactly(2)) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->removeAll(1)); + } + + public function testGetProjectId() + { + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foobar', 10)); + $this->assertEquals(1, $fileModel->getProjectId(1)); + $this->assertEquals(0, $fileModel->getProjectId(2)); + } +} diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php deleted file mode 100644 index 2faee95c..00000000 --- a/tests/units/Model/TaskFileTest.php +++ /dev/null @@ -1,445 +0,0 @@ -container); - $fileModel = new TaskFileModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); - - $file = $fileModel->getById(1); - $this->assertEquals('test', $file['name']); - $this->assertEquals('/tmp/foo', $file['path']); - $this->assertEquals(0, $file['is_image']); - $this->assertEquals(1, $file['task_id']); - $this->assertEquals(time(), $file['date'], '', 2); - $this->assertEquals(0, $file['user_id']); - $this->assertEquals(10, $file['size']); - - $this->assertEquals(2, $fileModel->create(1, 'test2.png', '/tmp/foobar', 10)); - - $file = $fileModel->getById(2); - $this->assertEquals('test2.png', $file['name']); - $this->assertEquals('/tmp/foobar', $file['path']); - $this->assertEquals(1, $file['is_image']); - } - - public function testCreationWithFileNameTooLong() - { - $projectModel = new ProjectModel($this->container); - $fileModel = new TaskFileModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertNotFalse($fileModel->create(1, 'test', '/tmp/foo', 10)); - $this->assertNotFalse($fileModel->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); - - $files = $fileModel->getAll(1); - $this->assertNotEmpty($files); - $this->assertCount(2, $files); - - $this->assertEquals(str_repeat('a', 255), $files[0]['name']); - $this->assertEquals('test', $files[1]['name']); - } - - public function testCreationWithSessionOpen() - { - $this->container['sessionStorage']->user = array('id' => 1); - - $projectModel = new ProjectModel($this->container); - $fileModel = new TaskFileModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); - - $file = $fileModel->getById(1); - $this->assertEquals('test', $file['name']); - $this->assertEquals(1, $file['user_id']); - } - - public function testGetAll() - { - $projectModel = new ProjectModel($this->container); - $fileModel = new TaskFileModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertEquals(1, $fileModel->create(1, 'B.pdf', '/tmp/foo', 10)); - $this->assertEquals(2, $fileModel->create(1, 'A.png', '/tmp/foo', 10)); - $this->assertEquals(3, $fileModel->create(1, 'D.doc', '/tmp/foo', 10)); - $this->assertEquals(4, $fileModel->create(1, 'C.JPG', '/tmp/foo', 10)); - - $fileModeliles = $fileModel->getAll(1); - $this->assertNotEmpty($fileModeliles); - $this->assertCount(4, $fileModeliles); - $this->assertEquals('A.png', $fileModeliles[0]['name']); - $this->assertEquals('B.pdf', $fileModeliles[1]['name']); - $this->assertEquals('C.JPG', $fileModeliles[2]['name']); - $this->assertEquals('D.doc', $fileModeliles[3]['name']); - - $fileModeliles = $fileModel->getAllImages(1); - $this->assertNotEmpty($fileModeliles); - $this->assertCount(2, $fileModeliles); - $this->assertEquals('A.png', $fileModeliles[0]['name']); - $this->assertEquals('C.JPG', $fileModeliles[1]['name']); - - $fileModeliles = $fileModel->getAllDocuments(1); - $this->assertNotEmpty($fileModeliles); - $this->assertCount(2, $fileModeliles); - $this->assertEquals('B.pdf', $fileModeliles[0]['name']); - $this->assertEquals('D.doc', $fileModeliles[1]['name']); - } - - public function testIsImage() - { - $fileModel = new TaskFileModel($this->container); - - $this->assertTrue($fileModel->isImage('test.png')); - $this->assertTrue($fileModel->isImage('test.jpeg')); - $this->assertTrue($fileModel->isImage('test.gif')); - $this->assertTrue($fileModel->isImage('test.jpg')); - $this->assertTrue($fileModel->isImage('test.JPG')); - - $this->assertFalse($fileModel->isImage('test.bmp')); - $this->assertFalse($fileModel->isImage('test')); - $this->assertFalse($fileModel->isImage('test.pdf')); - } - - public function testGetThumbnailPath() - { - $fileModel = new TaskFileModel($this->container); - $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); - } - - public function testGeneratePath() - { - $fileModel = new TaskFileModel($this->container); - - $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); - $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); - } - - public function testUploadFiles() - { - $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFileModel') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromFile')) - ->getMock(); - - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $files = array( - 'name' => array( - 'file1.png', - 'file2.doc', - ), - 'tmp_name' => array( - '/tmp/phpYzdqkD', - '/tmp/phpeEwEWG', - ), - 'error' => array( - UPLOAD_ERR_OK, - UPLOAD_ERR_OK, - ), - 'size' => array( - 123, - 456, - ), - ); - - $fileModel - ->expects($this->once()) - ->method('generateThumbnailFromFile'); - - $this->container['objectStorage'] - ->expects($this->at(0)) - ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); - - $this->assertTrue($fileModel->uploadFiles(1, $files)); - - $files = $fileModel->getAll(1); - $this->assertCount(2, $files); - - $this->assertEquals(1, $files[0]['id']); - $this->assertEquals('file1.png', $files[0]['name']); - $this->assertEquals(1, $files[0]['is_image']); - $this->assertEquals(1, $files[0]['task_id']); - $this->assertEquals(0, $files[0]['user_id']); - $this->assertEquals(123, $files[0]['size']); - $this->assertEquals(time(), $files[0]['date'], '', 2); - - $this->assertEquals(2, $files[1]['id']); - $this->assertEquals('file2.doc', $files[1]['name']); - $this->assertEquals(0, $files[1]['is_image']); - $this->assertEquals(1, $files[1]['task_id']); - $this->assertEquals(0, $files[1]['user_id']); - $this->assertEquals(456, $files[1]['size']); - $this->assertEquals(time(), $files[1]['date'], '', 2); - } - - public function testUploadFilesWithEmptyFiles() - { - $fileModel = new TaskFileModel($this->container); - $this->assertFalse($fileModel->uploadFiles(1, array())); - } - - public function testUploadFilesWithUploadError() - { - $files = array( - 'name' => array( - 'file1.png', - 'file2.doc', - ), - 'tmp_name' => array( - '', - '/tmp/phpeEwEWG', - ), - 'error' => array( - UPLOAD_ERR_CANT_WRITE, - UPLOAD_ERR_OK, - ), - 'size' => array( - 123, - 456, - ), - ); - - $fileModel = new TaskFileModel($this->container); - $this->assertFalse($fileModel->uploadFiles(1, $files)); - } - - public function testUploadFilesWithObjectStorageError() - { - $files = array( - 'name' => array( - 'file1.csv', - 'file2.doc', - ), - 'tmp_name' => array( - '/tmp/phpYzdqkD', - '/tmp/phpeEwEWG', - ), - 'error' => array( - UPLOAD_ERR_OK, - UPLOAD_ERR_OK, - ), - 'size' => array( - 123, - 456, - ), - ); - - $this->container['objectStorage'] - ->expects($this->at(0)) - ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) - ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - - $fileModel = new TaskFileModel($this->container); - $this->assertFalse($fileModel->uploadFiles(1, $files)); - } - - public function testUploadFileContent() - { - $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFileModel') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromFile')) - ->getMock(); - - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - $data = 'test'; - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('put') - ->with($this->anything(), $this->equalTo($data)); - - $this->assertEquals(1, $fileModel->uploadContent(1, 'test.doc', base64_encode($data))); - - $files = $fileModel->getAll(1); - $this->assertCount(1, $files); - - $this->assertEquals(1, $files[0]['id']); - $this->assertEquals('test.doc', $files[0]['name']); - $this->assertEquals(0, $files[0]['is_image']); - $this->assertEquals(1, $files[0]['task_id']); - $this->assertEquals(0, $files[0]['user_id']); - $this->assertEquals(4, $files[0]['size']); - $this->assertEquals(time(), $files[0]['date'], '', 2); - } - - public function testUploadFileContentWithObjectStorageError() - { - $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFileModel') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromFile')) - ->getMock(); - - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - $data = 'test'; - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('put') - ->with($this->anything(), $this->equalTo($data)) - ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - - $this->assertFalse($fileModel->uploadContent(1, 'test.doc', base64_encode($data))); - } - - public function testUploadScreenshot() - { - $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFileModel') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromData')) - ->getMock(); - - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - $data = 'test'; - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $fileModel - ->expects($this->once()) - ->method('generateThumbnailFromData'); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('put') - ->with($this->anything(), $this->equalTo($data)); - - $this->assertEquals(1, $fileModel->uploadScreenshot(1, base64_encode($data))); - - $files = $fileModel->getAll(1); - $this->assertCount(1, $files); - - $this->assertEquals(1, $files[0]['id']); - $this->assertStringStartsWith('Screenshot taken ', $files[0]['name']); - $this->assertEquals(1, $files[0]['is_image']); - $this->assertEquals(1, $files[0]['task_id']); - $this->assertEquals(0, $files[0]['user_id']); - $this->assertEquals(4, $files[0]['size']); - $this->assertEquals(time(), $files[0]['date'], '', 2); - } - - public function testRemove() - { - $fileModel = new TaskFileModel($this->container); - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('remove') - ->with('tmp/foo'); - - $this->assertTrue($fileModel->remove(1)); - } - - public function testRemoveWithObjectStorageError() - { - $fileModel = new TaskFileModel($this->container); - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('remove') - ->with('tmp/foo') - ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - - $this->assertFalse($fileModel->remove(1)); - } - - public function testRemoveImage() - { - $fileModel = new TaskFileModel($this->container); - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $fileModel->create(1, 'image.gif', 'tmp/image.gif', 10)); - - $this->container['objectStorage'] - ->expects($this->at(0)) - ->method('remove') - ->with('tmp/image.gif'); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('remove') - ->with('thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'); - - $this->assertTrue($fileModel->remove(1)); - } - - public function testRemoveAll() - { - $fileModel = new TaskFileModel($this->container); - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); - $this->assertEquals(2, $fileModel->create(1, 'test', 'tmp/foo', 10)); - - $this->container['objectStorage'] - ->expects($this->exactly(2)) - ->method('remove') - ->with('tmp/foo'); - - $this->assertTrue($fileModel->removeAll(1)); - } -} diff --git a/tests/units/Model/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php new file mode 100644 index 00000000..78590891 --- /dev/null +++ b/tests/units/Model/TaskLinkModelTest.php @@ -0,0 +1,211 @@ +container); + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C'))); + + $this->assertNotFalse($taskLinkModel->create(1, 2, 9)); + $this->assertNotFalse($taskLinkModel->create(1, 3, 9)); + + $task = $taskFinderModel->getExtendedQuery()->findOne(); + $this->assertNotEmpty($task); + } + + public function testCreateTaskLinkWithNoOpposite() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 1)); + + $links = $taskLinkModel->getAll(1); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('relates to', $links[0]['label']); + $this->assertEquals('B', $links[0]['title']); + $this->assertEquals(2, $links[0]['task_id']); + $this->assertEquals(1, $links[0]['is_active']); + + $links = $taskLinkModel->getAll(2); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('relates to', $links[0]['label']); + $this->assertEquals('A', $links[0]['title']); + $this->assertEquals(1, $links[0]['task_id']); + $this->assertEquals(1, $links[0]['is_active']); + + $task_link = $taskLinkModel->getById(1); + $this->assertNotEmpty($task_link); + $this->assertEquals(1, $task_link['id']); + $this->assertEquals(1, $task_link['task_id']); + $this->assertEquals(2, $task_link['opposite_task_id']); + $this->assertEquals(1, $task_link['link_id']); + + $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link); + $this->assertNotEmpty($opposite_task_link); + $this->assertEquals(2, $opposite_task_link['id']); + $this->assertEquals(2, $opposite_task_link['task_id']); + $this->assertEquals(1, $opposite_task_link['opposite_task_id']); + $this->assertEquals(1, $opposite_task_link['link_id']); + } + + public function testCreateTaskLinkWithOpposite() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 2)); + + $links = $taskLinkModel->getAll(1); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('blocks', $links[0]['label']); + $this->assertEquals('B', $links[0]['title']); + $this->assertEquals(2, $links[0]['task_id']); + $this->assertEquals(1, $links[0]['is_active']); + + $links = $taskLinkModel->getAll(2); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('is blocked by', $links[0]['label']); + $this->assertEquals('A', $links[0]['title']); + $this->assertEquals(1, $links[0]['task_id']); + $this->assertEquals(1, $links[0]['is_active']); + + $task_link = $taskLinkModel->getById(1); + $this->assertNotEmpty($task_link); + $this->assertEquals(1, $task_link['id']); + $this->assertEquals(1, $task_link['task_id']); + $this->assertEquals(2, $task_link['opposite_task_id']); + $this->assertEquals(2, $task_link['link_id']); + + $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link); + $this->assertNotEmpty($opposite_task_link); + $this->assertEquals(2, $opposite_task_link['id']); + $this->assertEquals(2, $opposite_task_link['task_id']); + $this->assertEquals(1, $opposite_task_link['opposite_task_id']); + $this->assertEquals(3, $opposite_task_link['link_id']); + } + + public function testGroupByLabel() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C'))); + + $this->assertNotFalse($taskLinkModel->create(1, 2, 2)); + $this->assertNotFalse($taskLinkModel->create(1, 3, 2)); + + $links = $taskLinkModel->getAllGroupedByLabel(1); + $this->assertCount(1, $links); + $this->assertArrayHasKey('blocks', $links); + $this->assertCount(2, $links['blocks']); + $this->assertEquals('test', $links['blocks'][0]['project_name']); + $this->assertEquals('Backlog', $links['blocks'][0]['column_title']); + $this->assertEquals('blocks', $links['blocks'][0]['label']); + } + + public function testUpdate() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'B'))); + $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C'))); + + $this->assertEquals(1, $taskLinkModel->create(1, 2, 5)); + $this->assertTrue($taskLinkModel->update(1, 1, 3, 11)); + + $links = $taskLinkModel->getAll(1); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('is fixed by', $links[0]['label']); + $this->assertEquals('C', $links[0]['title']); + $this->assertEquals(3, $links[0]['task_id']); + + $links = $taskLinkModel->getAll(2); + $this->assertEmpty($links); + + $links = $taskLinkModel->getAll(3); + $this->assertNotEmpty($links); + $this->assertCount(1, $links); + $this->assertEquals('fixes', $links[0]['label']); + $this->assertEquals('A', $links[0]['title']); + $this->assertEquals(1, $links[0]['task_id']); + } + + public function testRemove() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 2)); + + $links = $taskLinkModel->getAll(1); + $this->assertNotEmpty($links); + $links = $taskLinkModel->getAll(2); + $this->assertNotEmpty($links); + + $this->assertTrue($taskLinkModel->remove($links[0]['id'])); + + $links = $taskLinkModel->getAll(1); + $this->assertEmpty($links); + $links = $taskLinkModel->getAll(2); + $this->assertEmpty($links); + } + + public function testGetProjectId() + { + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 2)); + + $this->assertEquals(1, $taskLinkModel->getProjectId(1)); + $this->assertEquals(0, $taskLinkModel->getProjectId(42)); + } +} diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php deleted file mode 100644 index bc574731..00000000 --- a/tests/units/Model/TaskLinkTest.php +++ /dev/null @@ -1,196 +0,0 @@ -container); - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C'))); - - $this->assertNotFalse($tl->create(1, 2, 9)); - $this->assertNotFalse($tl->create(1, 3, 9)); - - $task = $tf->getExtendedQuery()->findOne(); - $this->assertNotEmpty($task); - } - - public function testCreateTaskLinkWithNoOpposite() - { - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertEquals(1, $tl->create(1, 2, 1)); - - $links = $tl->getAll(1); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('relates to', $links[0]['label']); - $this->assertEquals('B', $links[0]['title']); - $this->assertEquals(2, $links[0]['task_id']); - $this->assertEquals(1, $links[0]['is_active']); - - $links = $tl->getAll(2); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('relates to', $links[0]['label']); - $this->assertEquals('A', $links[0]['title']); - $this->assertEquals(1, $links[0]['task_id']); - $this->assertEquals(1, $links[0]['is_active']); - - $task_link = $tl->getById(1); - $this->assertNotEmpty($task_link); - $this->assertEquals(1, $task_link['id']); - $this->assertEquals(1, $task_link['task_id']); - $this->assertEquals(2, $task_link['opposite_task_id']); - $this->assertEquals(1, $task_link['link_id']); - - $opposite_task_link = $tl->getOppositeTaskLink($task_link); - $this->assertNotEmpty($opposite_task_link); - $this->assertEquals(2, $opposite_task_link['id']); - $this->assertEquals(2, $opposite_task_link['task_id']); - $this->assertEquals(1, $opposite_task_link['opposite_task_id']); - $this->assertEquals(1, $opposite_task_link['link_id']); - } - - public function testCreateTaskLinkWithOpposite() - { - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertEquals(1, $tl->create(1, 2, 2)); - - $links = $tl->getAll(1); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('blocks', $links[0]['label']); - $this->assertEquals('B', $links[0]['title']); - $this->assertEquals(2, $links[0]['task_id']); - $this->assertEquals(1, $links[0]['is_active']); - - $links = $tl->getAll(2); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('is blocked by', $links[0]['label']); - $this->assertEquals('A', $links[0]['title']); - $this->assertEquals(1, $links[0]['task_id']); - $this->assertEquals(1, $links[0]['is_active']); - - $task_link = $tl->getById(1); - $this->assertNotEmpty($task_link); - $this->assertEquals(1, $task_link['id']); - $this->assertEquals(1, $task_link['task_id']); - $this->assertEquals(2, $task_link['opposite_task_id']); - $this->assertEquals(2, $task_link['link_id']); - - $opposite_task_link = $tl->getOppositeTaskLink($task_link); - $this->assertNotEmpty($opposite_task_link); - $this->assertEquals(2, $opposite_task_link['id']); - $this->assertEquals(2, $opposite_task_link['task_id']); - $this->assertEquals(1, $opposite_task_link['opposite_task_id']); - $this->assertEquals(3, $opposite_task_link['link_id']); - } - - public function testGroupByLabel() - { - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C'))); - - $this->assertNotFalse($tl->create(1, 2, 2)); - $this->assertNotFalse($tl->create(1, 3, 2)); - - $links = $tl->getAllGroupedByLabel(1); - $this->assertCount(1, $links); - $this->assertArrayHasKey('blocks', $links); - $this->assertCount(2, $links['blocks']); - $this->assertEquals('test', $links['blocks'][0]['project_name']); - $this->assertEquals('Backlog', $links['blocks'][0]['column_title']); - $this->assertEquals('blocks', $links['blocks'][0]['label']); - } - - public function testUpdate() - { - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B'))); - $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C'))); - - $this->assertEquals(1, $tl->create(1, 2, 5)); - $this->assertTrue($tl->update(1, 1, 3, 11)); - - $links = $tl->getAll(1); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('is fixed by', $links[0]['label']); - $this->assertEquals('C', $links[0]['title']); - $this->assertEquals(3, $links[0]['task_id']); - - $links = $tl->getAll(2); - $this->assertEmpty($links); - - $links = $tl->getAll(3); - $this->assertNotEmpty($links); - $this->assertCount(1, $links); - $this->assertEquals('fixes', $links[0]['label']); - $this->assertEquals('A', $links[0]['title']); - $this->assertEquals(1, $links[0]['task_id']); - } - - public function testRemove() - { - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertEquals(1, $tl->create(1, 2, 2)); - - $links = $tl->getAll(1); - $this->assertNotEmpty($links); - $links = $tl->getAll(2); - $this->assertNotEmpty($links); - - $this->assertTrue($tl->remove($links[0]['id'])); - - $links = $tl->getAll(1); - $this->assertEmpty($links); - $links = $tl->getAll(2); - $this->assertEmpty($links); - } -} -- cgit v1.2.3 From b48c0cecbb1f687641594430260a67938d870cbb Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 11:57:28 -0400 Subject: Added new arguments to project API calls and update composer.json --- ChangeLog | 1 + app/Api/Procedure/BaseProcedure.php | 1 - app/Api/Procedure/ProjectProcedure.php | 6 +- app/Validator/ProjectValidator.php | 8 +- composer.json | 31 +-- composer.lock | 297 +++++++------------------ doc/api-project-procedures.markdown | 2 +- doc/requirements.markdown | 2 +- tests/integration/ProjectProcedureTest.php | 29 +++ tests/units/Validator/ProjectValidatorTest.php | 12 +- 10 files changed, 143 insertions(+), 246 deletions(-) (limited to 'doc') diff --git a/ChangeLog b/ChangeLog index 42af8ee3..550a7ada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ New features: Improvements: +* Added argument owner_id and identifier to project API calls * Rewrite integration tests to run with Docker containers * Use the same task form layout everywhere * Remove some tasks dropdown menus that are now available with task edit form diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php index 0aa43428..e31b3027 100644 --- a/app/Api/Procedure/BaseProcedure.php +++ b/app/Api/Procedure/BaseProcedure.php @@ -2,7 +2,6 @@ namespace Kanboard\Api\Procedure; -use JsonRPC\Exception\AccessDeniedException; use Kanboard\Api\Authorization\ProcedureAuthorization; use Kanboard\Api\Authorization\UserAuthorization; use Kanboard\Core\Base; diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php index 9187f221..fe6b63e2 100644 --- a/app/Api/Procedure/ProjectProcedure.php +++ b/app/Api/Procedure/ProjectProcedure.php @@ -78,17 +78,17 @@ class ProjectProcedure extends BaseProcedure public function createProject($name, $description = null, $owner_id = 0, $identifier = null) { - $values = array( + $values = $this->filterValues(array( 'name' => $name, 'description' => $description, 'identifier' => $identifier, - ); + )); list($valid, ) = $this->projectValidator->validateCreation($values); return $valid ? $this->projectModel->create($values, $owner_id, $this->userSession->isLogged()) : false; } - public function updateProject($project_id, $name, $description = null, $owner_id = null, $identifier = null) + public function updateProject($project_id, $name = null, $description = null, $owner_id = null, $identifier = null) { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateProject', $project_id); diff --git a/app/Validator/ProjectValidator.php b/app/Validator/ProjectValidator.php index 9ef59111..8c6117a4 100644 --- a/app/Validator/ProjectValidator.php +++ b/app/Validator/ProjectValidator.php @@ -28,7 +28,7 @@ class ProjectValidator extends BaseValidator new Validators\Integer('priority_start', t('This value must be an integer')), new Validators\Integer('priority_end', t('This value must be an integer')), new Validators\Integer('is_active', t('This value must be an integer')), - new Validators\Required('name', t('The project name is required')), + new Validators\NotEmpty('name', t('This field cannot be empty')), new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('identifier', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('start_date', t('The maximum length is %d characters', 10), 10), @@ -47,11 +47,15 @@ class ProjectValidator extends BaseValidator */ public function validateCreation(array $values) { + $rules = array( + new Validators\Required('name', t('The project name is required')), + ); + if (! empty($values['identifier'])) { $values['identifier'] = strtoupper($values['identifier']); } - $v = new Validator($values, $this->commonValidationRules()); + $v = new Validator($values, array_merge($this->commonValidationRules(), $rules)); return array( $v->execute(), diff --git a/composer.json b/composer.json index bcac020e..d82f3f0c 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "discard-changes": true }, "require" : { - "php" : ">=5.3.3", + "php" : ">=5.3.9", "ext-gd" : "*", "ext-mbstring" : "*", "ext-hash" : "*", @@ -23,21 +23,21 @@ "ext-ctype" : "*", "ext-filter" : "*", "ext-session" : "*", - "christian-riesen/otp" : "1.4", - "eluceo/ical": "0.8.0", + "christian-riesen/otp" : "1.4.3", + "eluceo/ical": "0.10.1", "erusev/parsedown" : "1.6.0", "fguillot/json-rpc" : "1.2.1", "fguillot/picodb" : "1.0.12", "fguillot/simpleLogger" : "1.0.1", - "fguillot/simple-validator" : "1.0.0", + "fguillot/simple-validator" : "1.0.1", "fguillot/simple-queue" : "1.0.1", - "paragonie/random_compat": "@stable", - "pimple/pimple" : "~3.0", - "ramsey/array_column": "@stable", - "swiftmailer/swiftmailer" : "~5.4", - "symfony/console" : "~2.7", - "symfony/event-dispatcher" : "~2.7", - "gregwar/captcha": "1.*" + "paragonie/random_compat": "2.0.2", + "pimple/pimple" : "3.0.2", + "ramsey/array_column": "1.1.3", + "swiftmailer/swiftmailer" : "5.4.2", + "symfony/console" : "2.8.7", + "symfony/event-dispatcher" : "2.7.14", + "gregwar/captcha": "1.1.1" }, "autoload" : { "classmap" : ["app/"], @@ -50,9 +50,10 @@ ] }, "require-dev" : { - "symfony/yaml" : "2.1", - "symfony/stopwatch" : "~2.6", - "phpunit/phpunit" : "4.8.*", - "phpunit/phpunit-selenium": "^2.0" + "phpdocumentor/reflection-docblock": "2.0.4", + "symfony/yaml": "2.8.7", + "symfony/stopwatch" : "2.6.13", + "phpunit/phpunit" : "4.8.26", + "phpunit/phpunit-selenium": "2.0.2" } } diff --git a/composer.lock b/composer.lock index e6a72582..03c5e523 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "283af0b856598f5bc3d8ee0b226959e5", - "content-hash": "18c0bbff5406ceb8b567d9655de26746", + "hash": "ab5b2c960b3a6d9f93883606269085e0", + "content-hash": "bd5f17c3382d7f85e33a68023927704c", "packages": [ { "name": "christian-riesen/base32", @@ -63,22 +63,25 @@ }, { "name": "christian-riesen/otp", - "version": "1.4", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/ChristianRiesen/otp.git", - "reference": "a209b8bbd975d96d6b5287f8658562061adef1f8" + "reference": "20a539ce6280eb029030f4e7caefd5709a75e1ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristianRiesen/otp/zipball/a209b8bbd975d96d6b5287f8658562061adef1f8", - "reference": "a209b8bbd975d96d6b5287f8658562061adef1f8", + "url": "https://api.github.com/repos/ChristianRiesen/otp/zipball/20a539ce6280eb029030f4e7caefd5709a75e1ad", + "reference": "20a539ce6280eb029030f4e7caefd5709a75e1ad", "shasum": "" }, "require": { "christian-riesen/base32": ">=1.0", "php": ">=5.3.0" }, + "suggest": { + "paragonie/random_compat": "Optional polyfill for a more secure random generator for pre PHP7 versions" + }, "type": "library", "autoload": { "psr-0": { @@ -107,20 +110,20 @@ "rfc6238", "totp" ], - "time": "2015-02-12 09:11:49" + "time": "2015-10-08 08:17:59" }, { "name": "eluceo/ical", - "version": "0.8.0", + "version": "0.10.1", "source": { "type": "git", "url": "https://github.com/markuspoerschke/iCal.git", - "reference": "a291711851d1538e2726ffe95862aa5e340ddb9a" + "reference": "2dd99c12c0aa961c541380ab0c113135e14af33e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/markuspoerschke/iCal/zipball/a291711851d1538e2726ffe95862aa5e340ddb9a", - "reference": "a291711851d1538e2726ffe95862aa5e340ddb9a", + "url": "https://api.github.com/repos/markuspoerschke/iCal/zipball/2dd99c12c0aa961c541380ab0c113135e14af33e", + "reference": "2dd99c12c0aa961c541380ab0c113135e14af33e", "shasum": "" }, "require": { @@ -160,7 +163,7 @@ "ics", "php calendar" ], - "time": "2015-07-12 18:19:30" + "time": "2016-06-09 09:08:55" }, { "name": "erusev/parsedown", @@ -331,16 +334,16 @@ }, { "name": "fguillot/simple-validator", - "version": "1.0.0", + "version": "v1.0.1", "source": { "type": "git", "url": "https://github.com/fguillot/simpleValidator.git", - "reference": "9579993f3dd0f03053b28fec1e7b9990edc3947b" + "reference": "23b0a99c5f11ad74d05f8845feaafbcfd9223eda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/9579993f3dd0f03053b28fec1e7b9990edc3947b", - "reference": "9579993f3dd0f03053b28fec1e7b9990edc3947b", + "url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/23b0a99c5f11ad74d05f8845feaafbcfd9223eda", + "reference": "23b0a99c5f11ad74d05f8845feaafbcfd9223eda", "shasum": "" }, "require": { @@ -363,7 +366,7 @@ ], "description": "Simple validator library", "homepage": "https://github.com/fguillot/simpleValidator", - "time": "2015-08-29 00:44:37" + "time": "2016-06-26 15:09:26" }, { "name": "fguillot/simpleLogger", @@ -742,16 +745,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.7", + "version": "v2.7.14", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110" + "reference": "d3e09ed1224503791f31b913d22196f65f9afed5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2a6b8713f8bdb582058cfda463527f195b066110", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d3e09ed1224503791f31b913d22196f65f9afed5", + "reference": "d3e09ed1224503791f31b913d22196f65f9afed5", "shasum": "" }, "require": { @@ -759,10 +762,10 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5|~3.0.0", - "symfony/dependency-injection": "~2.6|~3.0.0", - "symfony/expression-language": "~2.6|~3.0.0", - "symfony/stopwatch": "~2.3|~3.0.0" + "symfony/config": "~2.0,>=2.0.5", + "symfony/dependency-injection": "~2.6", + "symfony/expression-language": "~2.6", + "symfony/stopwatch": "~2.3" }, "suggest": { "symfony/dependency-injection": "", @@ -771,7 +774,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8-dev" + "dev-master": "2.7-dev" } }, "autoload": { @@ -798,7 +801,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2016-06-06 11:03:51" }, { "name": "symfony/polyfill-mbstring", @@ -915,136 +918,39 @@ ], "time": "2015-06-14 21:17:01" }, - { - "name": "phpdocumentor/reflection-common", - "version": "1.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "shasum": "" - }, - "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "time": "2015-12-27 11:43:31" - }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.0", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.2.0", - "webmozart/assert": "^1.0" + "php": ">=5.3.3" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-06-10 09:48:41" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "0.2", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0" + "phpunit/phpunit": "~4.0" }, - "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ + "psr-0": { + "phpDocumentor": [ "src/" ] } @@ -1056,10 +962,10 @@ "authors": [ { "name": "Mike van Riel", - "email": "me@mikevanriel.com" + "email": "mike.vanriel@naenius.com" } ], - "time": "2016-06-10 07:14:17" + "time": "2015-02-03 12:10:50" }, { "name": "phpspec/prophecy", @@ -1932,34 +1838,35 @@ }, { "name": "symfony/stopwatch", - "version": "v2.8.7", + "version": "v2.6.13", + "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "5e628055488bcc42dbace3af65be435d094e37e4" + "reference": "a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5e628055488bcc42dbace3af65be435d094e37e4", - "reference": "5e628055488bcc42dbace3af65be435d094e37e4", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987", + "reference": "a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8-dev" + "dev-master": "2.6-dev" } }, "autoload": { - "psr-4": { + "psr-0": { "Symfony\\Component\\Stopwatch\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1977,115 +1884,65 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2015-07-01 18:23:01" }, { "name": "symfony/yaml", - "version": "v2.1.0", - "target-dir": "Symfony/Component/Yaml", + "version": "v2.8.7", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715" + "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f18e004fc975707bb4695df1dbbe9b0d8c8b7715", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715", + "url": "https://api.github.com/repos/symfony/yaml/zipball/815fabf3f48c7d1df345a69d1ad1a88f59757b34", + "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "2.8-dev" } }, "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml": "" - } + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2012-08-22 13:48:41" - }, - { - "name": "webmozart/assert", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ + }, { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2015-08-24 13:29:44" + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-06-06 11:11:27" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "paragonie/random_compat": 0, - "ramsey/array_column": 0 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3", + "php": ">=5.3.9", "ext-gd": "*", "ext-mbstring": "*", "ext-hash": "*", diff --git a/doc/api-project-procedures.markdown b/doc/api-project-procedures.markdown index 3f8d33c2..d375852c 100644 --- a/doc/api-project-procedures.markdown +++ b/doc/api-project-procedures.markdown @@ -186,7 +186,7 @@ Response example: - Purpose: **Update a project** - Parameters: - **project_id** (integer, required) - - **name** (string, required) + - **name** (string, optional) - **description** (string, optional) - **owner_id** (integer, optional) - **identifier** (string, optional) diff --git a/doc/requirements.markdown b/doc/requirements.markdown index 9943465a..f6c9b309 100644 --- a/doc/requirements.markdown +++ b/doc/requirements.markdown @@ -51,7 +51,7 @@ Kanboard is pre-configured to work with Apache (URL rewriting). | PHP Version | |----------------| -| PHP >= 5.3.3 | +| PHP >= 5.3.9 | | PHP 5.4 | | PHP 5.5 | | PHP 5.6 | diff --git a/tests/integration/ProjectProcedureTest.php b/tests/integration/ProjectProcedureTest.php index 1ebd48ae..a4b65241 100644 --- a/tests/integration/ProjectProcedureTest.php +++ b/tests/integration/ProjectProcedureTest.php @@ -13,6 +13,8 @@ class ProjectProcedureTest extends BaseProcedureTest $this->assertGetProjectByName(); $this->assertGetAllProjects(); $this->assertUpdateProject(); + $this->assertUpdateProjectIdentifier(); + $this->assertCreateProjectWithIdentifier(); $this->assertGetProjectActivity(); $this->assertGetProjectsActivity(); $this->assertEnableDisableProject(); @@ -69,6 +71,33 @@ class ProjectProcedureTest extends BaseProcedureTest $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => $this->projectName))); } + public function assertUpdateProjectIdentifier() + { + $this->assertTrue($this->app->updateProject(array( + 'project_id' => $this->projectId, + 'identifier' => 'MYPROJECT', + ))); + + $project = $this->app->getProjectById($this->projectId); + $this->assertNotNull($project); + $this->assertEquals($this->projectName, $project['name']); + $this->assertEquals('MYPROJECT', $project['identifier']); + } + + public function assertCreateProjectWithIdentifier() + { + $projectId = $this->app->createProject(array( + 'name' => 'My project with an identifier', + 'identifier' => 'MYPROJECTWITHIDENTIFIER', + )); + + $this->assertNotFalse($projectId); + + $project = $this->app->getProjectById($projectId); + $this->assertEquals('My project with an identifier', $project['name']); + $this->assertEquals('MYPROJECTWITHIDENTIFIER', $project['identifier']); + } + public function assertEnableDisableProject() { $this->assertTrue($this->app->disableProject($this->projectId)); diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php index 07de6c25..e1e2f077 100644 --- a/tests/units/Validator/ProjectValidatorTest.php +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -55,13 +55,19 @@ class ProjectValidatorTest extends Base $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => '')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => '')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => null)); $this->assertFalse($r[0]); } } -- cgit v1.2.3