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 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 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']);
 }
 /**
  * Execute the action
  *
  * @access public
  * @param  array   $data   Event data dictionary
  * @return bool            True if the action was executed or false when not executed
  */
 public function doAction(array $data)
 {
     if ($data['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id')) {
         $task = $this->task->getById($data['task_id']);
         $this->task->duplicateToAnotherProject($this->getParam('project_id'), $task);
         return true;
     }
     return false;
 }
Esempio n. 5
0
 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']);
 }
Esempio n. 6
0
 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']);
 }
Esempio n. 7
0
 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 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']);
 }
Esempio n. 9
0
$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);
    return $valid && $task->update($values);
});
$server->register('openTask', function ($task_id) use($task) {
Esempio n. 10
0
 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']);
 }
Esempio n. 11
0
 public function testMoveToAnotherProject()
 {
     $t = new Task($this->registry);
     $p = new Project($this->registry);
     $user = new User($this->registry);
     // We create a regular user
     $user->create(array('username' => 'unittest1', 'password' => 'unittest'));
     $user->create(array('username' => 'unittest2', 'password' => 'unittest'));
     // We create 2 projects
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2')));
     // We create a task
     $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
     $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);
     $this->assertEquals(1, $t->moveToAnotherProject(2, $task));
     //$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
     // Check the values of the duplicated task
     $task = $t->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['owner_id']);
     $this->assertEquals(0, $task['category_id']);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals(5, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals('test', $task['title']);
     // We allow only one user on the second project
     $this->assertTrue($p->allowUser(2, 2));
     // The owner should be reseted
     $task = $t->getById(2);
     $this->assertEquals(2, $t->moveToAnotherProject(2, $task));
     $task = $t->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['owner_id']);
 }
Esempio n. 12
0
 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']);
 }