public function testExecute() { $action = new 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', 'project_id' => 1))); $this->assertEquals(2, $c->create(array('name' => 'c2', 'project_id' => 1))); $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(new GenericEvent($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(new GenericEvent($event))); // Our task should have the blue color $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals('blue', $task['color_id']); }
public function testThatExistingCategoryWillNotChange() { $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); $action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE); $action->setParam('category_id', 2); $action->setParam('link_id', 2); $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(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1))); $event = array('project_id' => 1, 'task_id' => 1, 'opposite_task_id' => 2, 'link_id' => 2); $this->assertFalse($action->execute(new TaskLinkEvent($event))); }
public function testExecute() { $action = new 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']); }
public function testWithExistingCategory() { $categoryModel = new Category($this->container); $projectModel = new Project($this->container); $taskCreationModel = new TaskCreation($this->container); $taskFinderModel = new TaskFinder($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 2))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'label' => 'foobar', 'category_id' => 2)); $action = new TaskAssignCategoryLabel($this->container); $action->setProjectId(1); $action->addEvent('test.event', 'Test Event'); $action->setParam('label', 'foobar'); $action->setParam('category_id', 1); $this->assertFalse($action->execute($event, 'test.event')); }
public function testWithWrongCategory() { $projectModel = new Project($this->container); $taskCreationModel = new TaskCreation($this->container); $taskFinderModel = new TaskFinder($this->container); $categoryModel = new Category($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2)); $action = new TaskMoveColumnCategoryChange($this->container); $action->setProjectId(1); $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); }
public function testRemove() { $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' => '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, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); $task = $tf->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 = $tf->getById(1); $this->assertTrue(is_array($task)); $this->assertEquals(0, $task['category_id']); }
public function testExport() { $tc = new TaskCreation($this->container); $p = new Project($this->container); $c = new Category($this->container); $e = new TaskExport($this->container); $s = new Swimlane($this->container); $this->assertEquals(1, $p->create(array('name' => 'Export Project'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $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), 'swimlane_id' => rand(0, 2)); $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][12]); $this->assertTrue(in_array($rows[$i - 1][4], array('Default swimlane', 'S1', 'S2'))); }
public function testWithWrongColor() { $categoryModel = new Category($this->container); $projectModel = new Project($this->container); $taskCreationModel = new TaskCreation($this->container); $taskFinderModel = new TaskFinder($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'blue')); $action = new TaskAssignCategoryColor($this->container); $action->setProjectId(1); $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); }
public function testChangeColor() { $categoryModel = new Category($this->container); $projectModel = new Project($this->container); $taskCreationModel = new TaskCreation($this->container); $taskFinderModel = new TaskFinder($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 1)); $action = new TaskAssignColorCategory($this->container); $action->setProjectId(1); $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); $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(6, $task['column_id']); $this->assertEquals(1, $task['position']); $this->assertEquals(2, $task['project_id']); $this->assertEquals('test', $task['title']); }
public function testDuplicate() { $projectModel = new Project($this->container); $categoryModel = new Category($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); $this->assertTrue($categoryModel->duplicate(1, 2)); $category = $categoryModel->getById(1); $this->assertEquals('Category #1', $category['name']); $this->assertEquals(1, $category['project_id']); $this->assertEquals('test', $category['description']); $category = $categoryModel->getById(2); $this->assertEquals('Category #1', $category['name']); $this->assertEquals(2, $category['project_id']); $this->assertEquals('test', $category['description']); }
public function testDuplicateWithCategoryParameterButNotFound() { $projectModel = new Project($this->container); $actionModel = new Action($this->container); $categoryModel = new Category($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); $this->assertEquals(1, $actionModel->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => '\\Kanboard\\Action\\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1)))); $this->assertTrue($actionModel->duplicate(1, 2)); $actions = $actionModel->getAllByProject(2); $this->assertCount(0, $actions); }
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']); $this->assertEquals('Feature request', $tasks[0]['category_name']); $tf->search('category:"hé hé"'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('task3', $tasks[0]['title']); $this->assertEquals('hé hé', $tasks[0]['category_name']); $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('Feature request', $tasks[0]['category_name']); $this->assertEquals('task3', $tasks[1]['title']); $this->assertEquals('hé hé', $tasks[1]['category_name']); $tf->search('category:none'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('task1', $tasks[0]['title']); $this->assertEquals('', $tasks[0]['category_name']); $tf->search('category:"not found"'); $tasks = $tf->findAll(); $this->assertEmpty($tasks); }
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']); }
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']); }