Improve API to return id instead of a boolean

This commit is contained in:
Frédéric Guillot 2014-11-22 18:22:10 -05:00
parent 15038cdb10
commit 77e10d2582
13 changed files with 270 additions and 310 deletions

View File

@ -94,11 +94,18 @@ class Category extends Base
* *
* @access public * @access public
* @param array $values Form values * @param array $values Form values
* @return bool * @return bool|integer
*/ */
public function create(array $values) public function create(array $values)
{ {
return $this->db->table(self::TABLE)->save($values); return $this->db->transaction(function($db) use ($values) {
if (! $db->table(Category::TABLE)->save($values)) {
return false;
}
return (int) $db->getConnection()->getLastId();
});
} }
/** /**

View File

@ -99,20 +99,25 @@ class Comment extends Base
* *
* @access public * @access public
* @param array $values Form values * @param array $values Form values
* @return boolean * @return boolean|integer
*/ */
public function create(array $values) public function create(array $values)
{ {
$values['date'] = time(); $values['date'] = time();
if ($this->db->table(self::TABLE)->save($values)) { return $this->db->transaction(function($db) use ($values) {
if (! $db->table(Comment::TABLE)->save($values)) {
return false;
}
$comment_id = (int) $db->getConnection()->getLastId();
$values['id'] = $comment_id;
$values['id'] = $this->db->getConnection()->getLastId();
$this->event->trigger(self::EVENT_CREATE, $values); $this->event->trigger(self::EVENT_CREATE, $values);
return true;
}
return false; return $comment_id;
});
} }
/** /**

View File

@ -138,19 +138,25 @@ class SubTask extends Base
* *
* @access public * @access public
* @param array $values Form values * @param array $values Form values
* @return bool * @return bool|integer
*/ */
public function create(array $values) public function create(array $values)
{ {
$this->prepare($values); $this->prepare($values);
$result = $this->db->table(self::TABLE)->save($values);
if ($result) { return $this->db->transaction(function($db) use ($values) {
$values['id'] = $this->db->getConnection()->getLastId();
if (! $db->table(SubTask::TABLE)->save($values)) {
return false;
}
$subtask_id = (int) $db->getConnection()->getLastId();
$values['id'] = $subtask_id;
$this->event->trigger(self::EVENT_CREATE, $values); $this->event->trigger(self::EVENT_CREATE, $values);
}
return $result; return $subtask_id;
});
} }
/** /**

View File

@ -255,12 +255,20 @@ class User extends Base
* *
* @access public * @access public
* @param array $values Form values * @param array $values Form values
* @return boolean * @return boolean|integer
*/ */
public function create(array $values) public function create(array $values)
{ {
$this->prepare($values); $this->prepare($values);
return $this->db->table(self::TABLE)->save($values);
return $this->db->transaction(function($db) use ($values) {
if (! $db->table(User::TABLE)->save($values)) {
return false;
}
return (int) $db->getConnection()->getLastId();
});
} }
/** /**

16
composer.lock generated
View File

@ -51,12 +51,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fguillot/JsonRPC.git", "url": "https://github.com/fguillot/JsonRPC.git",
"reference": "66db4093984790c34577c0ba0e17f2e3d2dc14a0" "reference": "86e8339205616ad9b09d581957cc084a99c0ed27"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/66db4093984790c34577c0ba0e17f2e3d2dc14a0", "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/86e8339205616ad9b09d581957cc084a99c0ed27",
"reference": "66db4093984790c34577c0ba0e17f2e3d2dc14a0", "reference": "86e8339205616ad9b09d581957cc084a99c0ed27",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -80,7 +80,7 @@
], ],
"description": "A simple Json-RPC client/server library that just works", "description": "A simple Json-RPC client/server library that just works",
"homepage": "https://github.com/fguillot/JsonRPC", "homepage": "https://github.com/fguillot/JsonRPC",
"time": "2014-11-05 01:56:31" "time": "2014-11-22 20:32:14"
}, },
{ {
"name": "fguillot/picodb", "name": "fguillot/picodb",
@ -88,12 +88,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fguillot/picoDb.git", "url": "https://github.com/fguillot/picoDb.git",
"reference": "48602866414b5b396a37c40eef9724962042ff21" "reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/fguillot/picoDb/zipball/48602866414b5b396a37c40eef9724962042ff21", "url": "https://api.github.com/repos/fguillot/picoDb/zipball/ebe721de0002b7ff86b7f66df0065224bf896eb2",
"reference": "48602866414b5b396a37c40eef9724962042ff21", "reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -117,7 +117,7 @@
], ],
"description": "Minimalist database query builder", "description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb", "homepage": "https://github.com/fguillot/picoDb",
"time": "2014-11-15 23:37:30" "time": "2014-11-22 04:15:43"
}, },
{ {
"name": "fguillot/simple-validator", "name": "fguillot/simple-validator",

View File

@ -149,7 +149,7 @@ Procedures
- Purpose: **Create a new project** - Purpose: **Create a new project**
- Parameters: - Parameters:
- **name** (string, required) - **name** (string, required)
- Result on success: **true** - Result on success: **project_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -171,7 +171,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 1797076613, "id": 1797076613,
"result": true "result": 2
} }
``` ```
@ -487,10 +487,9 @@ Response example:
} }
``` ```
### getAllowedUsers ### getMembers
- Purpose: **Get allowed users for a given project** - Purpose: **Get members of a project**
- Note: Only people explicitly allowed are part of this list, administrators are always authorized
- Parameters: - Parameters:
- **project_id** (integer, required) - **project_id** (integer, required)
- Result on success: Key/value pair of user_id and username - Result on success: Key/value pair of user_id and username
@ -943,7 +942,7 @@ Response example:
- **score** (integer, optional) - **score** (integer, optional)
- **date_due**: ISO8601 format (string, optional) - **date_due**: ISO8601 format (string, optional)
- **category_id** (integer, optional) - **category_id** (integer, optional)
- Result on success: **true** - Result on success: **task_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -974,7 +973,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 1176509098, "id": 1176509098,
"result": true "result": 3
} }
``` ```
@ -1279,7 +1278,7 @@ Response example:
- **email** (string, optional) - **email** (string, optional)
- **is_admin** Set the value 1 for admins or 0 for regular users (integer, optional) - **is_admin** Set the value 1 for admins or 0 for regular users (integer, optional)
- **default_project_id** (integer, optional) - **default_project_id** (integer, optional)
- Result on success: **true** - Result on success: **user_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -1302,7 +1301,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 1518863034, "id": 1518863034,
"result": true "result": 22
} }
``` ```
@ -1466,7 +1465,7 @@ Response example:
- Parameters: - Parameters:
- **project_id** (integer, required) - **project_id** (integer, required)
- **name** (string, required, must be unique for the given project) - **name** (string, required, must be unique for the given project)
- Result on success: **true** - Result on success: **category_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -1489,7 +1488,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 541909890, "id": 541909890,
"result": true "result": 4
} }
``` ```
@ -1638,7 +1637,7 @@ Response example:
- **task_id** (integer, required) - **task_id** (integer, required)
- **user_id** (integer, required) - **user_id** (integer, required)
- **content** Markdown content (string, required) - **content** Markdown content (string, required)
- Result on success: **true** - Result on success: **comment_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -1662,7 +1661,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 1580417921, "id": 1580417921,
"result": true "result": 11
} }
``` ```
@ -1822,7 +1821,7 @@ Response example:
- **time_estimated** (int, optional) - **time_estimated** (int, optional)
- **time_spent** (int, optional) - **time_spent** (int, optional)
- **status** (int, optional) - **status** (int, optional)
- Result on success: **true** - Result on success: **subtask_id**
- Result on failure: **false** - Result on failure: **false**
Request example: Request example:
@ -1845,7 +1844,7 @@ Response example:
{ {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 2041554661, "id": 2041554661,
"result": true "result": 45
} }
``` ```

View File

@ -2,74 +2,67 @@
require __DIR__.'/app/common.php'; require __DIR__.'/app/common.php';
use JsonRPC\Server; $models = array(
use Model\Project; 'Config',
use Model\ProjectPermission; 'Project',
use Model\Task; 'ProjectPermission',
use Model\TaskCreation; 'Task',
use Model\TaskFinder; 'TaskCreation',
use Model\TaskStatus; 'TaskFinder',
use Model\TaskValidator; 'TaskStatus',
use Model\User; 'TaskValidator',
use Model\Config; 'User',
use Model\Category; 'Category',
use Model\Comment; 'Comment',
use Model\SubTask; 'SubTask',
use Model\Board; 'Board',
use Model\Action; 'Action',
use Model\Webhook; 'Webhook',
use Model\Notification; 'Notification',
);
$config = new Config($container); $events = array(
$config->setupTranslations(); 'actionModel',
$config->setupTimezone(); 'projectModel',
'webhookModel',
'notificationModel',
);
$project = new Project($container); foreach ($models as $model) {
$projectPermission = new ProjectPermission($container); $variable = lcfirst($model).'Model';
$task = new Task($container); $class = '\Model\\'.$model;
$taskCreation = new TaskCreation($container); $$variable = new $class($container);
$taskFinder = new TaskFinder($container); }
$taskStatus = new TaskStatus($container);
$taskValidator = new TaskValidator($container);
$user = new User($container);
$category = new Category($container);
$comment = new Comment($container);
$subtask = new SubTask($container);
$board = new Board($container);
$action = new Action($container);
$webhook = new Webhook($container);
$notification = new Notification($container);
$action->attachEvents(); foreach ($events as $class) {
$project->attachEvents(); $$class->attachEvents();
$webhook->attachEvents(); }
$notification->attachEvents();
$server = new Server; $configModel->setupTranslations();
$server->authentication(array('jsonrpc' => $config->get('api_token'))); $configModel->setupTimezone();
$server = new JsonRPC\Server;
$server->authentication(array('jsonrpc' => $configModel->get('api_token')));
/** /**
* Project procedures * Project procedures
*/ */
$server->register('createProject', function($name) use ($project) { $server->bind('getProjectById', $projectModel, 'getById');
$server->bind('getProjectByName', $projectModel, 'getByName');
$server->bind('getAllProjects', $projectModel, 'getAll');
$server->bind('removeProject', $projectModel, 'remove');
$server->bind('enableProject', $projectModel, 'enable');
$server->bind('disableProject', $projectModel, 'disable');
$server->bind('enableProjectPublicAccess', $projectModel, 'enablePublicAccess');
$server->bind('disableProjectPublicAccess', $projectModel, 'disablePublicAccess');
$server->register('createProject', function($name) use ($projectModel) {
$values = array('name' => $name); $values = array('name' => $name);
list($valid,) = $project->validateCreation($values); list($valid,) = $projectModel->validateCreation($values);
return $valid && $project->create($values); return $valid && $projectModel->create($values);
}); });
$server->register('getProjectById', function($project_id) use ($project) { $server->register('updateProject', function($id, $name, $is_active = null, $is_public = null, $token = null) use ($projectModel) {
return $project->getById($project_id);
});
$server->register('getProjectByName', function($name) use ($project) {
return $project->getByName($name);
});
$server->register('getAllProjects', function() use ($project) {
return $project->getAll();
});
$server->register('updateProject', function($id, $name, $is_active = null, $is_public = null, $token = null) use ($project) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
@ -85,87 +78,40 @@ $server->register('updateProject', function($id, $name, $is_active = null, $is_p
} }
} }
list($valid,) = $project->validateModification($values); list($valid,) = $projectModel->validateModification($values);
return $valid && $project->update($values); return $valid && $projectModel->update($values);
}); });
$server->register('removeProject', function($project_id) use ($project) {
return $project->remove($project_id);
});
$server->register('enableProject', function($project_id) use ($project) {
return $project->enable($project_id);
});
$server->register('disableProject', function($project_id) use ($project) {
return $project->disable($project_id);
});
$server->register('enableProjectPublicAccess', function($project_id) use ($project) {
return $project->enablePublicAccess($project_id);
});
$server->register('disableProjectPublicAccess', function($project_id) use ($project) {
return $project->disablePublicAccess($project_id);
});
/** /**
* Board procedures * Board procedures
*/ */
$server->register('getBoard', function($project_id) use ($board) { $server->bind('getBoard', $boardModel, 'get');
return $board->get($project_id); $server->bind('getColumns', $boardModel, 'getColumns');
}); $server->bind('getColumn', $boardModel, 'getColumn');
$server->bind('moveColumnUp', $boardModel, 'moveUp');
$server->register('getColumns', function($project_id) use ($board) { $server->bind('moveColumnDown', $boardModel, 'moveDown');
return $board->getColumns($project_id); $server->bind('updateColumn', $boardModel, 'updateColumn');
}); $server->bind('addColumn', $boardModel, 'addColumn');
$server->bind('removeColumn', $boardModel, 'removeColumn');
$server->register('getColumn', function($column_id) use ($board) {
return $board->getColumn($column_id);
});
$server->register('moveColumnUp', function($project_id, $column_id) use ($board) {
return $board->moveUp($project_id, $column_id);
});
$server->register('moveColumnDown', function($project_id, $column_id) use ($board) {
return $board->moveDown($project_id, $column_id);
});
$server->register('updateColumn', function($column_id, $title, $task_limit = 0) use ($board) {
return $board->updateColumn($column_id, $title, $task_limit);
});
$server->register('addColumn', function($project_id, $title, $task_limit = 0) use ($board) {
return $board->addColumn($project_id, $title, $task_limit);
});
$server->register('removeColumn', function($column_id) use ($board) {
return $board->removeColumn($column_id);
});
/** /**
* Project permissions procedures * Project permissions procedures
*/ */
$server->register('getAllowedUsers', function($project_id) use ($projectPermission) { $server->bind('getMembers', $projectPermissionModel, 'getMembers');
return $projectPermission->getMemberList($project_id, false, false); $server->bind('revokeUser', $projectPermissionModel, 'revokeUser');
}); $server->bind('allowUser', $projectPermissionModel, 'allowUser');
$server->register('revokeUser', function($project_id, $user_id) use ($project, $projectPermission) {
return $projectPermission->revokeUser($project_id, $user_id);
});
$server->register('allowUser', function($project_id, $user_id) use ($project, $projectPermission) {
return $projectPermission->allowUser($project_id, $user_id);
});
/** /**
* Task procedures * Task procedures
*/ */
$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($taskCreation, $taskValidator) { $server->bind('getTask', $taskFinderModel, 'getById');
$server->bind('getAllTasks', $taskFinderModel, 'getAll');
$server->bind('openTask', $taskStatusModel, 'open');
$server->bind('closeTask', $taskStatusModel, 'close');
$server->bind('removeTask', $taskModel, 'remove');
$server->bind('moveTaskPosition', $taskModel, 'movePosition');
$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($taskCreationModel, $taskValidatorModel) {
$values = array( $values = array(
'title' => $title, 'title' => $title,
@ -180,19 +126,16 @@ $server->register('createTask', function($title, $project_id, $color_id = '', $c
'score' => $score, 'score' => $score,
); );
list($valid,) = $taskValidator->validateCreation($values); list($valid,) = $taskValidatorModel->validateCreation($values);
return $valid && $taskCreation->create($values) !== false;
if (! $valid) {
return false;
}
return $taskCreationModel->create($values);
}); });
$server->register('getTask', function($task_id) use ($taskFinder) { $server->register('updateTask', function($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null, $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null) use ($taskModel, $taskValidatorModel) {
return $taskFinder->getById($task_id);
});
$server->register('getAllTasks', function($project_id, $status) use ($taskFinder) {
return $taskFinder->getAll($project_id, $status);
});
$server->register('updateTask', function($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null, $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null) use ($task, $taskValidator) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
@ -214,31 +157,19 @@ $server->register('updateTask', function($id, $title = null, $project_id = null,
} }
} }
list($valid) = $taskValidator->validateApiModification($values); list($valid) = $taskValidatorModel->validateApiModification($values);
return $valid && $task->update($values); return $valid && $taskModel->update($values);
});
$server->register('openTask', function($task_id) use ($taskStatus) {
return $taskStatus->open($task_id);
});
$server->register('closeTask', function($task_id) use ($taskStatus) {
return $taskStatus->close($task_id);
});
$server->register('removeTask', function($task_id) use ($task) {
return $task->remove($task_id);
});
$server->register('moveTaskPosition', function($project_id, $task_id, $column_id, $position) use ($task) {
return $task->movePosition($project_id, $task_id, $column_id, $position);
}); });
/** /**
* User procedures * User procedures
*/ */
$server->register('createUser', function($username, $password, $name = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($user) { $server->bind('getUser', $userModel, 'getById');
$server->bind('getAllUsers', $userModel, 'getAll');
$server->bind('removeUser', $userModel, 'remove');
$server->register('createUser', function($username, $password, $name = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($userModel) {
$values = array( $values = array(
'username' => $username, 'username' => $username,
@ -250,19 +181,16 @@ $server->register('createUser', function($username, $password, $name = '', $emai
'default_project_id' => $default_project_id, 'default_project_id' => $default_project_id,
); );
list($valid,) = $user->validateCreation($values); list($valid,) = $userModel->validateCreation($values);
return $valid && $user->create($values);
if (! $valid) {
return false;
}
return $userModel->create($values);
}); });
$server->register('getUser', function($user_id) use ($user) { $server->register('updateUser', function($id, $username = null, $name = null, $email = null, $is_admin = null, $default_project_id = null) use ($userModel) {
return $user->getById($user_id);
});
$server->register('getAllUsers', function() use ($user) {
return $user->getAll();
});
$server->register('updateUser', function($id, $username = null, $name = null, $email = null, $is_admin = null, $default_project_id = null) use ($user) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
@ -279,57 +207,52 @@ $server->register('updateUser', function($id, $username = null, $name = null, $e
} }
} }
list($valid,) = $user->validateApiModification($values); list($valid,) = $userModel->validateApiModification($values);
return $valid && $user->update($values); return $valid && $userModel->update($values);
}); });
$server->register('removeUser', function($user_id) use ($user) {
return $user->remove($user_id);
});
/** /**
* Category procedures * Category procedures
*/ */
$server->register('createCategory', function($project_id, $name) use ($category) { $server->bind('getCategory', $categoryModel, 'getById');
$server->bind('getAllCategories', $categoryModel, 'getAll');
$server->bind('removeCategory', $categoryModel, 'remove');
$server->register('createCategory', function($project_id, $name) use ($categoryModel) {
$values = array( $values = array(
'project_id' => $project_id, 'project_id' => $project_id,
'name' => $name, 'name' => $name,
); );
list($valid,) = $category->validateCreation($values); list($valid,) = $categoryModel->validateCreation($values);
return $valid && $category->create($values);
if (! $valid) {
return false;
}
return $categoryModel->create($values);
}); });
$server->register('getCategory', function($category_id) use ($category) { $server->register('updateCategory', function($id, $name) use ($categoryModel) {
return $category->getById($category_id);
});
$server->register('getAllCategories', function($project_id) use ($category) {
return $category->getAll($project_id);
});
$server->register('updateCategory', function($id, $name) use ($category) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
'name' => $name, 'name' => $name,
); );
list($valid,) = $category->validateModification($values); list($valid,) = $categoryModel->validateModification($values);
return $valid && $category->update($values); return $valid && $categoryModel->update($values);
}); });
$server->register('removeCategory', function($category_id) use ($category) {
return $category->remove($category_id);
});
/** /**
* Comments procedures * Comments procedures
*/ */
$server->register('createComment', function($task_id, $user_id, $content) use ($comment) { $server->bind('getComment', $commentModel, 'getById');
$server->bind('getAllComments', $commentModel, 'getAll');
$server->bind('removeComment', $commentModel, 'remove');
$server->register('createComment', function($task_id, $user_id, $content) use ($commentModel) {
$values = array( $values = array(
'task_id' => $task_id, 'task_id' => $task_id,
@ -337,38 +260,34 @@ $server->register('createComment', function($task_id, $user_id, $content) use ($
'comment' => $content, 'comment' => $content,
); );
list($valid,) = $comment->validateCreation($values); list($valid,) = $commentModel->validateCreation($values);
return $valid && $comment->create($values);
if (! $valid) {
return false;
}
return $commentModel->create($values);
}); });
$server->register('getComment', function($comment_id) use ($comment) { $server->register('updateComment', function($id, $content) use ($commentModel) {
return $comment->getById($comment_id);
});
$server->register('getAllComments', function($task_id) use ($comment) {
return $comment->getAll($task_id);
});
$server->register('updateComment', function($id, $content) use ($comment) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
'comment' => $content, 'comment' => $content,
); );
list($valid,) = $comment->validateModification($values); list($valid,) = $commentModel->validateModification($values);
return $valid && $comment->update($values); return $valid && $commentModel->update($values);
}); });
$server->register('removeComment', function($comment_id) use ($comment) {
return $comment->remove($comment_id);
});
/** /**
* Subtask procedures * Subtask procedures
*/ */
$server->register('createSubtask', function($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) use ($subtask) { $server->bind('getSubtask', $subTaskModel, 'getById');
$server->bind('getAllSubtasks', $subTaskModel, 'getAll');
$server->bind('removeSubtask', $subTaskModel, 'remove');
$server->register('createSubtask', function($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) use ($subTaskModel) {
$values = array( $values = array(
'title' => $title, 'title' => $title,
@ -385,19 +304,16 @@ $server->register('createSubtask', function($task_id, $title, $user_id = 0, $tim
} }
} }
list($valid,) = $subtask->validateCreation($values); list($valid,) = $subTaskModel->validateCreation($values);
return $valid && $subtask->create($values);
if (! $valid) {
return false;
}
return $subTaskModel->create($values);
}); });
$server->register('getSubtask', function($subtask_id) use ($subtask) { $server->register('updateSubtask', function($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) use ($subTaskModel) {
return $subtask->getById($subtask_id);
});
$server->register('getAllSubtasks', function($task_id) use ($subtask) {
return $subtask->getAll($task_id);
});
$server->register('updateSubtask', function($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) use ($subtask) {
$values = array( $values = array(
'id' => $id, 'id' => $id,
@ -415,15 +331,10 @@ $server->register('updateSubtask', function($id, $task_id, $title = null, $user_
} }
} }
list($valid,) = $subtask->validateModification($values); list($valid,) = $subTaskModel->validateModification($values);
return $valid && $subtask->update($values); return $valid && $subTaskModel->update($values);
}); });
$server->register('removeSubtask', function($subtask_id) use ($subtask) {
return $subtask->remove($subtask_id);
});
/** /**
* Parse incoming requests * Parse incoming requests
*/ */

