diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-10-12 15:32:35 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-10-12 15:32:35 -0400 |
commit | 4061927d215c846ff8eb196301bf61532018042b (patch) | |
tree | 0e14a0e458ee8739754f75f8c158cc42a9b593a4 | |
parent | b7060b33ef317eeac576c504b1fb840d4471e411 (diff) |
Move some Task model methods to the TaskFinder class
32 files changed, 434 insertions, 334 deletions
diff --git a/app/Action/TaskDuplicateAnotherProject.php b/app/Action/TaskDuplicateAnotherProject.php index b76b3884..4ab88534 100644 --- a/app/Action/TaskDuplicateAnotherProject.php +++ b/app/Action/TaskDuplicateAnotherProject.php @@ -64,7 +64,7 @@ class TaskDuplicateAnotherProject extends Base */ public function doAction(array $data) { - $task = $this->task->getById($data['task_id']); + $task = $this->taskFinder->getById($data['task_id']); $this->task->duplicateToAnotherProject($this->getParam('project_id'), $task); return true; } diff --git a/app/Action/TaskMoveAnotherProject.php b/app/Action/TaskMoveAnotherProject.php index 9922a981..d852f56d 100644 --- a/app/Action/TaskMoveAnotherProject.php +++ b/app/Action/TaskMoveAnotherProject.php @@ -64,7 +64,7 @@ class TaskMoveAnotherProject extends Base */ public function doAction(array $data) { - $task = $this->task->getById($data['task_id']); + $task = $this->taskFinder->getById($data['task_id']); $this->task->moveToAnotherProject($this->getParam('project_id'), $task); return true; } diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 9fab0752..ac88df04 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -276,7 +276,7 @@ abstract class Base */ protected function getTask() { - $task = $this->task->getDetails($this->request->getIntegerParam('task_id')); + $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id')); if (! $task) { $this->notfound(); diff --git a/app/Controller/Project.php b/app/Controller/Project.php index f998e5d6..39d8d1b0 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -447,7 +447,7 @@ class Project extends Base $limit = 25; $tasks = $this->taskFinder->getClosedTasks($project['id'], $offset, $limit, $order, $direction); - $nb_tasks = $this->task->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED)); + $nb_tasks = $this->taskFinder->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED)); $this->response->html($this->template->layout('project_tasks', array( 'pagination' => array( diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 4c15d8df..1b20cf15 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -26,7 +26,7 @@ class Task extends Base $this->forbidden(true); } - $task = $this->task->getDetails($this->request->getIntegerParam('task_id')); + $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id')); if (! $task) { $this->notfound(true); diff --git a/app/Event/CommentHistoryListener.php b/app/Event/CommentHistoryListener.php index e5e92b01..ec826615 100644 --- a/app/Event/CommentHistoryListener.php +++ b/app/Event/CommentHistoryListener.php @@ -56,7 +56,7 @@ class CommentHistoryListener implements Listener if ($creator_id && isset($data['task_id']) && isset($data['id'])) { - $task = $this->model->task->getById($data['task_id']); + $task = $this->model->taskFinder->getById($data['task_id']); $this->model->create( $task['project_id'], diff --git a/app/Event/CommentNotificationListener.php b/app/Event/CommentNotificationListener.php index 36b7ea4b..13803874 100644 --- a/app/Event/CommentNotificationListener.php +++ b/app/Event/CommentNotificationListener.php @@ -23,7 +23,7 @@ class CommentNotificationListener extends BaseNotificationListener { $values = array(); $values['comment'] = $this->notification->comment->getById($data['id']); - $values['task'] = $this->notification->task->getDetails($values['comment']['task_id']); + $values['task'] = $this->notification->taskFinder->getDetails($values['comment']['task_id']); return $values; } diff --git a/app/Event/FileNotificationListener.php b/app/Event/FileNotificationListener.php index ed5d78ed..2366ce5d 100644 --- a/app/Event/FileNotificationListener.php +++ b/app/Event/FileNotificationListener.php @@ -23,7 +23,7 @@ class FileNotificationListener extends BaseNotificationListener { $values = array(); $values['file'] = $data; - $values['task'] = $this->notification->task->getDetails($data['task_id']); + $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']); return $values; } diff --git a/app/Event/SubTaskNotificationListener.php b/app/Event/SubTaskNotificationListener.php index 299ae00b..2b35d757 100644 --- a/app/Event/SubTaskNotificationListener.php +++ b/app/Event/SubTaskNotificationListener.php @@ -23,7 +23,7 @@ class SubTaskNotificationListener extends BaseNotificationListener { $values = array(); $values['subtask'] = $this->notification->subtask->getById($data['id'], true); - $values['task'] = $this->notification->task->getDetails($data['task_id']); + $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']); return $values; } diff --git a/app/Event/SubtaskHistoryListener.php b/app/Event/SubtaskHistoryListener.php index 8cc7a7fd..6b4f1c2d 100644 --- a/app/Event/SubtaskHistoryListener.php +++ b/app/Event/SubtaskHistoryListener.php @@ -56,7 +56,7 @@ class SubtaskHistoryListener implements Listener if ($creator_id && isset($data['task_id']) && isset($data['id'])) { - $task = $this->model->task->getById($data['task_id']); + $task = $this->model->taskFinder->getById($data['task_id']); $this->model->create( $task['project_id'], diff --git a/app/Event/TaskNotificationListener.php b/app/Event/TaskNotificationListener.php index 466a8eb4..119e61e5 100644 --- a/app/Event/TaskNotificationListener.php +++ b/app/Event/TaskNotificationListener.php @@ -22,7 +22,7 @@ class TaskNotificationListener extends BaseNotificationListener public function getTemplateData(array $data) { $values = array(); - $values['task'] = $this->notification->task->getDetails($data['task_id']); + $values['task'] = $this->notification->taskFinder->getDetails($data['task_id']); return $values; } diff --git a/app/Model/Board.php b/app/Model/Board.php index de47e6b9..4c78b0f6 100644 --- a/app/Model/Board.php +++ b/app/Model/Board.php @@ -235,7 +235,7 @@ class Board extends Base public function get($project_id, array $filters = array()) { $columns = $this->getColumns($project_id); - $tasks = $this->taskFinder->getOpenTasks($project_id); + $tasks = $this->taskFinder->getTasksOnBoard($project_id); foreach ($columns as &$column) { diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php index b5f95eeb..6624a782 100644 --- a/app/Model/GithubWebhook.php +++ b/app/Model/GithubWebhook.php @@ -77,7 +77,7 @@ class GithubWebhook extends Base continue; } - $task = $this->task->getById($task_id); + $task = $this->taskFinder->getById($task_id); if (! $task) { continue; @@ -148,7 +148,7 @@ class GithubWebhook extends Base */ public function handleIssueClosed(array $issue) { - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($task) { $event = array( @@ -169,7 +169,7 @@ class GithubWebhook extends Base */ public function handleIssueReopened(array $issue) { - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($task) { $event = array( @@ -191,7 +191,7 @@ class GithubWebhook extends Base public function handleIssueAssigned(array $issue) { $user = $this->user->getByUsername($issue['assignee']['login']); - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($user && $task) { @@ -214,7 +214,7 @@ class GithubWebhook extends Base */ public function handleIssueUnassigned(array $issue) { - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($task) { @@ -238,7 +238,7 @@ class GithubWebhook extends Base */ public function handleIssueLabeled(array $issue, array $label) { - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($task) { @@ -262,7 +262,7 @@ class GithubWebhook extends Base */ public function handleIssueUnlabeled(array $issue, array $label) { - $task = $this->task->getByReference($issue['number']); + $task = $this->taskFinder->getByReference($issue['number']); if ($task) { diff --git a/app/Model/Project.php b/app/Model/Project.php index b60ba567..ad0afa82 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -196,12 +196,12 @@ class Project extends Base $stats['nb_active_tasks'] = 0; foreach ($columns as &$column) { - $column['nb_active_tasks'] = $this->task->countByColumnId($project_id, $column['id']); + $column['nb_active_tasks'] = $this->taskFinder->countByColumnId($project_id, $column['id']); $stats['nb_active_tasks'] += $column['nb_active_tasks']; } $stats['columns'] = $columns; - $stats['nb_tasks'] = $this->task->countByProjectId($project_id); + $stats['nb_tasks'] = $this->taskFinder->countByProjectId($project_id); $stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks']; return $stats; diff --git a/app/Model/Task.php b/app/Model/Task.php index 4536ba5c..a0090641 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -2,8 +2,6 @@ namespace Model; -use PDO; - /** * Task model * @@ -42,163 +40,6 @@ class Task extends Base const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change'; /** - * Get a list of due tasks for all projects - * - * @access public - * @return array - */ - public function getOverdueTasks() - { - $tasks = $this->db->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.title', - self::TABLE.'.date_due', - self::TABLE.'.project_id', - Project::TABLE.'.name AS project_name', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name' - ) - ->join(Project::TABLE, 'id', 'project_id') - ->join(User::TABLE, 'id', 'owner_id') - ->eq(Project::TABLE.'.is_active', 1) - ->eq(self::TABLE.'.is_active', 1) - ->neq(self::TABLE.'.date_due', 0) - ->lte(self::TABLE.'.date_due', mktime(23, 59, 59)) - ->findAll(); - - return $tasks; - } - - /** - * Get task details (fetch more information from other tables) - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getDetails($task_id) - { - $sql = ' - SELECT - tasks.id, - tasks.reference, - tasks.title, - tasks.description, - tasks.date_creation, - tasks.date_completed, - tasks.date_modification, - tasks.date_due, - tasks.date_started, - tasks.time_estimated, - tasks.time_spent, - tasks.color_id, - tasks.project_id, - tasks.column_id, - tasks.owner_id, - tasks.creator_id, - tasks.position, - tasks.is_active, - tasks.score, - tasks.category_id, - project_has_categories.name AS category_name, - projects.name AS project_name, - columns.title AS column_title, - users.username AS assignee_username, - users.name AS assignee_name, - creators.username AS creator_username, - creators.name AS creator_name - FROM tasks - LEFT JOIN users ON users.id = tasks.owner_id - LEFT JOIN users AS creators ON creators.id = tasks.creator_id - LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id - LEFT JOIN projects ON projects.id = tasks.project_id - LEFT JOIN columns ON columns.id = tasks.column_id - WHERE tasks.id = ? - '; - - $rq = $this->db->execute($sql, array($task_id)); - return $rq->fetch(PDO::FETCH_ASSOC); - } - - /** - * Fetch a task by the id - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getById($task_id) - { - return $this->db->table(self::TABLE)->eq('id', $task_id)->findOne(); - } - - /** - * Fetch a task by the reference (external id) - * - * @access public - * @param string $reference Task reference - * @return array - */ - public function getByReference($reference) - { - return $this->db->table(self::TABLE)->eq('reference', $reference)->findOne(); - } - - /** - * Get all tasks for a given project and status - * - * @access public - * @param integer $project_id Project id - * @param integer $status_id Status id - * @return array - */ - public function getAll($project_id, $status_id = self::STATUS_OPEN) - { - return $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('is_active', $status_id) - ->findAll(); - } - - /** - * Count all tasks for a given project and status - * - * @access public - * @param integer $project_id Project id - * @param array $status List of status id - * @return integer - */ - public function countByProjectId($project_id, array $status = array(self::STATUS_OPEN, self::STATUS_CLOSED)) - { - return $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->in('is_active', $status) - ->count(); - } - - /** - * Count the number of tasks for a given column and status - * - * @access public - * @param integer $project_id Project id - * @param integer $column_id Column id - * @param array $status List of status id - * @return integer - */ - public function countByColumnId($project_id, $column_id, array $status = array(self::STATUS_OPEN)) - { - return $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('column_id', $column_id) - ->in('is_active', $status) - ->count(); - } - - /** * Prepare data before task creation or modification * * @access public @@ -233,7 +74,7 @@ class Task extends Base $values['date_creation'] = time(); $values['date_modification'] = $values['date_creation']; - $values['position'] = $this->countByColumnId($values['project_id'], $values['column_id']) + 1; + $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1; } /** @@ -288,7 +129,7 @@ class Task extends Base public function update(array $values, $trigger_events = true) { // Fetch original task - $original_task = $this->getById($values['id']); + $original_task = $this->taskFinder->getById($values['id']); if (! $original_task) { return false; @@ -341,18 +182,6 @@ class Task extends Base } /** - * Return true if the project exists - * - * @access public - * @param integer $task_id Task id - * @return boolean - */ - public function exists($task_id) - { - return $this->db->table(self::TABLE)->eq('id', $task_id)->count() === 1; - } - - /** * Mark a task closed * * @access public @@ -361,7 +190,7 @@ class Task extends Base */ public function close($task_id) { - if (! $this->exists($task_id)) { + if (! $this->taskFinder->exists($task_id)) { return false; } @@ -374,7 +203,7 @@ class Task extends Base )); if ($result) { - $this->event->trigger(self::EVENT_CLOSE, array('task_id' => $task_id) + $this->getById($task_id)); + $this->event->trigger(self::EVENT_CLOSE, array('task_id' => $task_id) + $this->taskFinder->getById($task_id)); } return $result; @@ -389,7 +218,7 @@ class Task extends Base */ public function open($task_id) { - if (! $this->exists($task_id)) { + if (! $this->taskFinder->exists($task_id)) { return false; } @@ -402,7 +231,7 @@ class Task extends Base )); if ($result) { - $this->event->trigger(self::EVENT_OPEN, array('task_id' => $task_id) + $this->getById($task_id)); + $this->event->trigger(self::EVENT_OPEN, array('task_id' => $task_id) + $this->taskFinder->getById($task_id)); } return $result; @@ -417,7 +246,7 @@ class Task extends Base */ public function remove($task_id) { - if (! $this->exists($task_id)) { + if (! $this->taskFinder->exists($task_id)) { return false; } @@ -541,7 +370,7 @@ class Task extends Base // We use the first column of the new project $values['column_id'] = $this->board->getFirstColumn($project_id); - $values['position'] = $this->countByColumnId($project_id, $values['column_id']) + 1; + $values['position'] = $this->taskFinder->countByColumnId($project_id, $values['column_id']) + 1; $values['project_id'] = $project_id; // The task will be open (close event binding) @@ -583,7 +412,7 @@ class Task extends Base $values['column_id'] = $task['column_id']; $values['owner_id'] = 0; $values['creator_id'] = $task['creator_id']; - $values['position'] = $this->countByColumnId($values['project_id'], $values['column_id']) + 1; + $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1; $values['score'] = $task['score']; $values['category_id'] = 0; diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php index 43537e2d..5bf8c139 100644 --- a/app/Model/TaskFinder.php +++ b/app/Model/TaskFinder.php @@ -2,6 +2,8 @@ namespace Model; +use PDO; + /** * Task Finder model * @@ -10,7 +12,13 @@ namespace Model; */ class TaskFinder extends Base { - private function prepareRequest() + /** + * Common request to fetch a list of tasks + * + * @access private + * @return \PicoDb\Table + */ + private function prepareRequestList() { return $this->db ->table(Task::TABLE) @@ -42,9 +50,21 @@ class TaskFinder extends Base ->join(User::TABLE, 'id', 'owner_id'); } + /** + * Task search with pagination + * + * @access public + * @param integer $project_id Project id + * @param string $search Search terms + * @param integer $offset Offset + * @param integer $limit Limit + * @param string $column Sorting column + * @param string $direction Sorting direction + * @return array + */ public function search($project_id, $search, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'DESC') { - return $this->prepareRequest() + return $this->prepareRequestList() ->eq('project_id', $project_id) ->like('title', '%'.$search.'%') ->offset($offset) @@ -53,17 +73,20 @@ class TaskFinder extends Base ->findAll(); } - public function countSearch($project_id, $search) - { - return $this->db->table(Task::TABLE) - ->eq('project_id', $project_id) - ->like('title', '%'.$search.'%') - ->count(); - } - + /** + * Get all completed tasks with pagination + * + * @access public + * @param integer $project_id Project id + * @param integer $offset Offset + * @param integer $limit Limit + * @param string $column Sorting column + * @param string $direction Sorting direction + * @return array + */ public function getClosedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC') { - return $this->prepareRequest() + return $this->prepareRequestList() ->eq('project_id', $project_id) ->eq('is_active', Task::STATUS_CLOSED) ->offset($offset) @@ -72,12 +95,204 @@ class TaskFinder extends Base ->findAll(); } - public function getOpenTasks($project_id, $column = 'tasks.position', $direction = 'ASC') + /** + * Get all tasks shown on the board (sorted by position) + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getTasksOnBoard($project_id) { - return $this->prepareRequest() + return $this->prepareRequestList() ->eq('project_id', $project_id) ->eq('is_active', Task::STATUS_OPEN) - ->orderBy($column, $direction) + ->asc('tasks.position') + ->findAll(); + } + + /** + * Get all tasks for a given project and status + * + * @access public + * @param integer $project_id Project id + * @param integer $status_id Status id + * @return array + */ + public function getAll($project_id, $status_id = Task::STATUS_OPEN) + { + return $this->db + ->table(Task::TABLE) + ->eq('project_id', $project_id) + ->eq('is_active', $status_id) + ->findAll(); + } + + /** + * Get a list of overdue tasks for all projects + * + * @access public + * @return array + */ + public function getOverdueTasks() + { + $tasks = $this->db->table(Task::TABLE) + ->columns( + Task::TABLE.'.id', + Task::TABLE.'.title', + Task::TABLE.'.date_due', + Task::TABLE.'.project_id', + Project::TABLE.'.name AS project_name', + User::TABLE.'.username AS assignee_username', + User::TABLE.'.name AS assignee_name' + ) + ->join(Project::TABLE, 'id', 'project_id') + ->join(User::TABLE, 'id', 'owner_id') + ->eq(Project::TABLE.'.is_active', 1) + ->eq(Task::TABLE.'.is_active', 1) + ->neq(Task::TABLE.'.date_due', 0) + ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)) ->findAll(); + + return $tasks; + } + + /** + * Fetch a task by the id + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getById($task_id) + { + return $this->db->table(Task::TABLE)->eq('id', $task_id)->findOne(); + } + + /** + * Fetch a task by the reference (external id) + * + * @access public + * @param string $reference Task reference + * @return array + */ + public function getByReference($reference) + { + return $this->db->table(Task::TABLE)->eq('reference', $reference)->findOne(); + } + + /** + * Get task details (fetch more information from other tables) + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getDetails($task_id) + { + $sql = ' + SELECT + tasks.id, + tasks.reference, + tasks.title, + tasks.description, + tasks.date_creation, + tasks.date_completed, + tasks.date_modification, + tasks.date_due, + tasks.date_started, + tasks.time_estimated, + tasks.time_spent, + tasks.color_id, + tasks.project_id, + tasks.column_id, + tasks.owner_id, + tasks.creator_id, + tasks.position, + tasks.is_active, + tasks.score, + tasks.category_id, + project_has_categories.name AS category_name, + projects.name AS project_name, + columns.title AS column_title, + users.username AS assignee_username, + users.name AS assignee_name, + creators.username AS creator_username, + creators.name AS creator_name + FROM tasks + LEFT JOIN users ON users.id = tasks.owner_id + LEFT JOIN users AS creators ON creators.id = tasks.creator_id + LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id + LEFT JOIN projects ON projects.id = tasks.project_id + LEFT JOIN columns ON columns.id = tasks.column_id + WHERE tasks.id = ? + '; + + $rq = $this->db->execute($sql, array($task_id)); + return $rq->fetch(PDO::FETCH_ASSOC); + } + + /** + * Count all tasks for a given project and status + * + * @access public + * @param integer $project_id Project id + * @param array $status List of status id + * @return integer + */ + public function countByProjectId($project_id, array $status = array(Task::STATUS_OPEN, Task::STATUS_CLOSED)) + { + return $this->db + ->table(Task::TABLE) + ->eq('project_id', $project_id) + ->in('is_active', $status) + ->count(); + } + + /** + * Count the number of tasks for a given column and status + * + * @access public + * @param integer $project_id Project id + * @param integer $column_id Column id + * @param array $status List of status id + * @return integer + */ + public function countByColumnId($project_id, $column_id, array $status = array(Task::STATUS_OPEN)) + { + return $this->db + ->table(Task::TABLE) + ->eq('project_id', $project_id) + ->eq('column_id', $column_id) + ->in('is_active', $status) + ->count(); + } + + /** + * Count the number of tasks for a custom search + * + * @access public + * @param integer $project_id Project id + * @param string $search Search terms + * @return integer + */ + public function countSearch($project_id, $search) + { + return $this->db->table(Task::TABLE) + ->eq('project_id', $project_id) + ->like('title', '%'.$search.'%') + ->count(); + } + + /** + * Return true if the task exists + * + * @access public + * @param integer $task_id Task id + * @return boolean + */ + public function exists($task_id) + { + return $this->db->table(Task::TABLE)->eq('id', $task_id)->count() === 1; } } diff --git a/jsonrpc.php b/jsonrpc.php index f577ef82..99d14806 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -6,6 +6,7 @@ use JsonRPC\Server; use Model\Project; use Model\ProjectPermission; use Model\Task; +use Model\TaskFinder; use Model\TaskValidator; use Model\User; use Model\Config; @@ -24,6 +25,7 @@ $config->setupTimezone(); $project = new Project($registry); $projectPermission = new ProjectPermission($registry); $task = new Task($registry); +$taskFinder = new TaskFinder($registry); $taskValidator = new TaskValidator($registry); $user = new User($registry); $category = new Category($registry); @@ -178,12 +180,12 @@ $server->register('createTask', function($title, $project_id, $color_id = '', $c return $valid && $task->create($values) !== false; }); -$server->register('getTask', function($task_id) use ($task) { - return $task->getById($task_id); +$server->register('getTask', function($task_id) use ($taskFinder) { + return $taskFinder->getById($task_id); }); -$server->register('getAllTasks', function($project_id, $status) use ($task) { - return $task->getAll($project_id, $status); +$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) { @@ -7,6 +7,7 @@ use Core\Cli; use Core\Tool; use Model\Config; use Model\Task; +use Model\TaskFinder; use Model\TaskExport; use Model\Notification; @@ -47,7 +48,7 @@ $cli->register('export-csv', function() use ($cli, $registry) { $cli->register('send-notifications-due-tasks', function() use ($cli, $registry) { $notificationModel = new Notification($registry); - $taskModel = new Task($registry); + $taskModel = new TaskFinder($registry); $tasks = $taskModel->getOverdueTasks(); // Group tasks by project diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php index 5a8c0458..b7d99dae 100644 --- a/tests/units/ActionTaskAssignColorCategoryTest.php +++ b/tests/units/ActionTaskAssignColorCategoryTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\Category; @@ -30,6 +31,7 @@ class ActionTaskAssignColorCategory extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); @@ -51,7 +53,7 @@ class ActionTaskAssignColorCategory extends Base $this->assertFalse($action->execute($event)); // Our task should be assigned to the ategory_id=1 and have the green color - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['category_id']); $this->assertEquals('green', $task['color_id']); @@ -69,7 +71,7 @@ class ActionTaskAssignColorCategory extends Base $this->assertTrue($action->execute($event)); // Our task should have the blue color - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals('blue', $task['color_id']); } diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php index 8f6a891e..61600fdc 100644 --- a/tests/units/ActionTaskAssignColorUserTest.php +++ b/tests/units/ActionTaskAssignColorUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; class ActionTaskAssignColorUser extends Base @@ -29,6 +30,7 @@ class ActionTaskAssignColorUser extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green'))); @@ -44,7 +46,7 @@ class ActionTaskAssignColorUser extends Base $this->assertFalse($action->execute($event)); // Our task should be assigned to nobody and have the green color - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); $this->assertEquals('green', $task['color_id']); @@ -60,7 +62,7 @@ class ActionTaskAssignColorUser extends Base $this->assertTrue($action->execute($event)); // Our task should be assigned to nobody and have the blue color - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); $this->assertEquals('blue', $task['color_id']); diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php index cfed7be5..edc2577c 100644 --- a/tests/units/ActionTaskAssignCurrentUserTest.php +++ b/tests/units/ActionTaskAssignCurrentUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\Acl; @@ -47,6 +48,7 @@ class ActionTaskAssignCurrentUser extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $a = new Acl($this->registry); @@ -65,7 +67,7 @@ class ActionTaskAssignCurrentUser extends Base $this->assertTrue($action->execute($event)); // Our task should be assigned to the user 5 (from the session) - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['id']); $this->assertEquals(5, $task['owner_id']); diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php index de8daf11..8795d5fb 100644 --- a/tests/units/ActionTaskAssignSpecificUserTest.php +++ b/tests/units/ActionTaskAssignSpecificUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; class ActionTaskAssignSpecificUser extends Base @@ -44,6 +45,7 @@ class ActionTaskAssignSpecificUser extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); @@ -59,7 +61,7 @@ class ActionTaskAssignSpecificUser extends Base $this->assertTrue($action->execute($event)); // Our task should be assigned to the user 1 - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['owner_id']); } diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php index 73ff57f3..6c8e4cf1 100644 --- a/tests/units/ActionTaskCloseTest.php +++ b/tests/units/ActionTaskCloseTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\GithubWebhook; @@ -82,6 +83,7 @@ class ActionTaskCloseTest extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); @@ -97,7 +99,7 @@ class ActionTaskCloseTest extends Base $this->assertTrue($action->execute($event)); // Our task should be closed - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['is_active']); } diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php index 75aeedf8..6fb3c8d8 100644 --- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php +++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; class ActionTaskDuplicateAnotherProject extends Base @@ -42,6 +43,7 @@ class ActionTaskDuplicateAnotherProject extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'project 1'))); $this->assertEquals(2, $p->create(array('name' => 'project 2'))); @@ -60,7 +62,7 @@ class ActionTaskDuplicateAnotherProject extends Base $this->assertFalse($action->execute($event)); // Our task should be assigned to the project 1 - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['project_id']); @@ -77,12 +79,12 @@ class ActionTaskDuplicateAnotherProject extends Base $this->assertTrue($action->execute($event)); // Our task should be assigned to the project 1 - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['project_id']); // We should have another task assigned to the project 2 - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); } diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php index b395a279..903cc392 100644 --- a/tests/units/ActionTaskMoveAnotherProjectTest.php +++ b/tests/units/ActionTaskMoveAnotherProjectTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; class ActionTaskMoveAnotherProject extends Base @@ -42,6 +43,7 @@ class ActionTaskMoveAnotherProject extends Base // We create a task in the first column $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'project 1'))); $this->assertEquals(2, $p->create(array('name' => 'project 2'))); @@ -60,7 +62,7 @@ class ActionTaskMoveAnotherProject extends Base $this->assertFalse($action->execute($event)); // Our task should be assigned to the project 1 - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['project_id']); @@ -77,7 +79,7 @@ class ActionTaskMoveAnotherProject extends Base $this->assertTrue($action->execute($event)); // Our task should be assigned to the project 2 - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); } diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php index f155d0c0..aa923445 100644 --- a/tests/units/ActionTest.php +++ b/tests/units/ActionTest.php @@ -6,6 +6,7 @@ use Model\Action; use Model\Project; use Model\Board; use Model\Task; +use Model\TaskFinder; use Model\Category; class ActionTest extends Base @@ -49,6 +50,7 @@ class ActionTest extends Base public function testEventMoveColumn() { $task = new Task($this->registry); + $tf = new TaskFinder($this->registry); $board = new Board($this->registry); $project = new Project($this->registry); $action = new Action($this->registry); @@ -79,7 +81,7 @@ class ActionTest extends Base $action->attachEvents(); // Our task should be open - $t1 = $task->getById(1); + $t1 = $tf->getById(1); $this->assertEquals(1, $t1['is_active']); $this->assertEquals(1, $t1['column_id']); @@ -90,7 +92,7 @@ class ActionTest extends Base $this->assertFalse($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE)); // Our task should be closed - $t1 = $task->getById(1); + $t1 = $tf->getById(1); $this->assertEquals(4, $t1['column_id']); $this->assertEquals(0, $t1['is_active']); } @@ -98,6 +100,7 @@ class ActionTest extends Base public function testExecuteMultipleActions() { $task = new Task($this->registry); + $tf = new TaskFinder($this->registry); $board = new Board($this->registry); $project = new Project($this->registry); $action = new Action($this->registry); @@ -143,7 +146,7 @@ class ActionTest extends Base $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose')); // Our task should be open, linked to the first project and in the first column - $t1 = $task->getById(1); + $t1 = $tf->getById(1); $this->assertEquals(1, $t1['is_active']); $this->assertEquals(1, $t1['column_id']); $this->assertEquals(1, $t1['project_id']); @@ -155,12 +158,12 @@ class ActionTest extends Base $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // Our task should be closed - $t1 = $task->getById(1); + $t1 = $tf->getById(1); $this->assertEquals(4, $t1['column_id']); $this->assertEquals(0, $t1['is_active']); // Our task should be duplicated to the 2nd project - $t2 = $task->getById(2); + $t2 = $tf->getById(2); $this->assertNotEmpty($t2); $this->assertNotEquals(4, $t2['column_id']); $this->assertEquals(1, $t2['is_active']); diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php index 201fa589..ef061419 100644 --- a/tests/units/CategoryTest.php +++ b/tests/units/CategoryTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\Category; use Model\User; @@ -12,6 +13,7 @@ class CategoryTest extends Base public function testCreation() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); @@ -20,7 +22,7 @@ class CategoryTest extends Base $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertTrue(is_array($task)); $this->assertEquals(2, $task['category_id']); @@ -34,6 +36,7 @@ class CategoryTest extends Base public function testRemove() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); @@ -42,7 +45,7 @@ class CategoryTest extends Base $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertTrue(is_array($task)); $this->assertEquals(2, $task['category_id']); @@ -50,7 +53,7 @@ class CategoryTest extends Base $this->assertTrue($c->remove(2)); // Make sure tasks assigned with that category are reseted - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertTrue(is_array($task)); $this->assertEquals(0, $task['category_id']); } diff --git a/tests/units/TaskFinderTest.php b/tests/units/TaskFinderTest.php new file mode 100644 index 00000000..5a90f3af --- /dev/null +++ b/tests/units/TaskFinderTest.php @@ -0,0 +1,32 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\Task; +use Model\TaskFinder; +use Model\Project; +use Model\ProjectPermission; +use Model\Category; +use Model\User; + +class TaskFinderTest extends Base +{ + public function testGetOverdueTasks() + { + $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); + $p = new Project($this->registry); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); + $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day')))); + $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0))); + $this->assertEquals(4, $t->create(array('title' => 'Task #3', 'project_id' => 1))); + + $tasks = $tf->getOverdueTasks(); + $this->assertNotEmpty($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals(1, count($tasks)); + $this->assertEquals('Task #1', $tasks[0]['title']); + } +} diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php index 66036990..5a94a274 100644 --- a/tests/units/TaskPermissionTest.php +++ b/tests/units/TaskPermissionTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\TaskPermission; use Model\Project; use Model\Category; @@ -13,6 +14,7 @@ class TaskPermissionTest extends Base public function testPrepareCreation() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $tp = new TaskPermission($this->registry); $p = new Project($this->registry); $u = new User($this->registry); @@ -30,7 +32,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(1); + $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); @@ -39,7 +41,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(1); + $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); @@ -48,7 +50,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(2); + $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); @@ -57,7 +59,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(2); + $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); @@ -66,7 +68,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(3); + $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); @@ -75,7 +77,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(3); + $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); @@ -84,7 +86,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(4); + $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); @@ -93,7 +95,7 @@ class TaskPermissionTest extends Base $this->assertNotEmpty($user); $u->updateSession($user); - $task = $t->getbyId(4); + $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); } diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php index 4d121fcd..e82faf19 100644 --- a/tests/units/TaskTest.php +++ b/tests/units/TaskTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; use Model\Category; @@ -13,6 +14,7 @@ class TaskTest extends Base public function testPrepareCreation() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -91,6 +93,7 @@ class TaskTest extends Base public function testPrepareModification() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -110,12 +113,13 @@ class TaskTest extends Base public function testCreation() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); @@ -126,7 +130,7 @@ class TaskTest extends Base $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1))); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(2, $task['position']); @@ -134,19 +138,20 @@ class TaskTest extends Base $this->assertEquals(time(), $task['date_modification']); $this->assertEquals(0, $task['date_due']); - $tasks = $t->getAll(1, 1); + $tasks = $tf->getAll(1, 1); $this->assertNotEmpty($tasks); $this->assertTrue(is_array($tasks)); $this->assertEquals(1, $tasks[0]['id']); $this->assertEquals(2, $tasks[1]['id']); - $tasks = $t->getAll(1, 0); + $tasks = $tf->getAll(1, 0); $this->assertEmpty($tasks); } public function testRemove() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); @@ -156,27 +161,10 @@ class TaskTest extends Base $this->assertFalse($t->remove(1234)); } - public function testGetOverdueTasks() - { - $t = new Task($this->registry); - $p = new Project($this->registry); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day')))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0))); - $this->assertEquals(4, $t->create(array('title' => 'Task #3', 'project_id' => 1))); - - $tasks = $t->getOverdueTasks(); - $this->assertNotEmpty($tasks); - $this->assertTrue(is_array($tasks)); - $this->assertEquals(1, count($tasks)); - $this->assertEquals('Task #1', $tasks[0]['title']); - } - public function testMoveTaskWithColumnThatNotChange() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -194,42 +182,42 @@ class TaskTest extends Base $this->assertTrue($t->movePosition(1, 3, 3, 2)); // Check tasks position - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(3); + $task = $tf->getById(3); $this->assertEquals(3, $task['id']); $this->assertEquals(3, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(5); + $task = $tf->getById(5); $this->assertEquals(5, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(6); + $task = $tf->getById(6); $this->assertEquals(6, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); - $task = $t->getById(7); + $task = $tf->getById(7); $this->assertEquals(7, $task['id']); $this->assertEquals(3, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(8); + $task = $tf->getById(8); $this->assertEquals(8, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(3, $task['position']); @@ -238,6 +226,7 @@ class TaskTest extends Base public function testMoveTaskWithBadPreviousPosition() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -251,17 +240,17 @@ class TaskTest extends Base $this->assertTrue($t->movePosition(1, 1, 2, 3)); // Check tasks position - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(3); + $task = $tf->getById(3); $this->assertEquals(3, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); @@ -270,6 +259,7 @@ class TaskTest extends Base public function testMoveTaskTop() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -282,22 +272,22 @@ class TaskTest extends Base $this->assertTrue($t->movePosition(1, 4, 1, 1)); // Check tasks position - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(3, $task['position']); - $task = $t->getById(3); + $task = $tf->getById(3); $this->assertEquals(3, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(4, $task['position']); - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); @@ -306,6 +296,7 @@ class TaskTest extends Base public function testMoveTaskBottom() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -318,22 +309,22 @@ class TaskTest extends Base $this->assertTrue($t->movePosition(1, 1, 1, 4)); // Check tasks position - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(4, $task['position']); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(3); + $task = $tf->getById(3); $this->assertEquals(3, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(2, $task['position']); - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(3, $task['position']); @@ -342,6 +333,7 @@ class TaskTest extends Base public function testMovePosition() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -361,7 +353,7 @@ class TaskTest extends Base $this->assertEquals($counter, $t->create($task)); - $task = $t->getById($counter); + $task = $tf->getById($counter); $this->assertNotFalse($task); $this->assertNotEmpty($task); $this->assertEquals($i, $task['position']); @@ -372,68 +364,68 @@ class TaskTest extends Base $this->assertTrue($t->movePosition(1, 4, 2, 3)); // We check the new position of the task - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); // The tasks before have the correct position - $task = $t->getById(3); + $task = $tf->getById(3); $this->assertEquals(3, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(3, $task['position']); - $task = $t->getById(7); + $task = $tf->getById(7); $this->assertEquals(7, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); // The tasks after have the correct position - $task = $t->getById(5); + $task = $tf->getById(5); $this->assertEquals(5, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(4, $task['position']); - $task = $t->getById(8); + $task = $tf->getById(8); $this->assertEquals(8, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(4, $task['position']); // The number of tasks per column - $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 1)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2)); - $this->assertEquals($task_per_column, $t->countByColumnId(1, 3)); - $this->assertEquals($task_per_column, $t->countByColumnId(1, 4)); + $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2)); + $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3)); + $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4)); // We move task id #1, column 1, position 1 to the column 4, position 6 (last position) $this->assertTrue($t->movePosition(1, 1, 4, $task_per_column + 1)); // We check the new position of the task - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(4, $task['column_id']); $this->assertEquals($task_per_column + 1, $task['position']); // The tasks before have the correct position - $task = $t->getById(20); + $task = $tf->getById(20); $this->assertEquals(20, $task['id']); $this->assertEquals(4, $task['column_id']); $this->assertEquals($task_per_column, $task['position']); // The tasks after have the correct position - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); // The number of tasks per column - $this->assertEquals($task_per_column - 2, $t->countByColumnId(1, 1)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2)); - $this->assertEquals($task_per_column, $t->countByColumnId(1, 3)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4)); + $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2)); + $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4)); // Our previous moved task should stay at the same place - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); @@ -448,28 +440,28 @@ class TaskTest extends Base // Test position greater than the last position $this->assertTrue($t->movePosition(1, 11, 1, 22)); - $task = $t->getById(11); + $task = $tf->getById(11); $this->assertEquals(11, $task['id']); $this->assertEquals(1, $task['column_id']); - $this->assertEquals($t->countByColumnId(1, 1), $task['position']); + $this->assertEquals($tf->countByColumnId(1, 1), $task['position']); - $task = $t->getById(5); + $task = $tf->getById(5); $this->assertEquals(5, $task['id']); $this->assertEquals(1, $task['column_id']); - $this->assertEquals($t->countByColumnId(1, 1) - 1, $task['position']); + $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']); - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); - $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 1)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2)); - $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 3)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4)); + $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2)); + $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4)); // Our previous moved task should stay at the same place - $task = $t->getById(4); + $task = $tf->getById(4); $this->assertEquals(4, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(3, $task['position']); @@ -477,25 +469,26 @@ class TaskTest extends Base // Test moving task to position 1 $this->assertTrue($t->movePosition(1, 14, 1, 1)); - $task = $t->getById(14); + $task = $tf->getById(14); $this->assertEquals(14, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(1, $task['position']); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(1, $task['column_id']); $this->assertEquals(2, $task['position']); - $this->assertEquals($task_per_column, $t->countByColumnId(1, 1)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2)); - $this->assertEquals($task_per_column - 2, $t->countByColumnId(1, 3)); - $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4)); + $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2)); + $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3)); + $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4)); } public function testDuplicateToTheSameProject() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); @@ -510,7 +503,7 @@ class TaskTest extends Base $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['position']); @@ -519,7 +512,7 @@ class TaskTest extends Base $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); $this->assertEquals(1, $task['project_id']); @@ -532,6 +525,7 @@ class TaskTest extends Base public function testDuplicateToAnotherProject() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); @@ -544,14 +538,14 @@ class TaskTest extends Base // We create a task $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); - $task = $t->getById(1); + $task = $tf->getById(1); // We duplicate our task to the 2nd project $this->assertEquals(2, $t->duplicateToAnotherProject(2, $task)); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(1, $task['owner_id']); $this->assertEquals(0, $task['category_id']); @@ -564,6 +558,7 @@ class TaskTest extends Base public function testMoveToAnotherProject() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $pp = new ProjectPermission($this->registry); $user = new User($this->registry); @@ -581,12 +576,12 @@ class TaskTest extends Base $this->assertEquals(2, $t->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333))); // We duplicate our task to the 2nd project - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $t->moveToAnotherProject(2, $task)); //$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['owner_id']); $this->assertEquals(0, $task['category_id']); @@ -599,10 +594,10 @@ class TaskTest extends Base $this->assertTrue($pp->allowUser(2, 2)); // The owner should be reseted - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertEquals(2, $t->moveToAnotherProject(2, $task)); - $task = $t->getById(2); + $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); } diff --git a/tests/units/TimeTrackingTest.php b/tests/units/TimeTrackingTest.php index 50d5cb53..aa772a36 100644 --- a/tests/units/TimeTrackingTest.php +++ b/tests/units/TimeTrackingTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/Base.php'; use Model\SubTask; use Model\Task; +use Model\TaskFinder; use Model\Project; use Model\TimeTracking; @@ -12,6 +13,7 @@ class TimeTrackingTest extends Base public function testCalculateTime() { $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $s = new SubTask($this->registry); $ts = new TimeTracking($this->registry); @@ -20,7 +22,7 @@ class TimeTrackingTest extends Base $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5))); $this->assertTrue($t->update(array('id' => 1, 'time_spent' => 3.5))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(4.5, $task['time_estimated']); $this->assertEquals(3.5, $task['time_spent']); diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php index 9a304e85..b66a6c27 100644 --- a/tests/units/UserTest.php +++ b/tests/units/UserTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/Base.php'; use Model\User; use Model\Task; +use Model\TaskFinder; use Model\Project; class UserTest extends Base @@ -110,13 +111,14 @@ class UserTest extends Base { $u = new User($this->registry); $t = new Task($this->registry); + $tf = new TaskFinder($this->registry); $p = new Project($this->registry); $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['owner_id']); @@ -126,7 +128,7 @@ class UserTest extends Base $this->assertFalse($u->remove(55)); // Make sure that assigned tasks are unassigned after removing the user - $task = $t->getById(1); + $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(0, $task['owner_id']); } |