public function testDuplicate() { $t = new Task($this->registry); $s = new SubTask($this->registry); $p = new Project($this->registry); // We create a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); // We create 2 tasks $this->assertEquals(1, $t->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); $this->assertEquals(2, $t->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))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 0, 'time_spent' => 0, '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 testExecute() { $action = new Action\TaskAssignColorUser(1, new Task($this->registry)); $action->setParam('user_id', 1); $action->setParam('color_id', 'blue'); // We create a task in the first column $t = new Task($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'))); // We create an event to move the task to the 2nd column with a user id 5 $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 5); // Our event should NOT be executed $this->assertFalse($action->execute($event)); // Our task should be assigned to nobody and have the green color $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); $this->assertEquals('green', $task['color_id']); // We create an event to move the task to the 2nd column with a user id 1 $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 1); // Our event should be executed $this->assertTrue($action->execute($event)); // Our task should be assigned to nobody and have the blue color $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); $this->assertEquals('blue', $task['color_id']); }
public function testCleanup() { $e = new TaskHistory($this->registry); $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))); $max = 15; $nb_events = 100; for ($i = 0; $i < $nb_events; $i++) { $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE)); } $this->assertEquals($nb_events, $this->registry->db->table('task_has_events')->count()); $e->cleanup($max); $events = $e->getAllByProjectId(1); $this->assertNotEmpty($events); $this->assertTrue(is_array($events)); $this->assertEquals($max, count($events)); $this->assertEquals(100, $events[0]['id']); $this->assertEquals(99, $events[1]['id']); $this->assertEquals(86, $events[14]['id']); // Cleanup during task creation $nb_events = TaskHistory::MAX_EVENTS + 10; for ($i = 0; $i < $nb_events; $i++) { $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE)); } $this->assertEquals(TaskHistory::MAX_EVENTS, $this->registry->db->table('task_has_events')->count()); }
public function testExecute() { $action = new Action\TaskAssignColorCategory(1, new Task($this->registry)); $action->setParam('category_id', 1); $action->setParam('color_id', 'blue'); // We create a task in the first column $t = new Task($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $c->create(array('name' => 'c1'))); $this->assertEquals(2, $c->create(array('name' => 'c2'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2))); // We create an event but we don't do anything $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2, 'position' => 2); // Our event should NOT be executed $this->assertFalse($action->execute($event)); // Our task should be assigned to the ategory_id=1 and have the green color $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['category_id']); $this->assertEquals('green', $task['color_id']); // We create an event to move the task $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'position' => 5, 'category_id' => 1); // Our event should be executed $this->assertTrue($action->execute($event)); // Our task should have the blue color $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals('blue', $task['color_id']); }
public function testExecute() { $action = new Action\TaskMoveAnotherProject(1, new Task($this->registry)); // We create a task in the first column $t = new Task($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'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should NOT be executed because we define the same project $action->setParam('column_id', 2); $action->setParam('project_id', 1); $this->assertFalse($action->execute($event)); // Our task should be assigned to the project 1 $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['project_id']); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should be executed because we define a different project $action->setParam('column_id', 2); $action->setParam('project_id', 2); $this->assertTrue($action->execute($event)); // Our task should be assigned to the project 2 $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); }
public function validateRemove() { $c = new Comment($this->registry); $t = new Task($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $t->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->assertTrue($c->remove(1)); $this->assertFalse($c->remove(1)); $this->assertFalse($c->remove(1111)); }
public function testUpdate() { $c = new Comment($this->registry); $t = new Task($this->registry); $p = new Project($this->registry); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $t->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->assertTrue($c->update(array('id' => 1, 'comment' => 'bla'))); $comment = $c->getById(1); $this->assertNotEmpty($comment); $this->assertEquals('bla', $comment['comment']); }
public function testExecute() { $action = new Action\TaskClose(1, new Task($this->registry)); $action->setParam('column_id', 2); // We create a task in the first column $t = new Task($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))); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should be executed $this->assertTrue($action->execute($event)); // Our task should be closed $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['is_active']); }
public function testIsLastModified() { $p = new Project($this->registry); $t = new Task($this->registry); $now = time(); $p->attachEvents(); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $project = $p->getById(1); $this->assertNotEmpty($project); $this->assertEquals($now, $project['last_modified']); sleep(1); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE)); $this->assertEquals('Event\\ProjectModificationDate', $this->registry->shared('event')->getLastListenerExecuted()); $project = $p->getById(1); $this->assertNotEmpty($project); $this->assertTrue($p->isModifiedSince(1, $now)); }
public function testRemove() { $t = new Task($this->registry); $p = new Project($this->registry); $c = new Category($this->registry); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1))); $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); $this->assertTrue(is_array($task)); $this->assertEquals(2, $task['category_id']); $this->assertTrue($c->remove(1)); $this->assertTrue($c->remove(2)); // Make sure tasks assigned with that category are reseted $task = $t->getById(1); $this->assertTrue(is_array($task)); $this->assertEquals(0, $task['category_id']); }
public function testRemove() { $u = new User($this->registry); $t = new Task($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); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['owner_id']); $this->assertTrue($u->remove(1)); $this->assertTrue($u->remove(2)); $this->assertFalse($u->remove(2)); $this->assertFalse($u->remove(55)); // Make sure that assigned tasks are unassigned after removing the user $task = $t->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(0, $task['owner_id']); }
public function testExecute() { $action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry)); $action->setParam('column_id', 2); $_SESSION = array('user' => array('id' => 5)); // We create a task in the first column $t = new Task($this->registry); $p = new Project($this->registry); $a = new Acl($this->registry); $this->assertEquals(5, $a->getUserId()); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should be executed $this->assertTrue($action->execute($event)); // Our task should be assigned to the user 5 (from the session) $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['id']); $this->assertEquals(5, $task['owner_id']); }
#!/usr/bin/env php <?php require __DIR__ . '/../app/common.php'; use Model\Task; $task_per_column = 250; $taskModel = new Task($registry); 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' => rand(0, 1), 'color_id' => rand(0, 1) === 0 ? 'green' : 'purple', 'score' => rand(0, 21)); $taskModel->create($task); } }
$server->register('getAllowedUsers', function ($project_id) use($project) { return $project->getUsersList($project_id, false, false); }); $server->register('revokeUser', function ($project_id, $user_id) use($project) { return $project->revokeUser($project_id, $user_id); }); $server->register('allowUser', function ($project_id, $user_id) use($project) { return $project->allowUser($project_id, $user_id); }); /** * 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($task) { $values = array('title' => $title, 'project_id' => $project_id, 'color_id' => $color_id, 'column_id' => $column_id, 'owner_id' => $owner_id, 'creator_id' => $creator_id, 'date_due' => $date_due, 'description' => $description, 'category_id' => $category_id, 'score' => $score); list($valid, ) = $task->validateCreation($values); return $valid && $task->create($values) !== false; }); $server->register('getTask', function ($task_id) use($task) { return $task->getById($task_id); }); $server->register('getAllTasks', function ($project_id, array $status) use($task) { return $task->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) { $values = array('id' => $id, 'title' => $title, 'project_id' => $project_id, 'color_id' => $color_id, 'column_id' => $column_id, 'owner_id' => $owner_id, 'creator_id' => $creator_id, 'date_due' => $date_due, 'description' => $description, 'category_id' => $category_id, 'score' => $score); foreach ($values as $key => $value) { if (is_null($value)) { unset($values[$key]); } } list($valid) = $task->validateModification($values);
public function testEventMovePosition() { $task = new Task($this->registry); $board = new Board($this->registry); $project = new Project($this->registry); $action = new Action($this->registry); // We create a project $this->assertEquals(1, $project->create(array('name' => 'unit_test'))); // We create a task $this->assertEquals(1, $task->create(array('title' => 'unit_test 0', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', 'column_id' => 1, 'category_id' => 1))); $this->assertEquals(2, $task->create(array('title' => 'unit_test 1', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'yellow', 'column_id' => 1, 'category_id' => 1))); // We create a new action, when the category_id=2 then the color_id should be green $this->assertTrue($action->create(array('project_id' => 1, 'event_name' => Task::EVENT_MOVE_POSITION, 'action_name' => 'TaskAssignColorCategory', 'params' => array('category_id' => 1, 'color_id' => 'green')))); // We bind events $action->attachEvents(); $this->assertTrue($this->registry->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\\TaskAssignColorCategory')); // Our task should have the color red and position=1 $t1 = $task->getById(1); $this->assertEquals(1, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('red', $t1['color_id']); $t1 = $task->getById(2); $this->assertEquals(2, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('yellow', $t1['color_id']); // We move our tasks $this->assertTrue($task->movePosition(1, 1, 1, 10)); // task #1 to the end of the column $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); $t1 = $task->getById(1); $this->assertEquals(2, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('green', $t1['color_id']); $t1 = $task->getById(2); $this->assertEquals(1, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('yellow', $t1['color_id']); $this->registry->event->clearTriggeredEvents(); $this->assertTrue($task->movePosition(1, 2, 1, 44)); // task #2 to position 1 $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); $this->assertEquals('Action\\TaskAssignColorCategory', $this->registry->event->getLastListenerExecuted()); $t1 = $task->getById(1); $this->assertEquals(1, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('green', $t1['color_id']); $t1 = $task->getById(2); $this->assertEquals(2, $t1['position']); $this->assertEquals(1, $t1['is_active']); $this->assertEquals('green', $t1['color_id']); }
public function testEvents() { $t = new Task($this->registry); $p = new Project($this->registry); // We create a project $this->assertEquals(1, $p->create(array('name' => 'test'))); // We create task $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE)); // We update a task $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1))); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_UPDATE)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE_UPDATE)); // We close our task $this->assertTrue($t->close(1)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CLOSE)); // We open our task $this->assertTrue($t->open(1)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_OPEN)); // We change the column of our task $this->assertTrue($t->movePosition(1, 1, 2, 1)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // We change the position of our task $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2))); $this->assertTrue($t->movePosition(1, 1, 2, 2)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); // We change the column and the position of our task $this->assertTrue($t->movePosition(1, 1, 1, 1)); $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); }
public function testExecuteMultipleActions() { $task = new Task($this->registry); $board = new Board($this->registry); $project = new Project($this->registry); $action = new Action($this->registry); // We create 2 projects $this->assertEquals(1, $project->create(array('name' => 'unit_test1'))); $this->assertEquals(2, $project->create(array('name' => 'unit_test2'))); // We create a task $this->assertEquals(1, $task->create(array('title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', 'column_id' => 1))); // We create 2 actions $this->assertTrue($action->create(array('project_id' => 1, 'event_name' => Task::EVENT_CLOSE, 'action_name' => 'TaskDuplicateAnotherProject', 'params' => array('column_id' => 4, 'project_id' => 2)))); $this->assertTrue($action->create(array('project_id' => 1, 'event_name' => Task::EVENT_MOVE_COLUMN, 'action_name' => 'TaskClose', 'params' => array('column_id' => 4)))); // We bind events $action->attachEvents(); // Events should be attached $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_CLOSE, 'Action\\TaskDuplicateAnotherProject')); $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); $this->assertEquals(1, $t1['is_active']); $this->assertEquals(1, $t1['column_id']); $this->assertEquals(1, $t1['project_id']); // We move our task $task->movePosition(1, 1, 4, 1); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE)); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // Our task should be closed $t1 = $task->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); $this->assertNotEmpty($t2); $this->assertNotEquals(4, $t2['column_id']); $this->assertEquals(1, $t2['is_active']); $this->assertEquals(2, $t2['project_id']); $this->assertEquals('unit_test', $t2['title']); }
#!/usr/bin/env php <?php require __DIR__ . '/../app/common.php'; use Model\ProjectDailySummary; use Model\Task; $pds = new ProjectDailySummary($container); $taskModel = new Task($container); for ($i = 1; $i <= 15; $i++) { $task = array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 1); $taskModel->create($task); } $pds->updateTotals(1, date('Y-m-d', strtotime('-7 days'))); $taskModel->movePosition(1, 1, 2, 1); $taskModel->movePosition(1, 2, 2, 1); $taskModel->movePosition(1, 3, 2, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-6 days'))); $taskModel->movePosition(1, 3, 3, 1); $taskModel->movePosition(1, 4, 3, 1); $taskModel->movePosition(1, 5, 3, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-5 days'))); $taskModel->movePosition(1, 5, 4, 1); $taskModel->movePosition(1, 6, 4, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-4 days'))); $taskModel->movePosition(1, 7, 4, 1); $taskModel->movePosition(1, 8, 4, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-3 days'))); $taskModel->movePosition(1, 9, 3, 1); $taskModel->movePosition(1, 10, 2, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-2 days'))); $taskModel->create(array('title' => 'Random task', 'project_id' => 1)); $taskModel->movePosition(1, 11, 2, 1);