View File

@ -162,12 +162,15 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 2, 'column_id' => 2,
); );
//$this->assertTrue($this->client->execute('createTask', $task)); $task_id = $this->client->createTask($task);
$this->assertTrue($this->client->createTask($task));
$this->assertNotFalse($task_id);
$this->assertInternalType('int', $task_id);
$this->assertTrue($task_id > 0);
} }
/** /**
* @expectedException BadFunctionCallException * @expectedException InvalidArgumentException
*/ */
public function testCreateTaskWithBadParams() public function testCreateTaskWithBadParams()
{ {
@ -207,12 +210,15 @@ class Api extends PHPUnit_Framework_TestCase
public function testUpdateTask() public function testUpdateTask()
{ {
$task = $this->client->getTask(1); $task = $this->client->getTask(1);
$task['color_id'] = 'green';
$task['column_id'] = 1;
$task['description'] = 'test';
$task['date_due'] = '';
$this->assertTrue($this->client->execute('updateTask', $task)); $values = array();
$values['id'] = $task['id'];
$values['color_id'] = 'green';
$values['column_id'] = 1;
$values['description'] = 'test';
$values['date_due'] = '';
$this->assertTrue($this->client->execute('updateTask', $values));
} }
public function testRemoveTask() public function testRemoveTask()
@ -241,11 +247,14 @@ class Api extends PHPUnit_Framework_TestCase
'password' => '123456', 'password' => '123456',
); );
$this->assertTrue($this->client->execute('createUser', $user)); $user_id = $this->client->execute('createUser', $user);
$this->assertNotFalse($user_id);
$this->assertInternalType('int', $user_id);
$this->assertTrue($user_id > 0);
} }
/** /**
* @expectedException BadFunctionCallException * @expectedException InvalidArgumentException
*/ */
public function testCreateUserWithBadParams() public function testCreateUserWithBadParams()
{ {
@ -296,7 +305,7 @@ class Api extends PHPUnit_Framework_TestCase
public function testGetAllowedUsers() public function testGetAllowedUsers()
{ {
$users = $this->client->getAllowedUsers(1); $users = $this->client->getMembers(1);
$this->assertNotFalse($users); $this->assertNotFalse($users);
$this->assertEquals(array(), $users); $this->assertEquals(array(), $users);
} }
@ -305,7 +314,7 @@ class Api extends PHPUnit_Framework_TestCase
{ {
$this->assertTrue($this->client->allowUser(1, 2)); $this->assertTrue($this->client->allowUser(1, 2));
$users = $this->client->getAllowedUsers(1); $users = $this->client->getMembers(1);
$this->assertNotFalse($users); $this->assertNotFalse($users);
$this->assertEquals(array(2 => 'Titi'), $users); $this->assertEquals(array(2 => 'Titi'), $users);
} }
@ -314,7 +323,7 @@ class Api extends PHPUnit_Framework_TestCase
{ {
$this->assertTrue($this->client->revokeUser(1, 2)); $this->assertTrue($this->client->revokeUser(1, 2));
$users = $this->client->getAllowedUsers(1); $users = $this->client->getMembers(1);
$this->assertNotFalse($users); $this->assertNotFalse($users);
$this->assertEquals(array(), $users); $this->assertEquals(array(), $users);
} }
@ -329,7 +338,7 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 1, 'column_id' => 1,
); );
$this->assertTrue($this->client->execute('createTask', $task)); $this->assertNotFalse($this->client->execute('createTask', $task));
$tasks = $this->client->getAllTasks(1, 1); $tasks = $this->client->getAllTasks(1, 1);
$this->assertNotEmpty($tasks); $this->assertNotEmpty($tasks);
@ -341,7 +350,11 @@ class Api extends PHPUnit_Framework_TestCase
'content' => 'boo', 'content' => 'boo',
); );
$this->assertTrue($this->client->execute('createComment', $comment)); $comment_id = $this->client->execute('createComment', $comment);
$this->assertNotFalse($comment_id);
$this->assertInternalType('int', $comment_id);
$this->assertTrue($comment_id > 0);
} }
public function testGetComment() public function testGetComment()
@ -375,7 +388,11 @@ class Api extends PHPUnit_Framework_TestCase
'content' => 'blabla', 'content' => 'blabla',
); );
$this->assertTrue($this->client->execute('createComment', $comment)); $comment_id = $this->client->createComment($comment);
$this->assertNotFalse($comment_id);
$this->assertInternalType('int', $comment_id);
$this->assertTrue($comment_id > 0);
$comments = $this->client->getAllComments($task_id); $comments = $this->client->getAllComments($task_id);
$this->assertNotFalse($comments); $this->assertNotFalse($comments);
@ -410,7 +427,11 @@ class Api extends PHPUnit_Framework_TestCase
'title' => 'subtask #1', 'title' => 'subtask #1',
); );
$this->assertTrue($this->client->execute('createSubtask', $subtask)); $subtask_id = $this->client->createSubtask($subtask);
$this->assertNotFalse($subtask_id);
$this->assertInternalType('int', $subtask_id);
$this->assertTrue($subtask_id > 0);
} }
public function testGetSubtask() public function testGetSubtask()
@ -444,7 +465,7 @@ class Api extends PHPUnit_Framework_TestCase
'title' => 'Subtask #2', 'title' => 'Subtask #2',
); );
$this->assertTrue($this->client->execute('createSubtask', $subtask)); $this->assertNotFalse($this->client->execute('createSubtask', $subtask));
$subtasks = $this->client->getAllSubtasks($this->getTaskId()); $subtasks = $this->client->getAllSubtasks($this->getTaskId());
$this->assertNotFalse($subtasks); $this->assertNotFalse($subtasks);
@ -483,7 +504,10 @@ class Api extends PHPUnit_Framework_TestCase
'project_id' => 1, 'project_id' => 1,
); );
$this->assertTrue($this->client->execute('createCategory', $category)); $cat_id = $this->client->execute('createCategory', $category);
$this->assertNotFalse($cat_id);
$this->assertInternalType('int', $cat_id);
$this->assertTrue($cat_id > 0);
// Duplicate // Duplicate
@ -496,7 +520,7 @@ class Api extends PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException BadFunctionCallException * @expectedException InvalidArgumentException
*/ */
public function testCategoryCreationWithBadParams() public function testCategoryCreationWithBadParams()
{ {

View File

@ -17,7 +17,7 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $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, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1))); $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
$comment = $c->getById(1); $comment = $c->getById(1);
@ -37,9 +37,9 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $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, $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->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
$comments = $c->getAll(1); $comments = $c->getAll(1);
@ -60,7 +60,7 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $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, $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->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla'))); $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
$comment = $c->getById(1); $comment = $c->getById(1);

