Пример #1
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']);
 }
Пример #2
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']);
 }
Пример #3
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']);
 }
Пример #4
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']);
 }