public function testExecute()
 {
     $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
     $action->setParam('category_id', 1);
     $action->setParam('color_id', 'blue');
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $c = new Category($this->container);
     $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, $tc->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 = $tf->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 = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('blue', $task['color_id']);
 }
 public function testExecute()
 {
     $action = new Action\TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE);
     $action->setParam('dest_column_id', 3);
     $action->setParam('category_id', 1);
     $this->assertEquals(3, $action->getParam('dest_column_id'));
     $this->assertEquals(1, $action->getParam('category_id'));
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $c = new Category($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1)));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
     // No category should be assigned + column_id=1
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEmpty($task['category_id']);
     $this->assertEquals(1, $task['column_id']);
     // We create an event to move the task to the 2nd column
     $event = array('task_id' => 1, 'column_id' => 1, 'project_id' => 1, 'category_id' => 1);
     // Our event should be executed
     $this->assertTrue($action->hasCompatibleEvent());
     $this->assertTrue($action->hasRequiredProject($event));
     $this->assertTrue($action->hasRequiredParameters($event));
     $this->assertTrue($action->hasRequiredCondition($event));
     $this->assertTrue($action->isExecutable($event));
     $this->assertTrue($action->execute(new GenericEvent($event)));
     // Our task should be moved to the other column
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(3, $task['column_id']);
 }
Example #3
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']);
 }
Example #4
0
 public function testExport()
 {
     $tc = new TaskCreation($this->container);
     $p = new Project($this->container);
     $c = new Category($this->container);
     $e = new TaskExport($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Export Project')));
     $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
     $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
     $this->assertNotFalse($c->create(array('name' => 'Category #3', 'project_id' => 1)));
     for ($i = 1; $i <= 100; $i++) {
         $task = array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => rand(1, 3), 'creator_id' => rand(0, 1), 'owner_id' => rand(0, 1), 'color_id' => rand(0, 1) === 0 ? 'green' : 'purple', 'category_id' => rand(0, 3), 'date_due' => array_rand(array(0, date('Y-m-d'), date('Y-m-d', strtotime('+' . $i . 'day')))), 'score' => rand(0, 21));
         $this->assertEquals($i, $tc->create($task));
     }
     $rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day'));
     $this->assertEquals($i, count($rows));
     $this->assertEquals('Task Id', $rows[0][0]);
     $this->assertEquals(1, $rows[1][0]);
     $this->assertEquals('Task #' . ($i - 1), $rows[$i - 1][11]);
 }
 public function testCloneProjectWithCategories()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
     $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
     $this->assertEquals(2, $p->duplicate(1));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('P1 (Clone)', $project['name']);
     $categories = $c->getAll(2);
     $this->assertNotempty($categories);
     $this->assertEquals(3, count($categories));
     $this->assertEquals(4, $categories[0]['id']);
     $this->assertEquals('C1', $categories[0]['name']);
     $this->assertEquals(5, $categories[1]['id']);
     $this->assertEquals('C2', $categories[1]['name']);
     $this->assertEquals(6, $categories[2]['id']);
     $this->assertEquals('C3', $categories[2]['name']);
 }
Example #6
0
 public function testSearchWithCategory()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFilter($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $c->create(array('name' => 'Feature request', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'hé hé', 'project_id' => 1)));
     $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
     $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'category_id' => 1)));
     $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task3', 'category_id' => 2)));
     $tf->search('category:"Feature request"');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(1, $tasks);
     $this->assertEquals('task2', $tasks[0]['title']);
     $tf->search('category:"hé hé"');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(1, $tasks);
     $this->assertEquals('task3', $tasks[0]['title']);
     $tf->search('category:"Feature request" category:"hé hé"');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(2, $tasks);
     $this->assertEquals('task2', $tasks[0]['title']);
     $this->assertEquals('task3', $tasks[1]['title']);
     $tf->search('category:none');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(1, $tasks);
     $this->assertEquals('task1', $tasks[0]['title']);
     $tf->search('category:"not found"');
     $tasks = $tf->findAll();
     $this->assertEmpty($tasks);
 }