View File

@ -19,16 +19,16 @@ class NotificationTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
// Email + Notifications enabled // Email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled // No email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled // Email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled // No email + notifications disabled
$this->assertTrue($u->create(array('username' => 'user4'))); $this->assertNotFalse($u->create(array('username' => 'user4')));
// Nobody is member of any projects // Nobody is member of any projects
$this->assertEmpty($pp->getMembers(1)); $this->assertEmpty($pp->getMembers(1));
@ -61,16 +61,16 @@ class NotificationTest extends Base
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 1))); $this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 1)));
// Email + Notifications enabled // Email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled // No email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled // Email + Notifications enabled
$this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled // No email + notifications disabled
$this->assertTrue($u->create(array('username' => 'user4'))); $this->assertNotFalse($u->create(array('username' => 'user4')));
// We allow all users to be member of our projects // We allow all users to be member of our projects
$this->assertTrue($pp->allowUser(1, 1)); $this->assertTrue($pp->allowUser(1, 1));

View File

@ -11,8 +11,8 @@ class ProjectPermissionTest extends Base
public function testAllowEverybody() public function testAllowEverybody()
{ {
$user = new User($this->container); $user = new User($this->container);
$this->assertTrue($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($user->create(array('username' => 'unittest#2', 'password' => 'unittest'))); $this->assertNotFalse($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
$p = new Project($this->container); $p = new Project($this->container);
$pp = new ProjectPermission($this->container); $pp = new ProjectPermission($this->container);

View File

@ -20,8 +20,8 @@ class TaskPermissionTest extends Base
$p = new Project($this->container); $p = new Project($this->container);
$u = new User($this->container); $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456'))); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
$this->assertTrue($u->create(array('username' => 'toto2', 'password' => '123456'))); $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456')));
$this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));

View File

@ -73,8 +73,8 @@ class UserTest extends Base
public function testCreate() public function testCreate()
{ {
$u = new User($this->container); $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->create(array('username' => 'titi', 'is_ldap_user' => 1))); $this->assertNotFalse($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
$this->assertFalse($u->create(array('username' => 'toto'))); $this->assertFalse($u->create(array('username' => 'toto')));
$user = $u->getById(1); $user = $u->getById(1);
@ -105,7 +105,7 @@ class UserTest extends Base
public function testUpdate() public function testUpdate()
{ {
$u = new User($this->container); $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute'))); $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
$user = $u->getById(2); $user = $u->getById(2);
@ -124,7 +124,7 @@ class UserTest extends Base
$tf = new TaskFinder($this->container); $tf = new TaskFinder($this->container);
$p = new Project($this->container); $p = new Project($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));