public function testDuplicate() { $tc = new TaskCreation($this->container); $s = new SubTask($this->container); $p = new Project($this->container); // We create a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); // We create 2 tasks $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0))); // We create many subtasks for the first task $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on'))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1))); // We duplicate our subtasks $this->assertTrue($s->duplicate(1, 2)); $subtasks = $s->getAll(2); $this->assertNotFalse($subtasks); $this->assertNotEmpty($subtasks); $this->assertEquals(2, count($subtasks)); $this->assertEquals('subtask #1', $subtasks[0]['title']); $this->assertEquals('subtask #2', $subtasks[1]['title']); $this->assertEquals(2, $subtasks[0]['task_id']); $this->assertEquals(2, $subtasks[1]['task_id']); $this->assertEquals(5, $subtasks[0]['time_estimated']); $this->assertEquals(0, $subtasks[1]['time_estimated']); $this->assertEquals(0, $subtasks[0]['time_spent']); $this->assertEquals(0, $subtasks[1]['time_spent']); $this->assertEquals(0, $subtasks[0]['status']); $this->assertEquals(0, $subtasks[1]['status']); $this->assertEquals(0, $subtasks[0]['user_id']); $this->assertEquals(0, $subtasks[1]['user_id']); }
public function testCalculateTime() { $tm = new TaskModification($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $s = new SubTask($this->container); $ts = new TimeTracking($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5))); $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 3.5))); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(4.5, $task['time_estimated']); $this->assertEquals(3.5, $task['time_spent']); $timesheet = $ts->getTaskTimesheet($task, array()); $this->assertNotEmpty($timesheet); $this->assertEquals(4.5, $timesheet['time_estimated']); $this->assertEquals(3.5, $timesheet['time_spent']); $this->assertEquals(1, $timesheet['time_remaining']); // Subtasks calculation $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5.5, 'time_spent' => 3))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => 4))); $timesheet = $ts->getTaskTimesheet($task, $s->getAll(1)); $this->assertNotEmpty($timesheet); $this->assertEquals(5.5, $timesheet['time_estimated']); $this->assertEquals(7, $timesheet['time_spent']); $this->assertEquals(-1.5, $timesheet['time_remaining']); }
$server->register('getAllComments', function ($task_id) use($comment) { return $comment->getAll($task_id); }); $server->register('updateComment', function ($values) use($comment) { list($valid, ) = $comment->validateModification($values); return $valid && $comment->update($values); }); $server->register('removeComment', function ($comment_id) use($comment) { return $comment->remove($comment_id); }); /** * Subtask procedures */ $server->register('createSubtask', function (array $values) use($subtask) { list($valid, ) = $subtask->validate($values); return $valid && $subtask->create($values); }); $server->register('getSubtask', function ($subtask_id) use($subtask) { return $subtask->getById($subtask_id); }); $server->register('getAllSubtasks', function ($task_id) use($subtask) { return $subtask->getAll($task_id); }); $server->register('updateSubtask', function ($values) use($subtask) { list($valid, ) = $subtask->validate($values); return $valid && $subtask->update($values); }); $server->register('removeSubtask', function ($subtask_id) use($subtask) { return $subtask->remove($subtask_id); }); /**
#!/usr/bin/env php <?php require __DIR__ . '/../app/common.php'; use Model\TaskCreation; use Model\SubTask; use Model\Project; use Model\ProjectPermission; use Model\User; $task_per_column = 200; $userModel = new User($container); $projectModel = new Project($container); $permissionModel = new ProjectPermission($container); $taskModel = new TaskCreation($container); $subtaskModel = new SubTask($container); $project_id = $projectModel->create(array('name' => 'Project #1')); $permissionModel->addMember($project_id, 1); for ($i = 0; $i <= 5; $i++) { $userModel->create(array('username' => 'user' . $i, 'password' => 'password' . $i, 'name' => 'User #' . $i, 'email' => 'user' . $i . '@localhost')); } foreach (array(1, 2, 3, 4) as $column_id) { for ($i = 1; $i <= $task_per_column; $i++) { $task = array('title' => 'Task #' . $i . '-' . $column_id, 'project_id' => 1, 'column_id' => $column_id, 'owner_id' => 1, 'color_id' => mt_rand(0, 1) === 0 ? 'green' : 'purple', 'score' => mt_rand(0, 21), 'is_active' => mt_rand(0, 1)); $id = $taskModel->create($task); $subtaskModel->create(array('title' => 'Subtask of task #' . $id, 'user_id' => 1, 'status' => mt_rand(0, 2), 'task_id' => $id)); } }