Example #7
0
 public function testMultipleActions()
 {
     $tp = new TaskPosition($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $b = new Board($this->container);
     $p = new Project($this->container);
     $a = new Action($this->container);
     $c = new Category($this->container);
     $g = new GithubWebhook($this->container);
     // We create a project
     $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
     $this->assertEquals(1, $c->create(array('name' => 'unit_test')));
     // We create a new action
     $this->assertEquals(1, $a->create(array('project_id' => 1, 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED, 'action_name' => 'TaskCreation', 'params' => array())));
     $this->assertEquals(2, $a->create(array('project_id' => 1, 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, 'action_name' => 'TaskAssignCategoryLabel', 'params' => array('label' => 'bug', 'category_id' => 1))));
     $this->assertEquals(3, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignColorCategory', 'params' => array('color_id' => 'red', 'category_id' => 1))));
     // We attach events
     $a->attachEvents();
     $g->setProjectId(1);
     // We create a Github issue
     $issue = array('number' => 123, 'title' => 'Bugs everywhere', 'body' => 'There is a bug!', 'html_url' => 'http://localhost/');
     $this->assertTrue($g->handleIssueOpened($issue));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['is_active']);
     $this->assertEquals(0, $task['category_id']);
     $this->assertEquals('yellow', $task['color_id']);
     // We assign a label to our issue
     $label = array('name' => 'bug');
     $this->assertTrue($g->handleIssueLabeled($issue, $label));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['is_active']);
     $this->assertEquals(1, $task['category_id']);
     $this->assertEquals('red', $task['color_id']);
 }
 public function testMoveAnotherProjectWithCategory()
 {
     $td = new TaskDuplication($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $c = new Category($this->container);
     // We create 2 projects
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2')));
     $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
     $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
     $this->assertTrue($c->exists(1, 1));
     $this->assertTrue($c->exists(2, 2));
     // We create a task
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
     // We move our task to the 2nd project
     $this->assertTrue($td->moveToProject(1, 2));
     // Check the values of the duplicated task
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['owner_id']);
     $this->assertEquals(2, $task['category_id']);
     $this->assertEquals(0, $task['swimlane_id']);
     $this->assertEquals(5, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('test', $task['title']);
 }
Example #9
0
 public function testCloneProjectWithActionTaskAssignColorCategory()
 {
     $p = new Project($this->container);
     $a = new Action($this->container);
     $c = new Category($this->container);
     $pd = new ProjectDuplication($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
     $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
     $this->assertEquals(1, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignColorCategory', 'params' => array('color_id' => 'blue', 'category_id' => 2))));
     $this->assertEquals(2, $pd->duplicate(1));
     $actions = $a->getAllByProject(2);
     $this->assertNotEmpty($actions);
     $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
     $this->assertNotEmpty($actions[0]['params']);
     $this->assertEquals('blue', $actions[0]['params'][0]['value']);
     $this->assertEquals(5, $actions[0]['params'][1]['value']);
 }
Example #10
0
    return $user->getAll();
});
$server->register('updateUser', function ($values) use($user) {
    list($valid, ) = $user->validateModification($values);
    return $valid && $user->update($values);
});
$server->register('removeUser', function ($user_id) use($user) {
    return $user->remove($user_id);
});
/**
 * Category procedures
 */
$server->register('createCategory', function ($project_id, $name) use($category) {
    $values = array('project_id' => $project_id, 'name' => $name);
    list($valid, ) = $category->validateCreation($values);
    return $valid && $category->create($values);
});
$server->register('getCategory', function ($category_id) use($category) {
    return $category->getById($category_id);
});
$server->register('getAllCategories', function ($project_id) use($category) {
    return $category->getAll($project_id);
});
$server->register('updateCategory', function ($id, $name) use($category) {
    $values = array('id' => $id, 'name' => $name);
    list($valid, ) = $category->validateModification($values);
    return $valid && $category->update($values);
});
$server->register('removeCategory', function ($category_id) use($category) {
    return $category->remove($category_id);
});
Example #11
0
 public function testDuplicateMixedResults()
 {
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $a = new Action($this->container);
     $u = new User($this->container);
     $c = new Category($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertEquals(2, $p->create(array('name' => 'P2')));
     $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
     $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
     $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertEquals(1, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2))));
     $action = $a->getById(1);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals(2, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignCategoryColor', 'params' => array('color_id' => 'blue', 'category_id' => 1))));
     $action = $a->getById(2);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals('category_id', $action['params'][1]['name']);
     $this->assertEquals(1, $action['params'][1]['value']);
     $actions = $a->getAllByProject(1);
     $this->assertNotEmpty($actions);
     $this->assertCount(2, $actions);
     $this->assertTrue($a->duplicate(1, 2));
     $actions = $a->getAllByProject(2);
     $this->assertNotEmpty($actions);
     $this->assertCount(1, $actions);
     $actions = $a->getAll();
     $this->assertNotEmpty($actions);
     $this->assertCount(3, $actions);
     $action = $a->getById($actions[2]['id']);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals('color_id', $action['params'][0]['name']);
     $this->assertEquals('blue', $action['params'][0]['value']);
     $this->assertEquals('category_id', $action['params'][1]['name']);
     $this->assertEquals(3, $action['params'][1]['value']);
 }
Example #12
0
 public function testDuplicateToAnotherProject()
 {
     $t = new Task($this->registry);
     $p = new Project($this->registry);
     $c = new Category($this->registry);
     // We create 2 projects
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2')));
     $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
     $this->assertTrue($c->exists(1, 1));
     // 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);
     // We duplicate our task to the 2nd project
     $this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
     $this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
     // Check the values of the duplicated task
     $task = $t->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['owner_id']);
     $this->assertEquals(0, $task['category_id']);
     $this->assertEquals(5, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('test', $task['title']);
 }