} } list($valid) = $task->validateModification($values); return $valid && $task->update($values); }); $server->register('openTask', function ($task_id) use($task) { return $task->open($task_id); }); $server->register('closeTask', function ($task_id) use($task) { return $task->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 */ $server->register('createUser', function (array $values) use($user) { list($valid, ) = $user->validateCreation($values); return $valid && $user->create($values); }); $server->register('getUser', function ($user_id) use($user) { return $user->getById($user_id); }); $server->register('getAllUsers', function () use($user) { return $user->getAll(); }); $server->register('updateUser', function ($values) use($user) {
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 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']); }
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)); }
#!/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);