public function testExecute()
 {
     $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
     $action->setParam('user_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);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
     // We change the assignee
     $event = array('project_id' => 1, 'task_id' => 1, 'owner_id' => 5);
     // Our event should NOT be executed
     $this->assertFalse($action->execute(new GenericEvent($event)));
     // Our task should be assigned to nobody and have the green color
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['owner_id']);
     $this->assertEquals('green', $task['color_id']);
     // We change the assignee
     $event = array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1);
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
     // Our task should be assigned to nobody and have the blue color
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['owner_id']);
     $this->assertEquals('blue', $task['color_id']);
 }
Esempio n. 2
0
 public function testCalculateTime()
 {
     $tm = new TaskModification($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $s = new SubTask($this->container);
     $ts = new TimeTracking($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5)));
     $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 3.5)));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(4.5, $task['time_estimated']);
     $this->assertEquals(3.5, $task['time_spent']);
     $timesheet = $ts->getTaskTimesheet($task, array());
     $this->assertNotEmpty($timesheet);
     $this->assertEquals(4.5, $timesheet['time_estimated']);
     $this->assertEquals(3.5, $timesheet['time_spent']);
     $this->assertEquals(1, $timesheet['time_remaining']);
     // Subtasks calculation
     $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5.5, 'time_spent' => 3)));
     $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => 4)));
     $timesheet = $ts->getTaskTimesheet($task, $s->getAll(1));
     $this->assertNotEmpty($timesheet);
     $this->assertEquals(5.5, $timesheet['time_estimated']);
     $this->assertEquals(7, $timesheet['time_spent']);
     $this->assertEquals(-1.5, $timesheet['time_remaining']);
 }
 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']);
 }
Esempio n. 4
0
 public function testHandlePayload()
 {
     $w = new MailgunWebhook($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     // Empty payload
     $this->assertFalse($w->parsePayload(array()));
     // Unknown user
     $this->assertFalse($w->parsePayload(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo')));
     // Project not found
     $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo')));
     // User is not member
     $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
     $this->assertTrue($pp->addMember(2, 2));
     // The task must be created
     $this->assertTrue($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('boo', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }
Esempio n. 5
0
 public function testGetOverdueTasksByUser()
 {
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
     $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
     $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
     $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
     $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
     $tasks = $tf->getOverdueTasksByUser(1);
     $this->assertNotEmpty($tasks);
     $this->assertTrue(is_array($tasks));
     $this->assertEquals(2, count($tasks));
     $this->assertEquals(1, $tasks[0]['id']);
     $this->assertEquals('Task #1', $tasks[0]['title']);
     $this->assertEquals(1, $tasks[0]['owner_id']);
     $this->assertEquals(1, $tasks[0]['project_id']);
     $this->assertEquals('Project #1', $tasks[0]['project_name']);
     $this->assertEquals('admin', $tasks[0]['assignee_username']);
     $this->assertEquals('', $tasks[0]['assignee_name']);
     $this->assertEquals('Task #2', $tasks[1]['title']);
 }
Esempio n. 6
0
 public function testCleanup()
 {
     $e = new ProjectActivity($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
     $max = 15;
     $nb_events = 100;
     for ($i = 0; $i < $nb_events; $i++) {
         $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
     }
     $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
     $e->cleanup($max);
     $events = $e->getProject(1);
     $this->assertNotEmpty($events);
     $this->assertTrue(is_array($events));
     $this->assertEquals($max, count($events));
     $this->assertEquals(100, $events[0]['id']);
     $this->assertEquals(99, $events[1]['id']);
     $this->assertEquals(86, $events[14]['id']);
     // Cleanup during task creation
     $nb_events = ProjectActivity::MAX_EVENTS + 10;
     for ($i = 0; $i < $nb_events; $i++) {
         $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
     }
     $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count());
 }
 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\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'project 1')));
     $this->assertEquals(2, $p->create(array('name' => 'project 2')));
     $this->assertEquals(1, $tc->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 = $tf->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 = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
 }
 public function testMoveTaskAnotherSwimlane()
 {
     $tp = new TaskPosition($this->container);
     $tc = new TaskCreation($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $s = new Swimlane($this->container);
     $this->container['dispatcher'] = new EventDispatcher();
     $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
     $now = time();
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
     $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals($now, $task['date_moved'], '', 1);
     $this->assertEquals(1, $task['column_id']);
     $this->assertEquals(0, $task['swimlane_id']);
     sleep(1);
     $this->assertTrue($tp->movePosition(1, 1, 2, 1, 2));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotEquals($now, $task['date_moved']);
     $this->assertEquals(2, $task['column_id']);
     $this->assertEquals(2, $task['swimlane_id']);
 }
Esempio n. 10
0
 public function testStatus()
 {
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $ts = new TaskStatus($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     // The task must be open
     $this->assertTrue($ts->isOpen(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
     $this->assertEquals(0, $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     // We close the task
     $this->assertTrue($ts->close(1));
     $this->assertTrue($ts->isClosed(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']);
     $this->assertEquals(time(), $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
     // We open the task again
     $this->assertTrue($ts->open(1));
     $this->assertTrue($ts->isOpen(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
     $this->assertEquals(0, $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_OPEN));
 }
Esempio n. 11
0
 public function testHtml2Markdown()
 {
     $w = new Postmark($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }
Esempio n. 12
0
 public function testHandlePayload()
 {
     $w = new Sendgrid($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     // Empty payload
     $this->assertFalse($w->receiveEmail(array()));
     // Unknown user
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', 'subject' => 'Email task')));
     // Project not found
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', 'subject' => 'Email task')));
     // User is not member
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $this->assertTrue($pp->addMember(2, 2));
     // The task must be created
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> text')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'text' => '**bold** text')));
     $task = $tf->getById(3);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text + html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> html', 'text' => '**bold** text')));
     $task = $tf->getById(4);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** html', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }
Esempio n. 13
0
 public function testSendWithoutEmailAddress()
 {
     $en = new EmailNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $u = new User($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->container['emailClient'] = $this->getMockBuilder('\\Core\\EmailClient')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock();
     $this->container['emailClient']->expects($this->never())->method('send');
     $en->send($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
 }
Esempio n. 14
0
 public function testCountByProject()
 {
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
     $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2)));
     $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));
     $this->assertEquals(1, $tf->countByProjectId(1));
     $this->assertEquals(2, $tf->countByProjectId(2));
 }
Esempio n. 15
0
 public function testGetTaskWithMultipleMilestoneLink()
 {
     $tf = new TaskFinder($this->container);
     $tl = new TaskLink($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
     $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
     $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
     $this->assertNotFalse($tl->create(1, 2, 9));
     $this->assertNotFalse($tl->create(1, 3, 9));
     $task = $tf->getExtendedQuery()->findOne();
     $this->assertNotEmpty($task);
 }
Esempio n. 16
0
 public function testGetOverdueTasks()
 {
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
     $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
     $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
     $this->assertEquals(4, $tc->create(array('title' => 'Task #3', 'project_id' => 1)));
     $tasks = $tf->getOverdueTasks();
     $this->assertNotEmpty($tasks);
     $this->assertTrue(is_array($tasks));
     $this->assertEquals(1, count($tasks));
     $this->assertEquals('Task #1', $tasks[0]['title']);
 }
 public function testColorChange()
 {
     $action = new Action\TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN);
     $action->setParam('column_id', 2);
     $action->setParam('color_id', 'green');
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow')));
     $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'color_id' => 'green');
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
     // Our task should have color green
     $task = $tf->getById(1);
     $this->assertEquals('green', $task['color_id']);
 }
Esempio n. 18
0
 public function testExecute()
 {
     $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN);
     $action->setParam('column_id', 2);
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->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(new GenericEvent($event)));
     // Our task should be closed
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['is_active']);
 }
Esempio n. 19
0
 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']);
 }
Esempio n. 20
0
 public function testHandleIssueClosed()
 {
     $g = new GitlabWebhook($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $g->setProjectId(1);
     $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose'));
     $event = json_decode($this->issue_closed_payload, true);
     // Issue not there
     $this->assertFalse($g->handleIssueClosed($event['object_attributes']));
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertEmpty($called);
     // Create a task with the issue reference
     $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 103361)));
     $task = $tf->getByReference(103361);
     $this->assertNotEmpty($task);
     $this->assertTrue($g->handleIssueClosed($event['object_attributes']));
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_CLOSED . '.GitlabWebhookTest::onClose', $called);
 }
 public function testExecute()
 {
     $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
     $action->setParam('column_id', 2);
     $_SESSION = array('user' => array('id' => 5));
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $us = new UserSession($this->container);
     $this->assertEquals(5, $us->getId());
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->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(new GenericEvent($event)));
     // Our task should be assigned to the user 5 (from the session)
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(5, $task['owner_id']);
 }
Esempio n. 22
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']);
 }
Esempio n. 23
0
 public function testStatus()
 {
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $ts = new TaskStatus($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     // The task must be open
     $this->assertTrue($ts->isOpen(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
     $this->assertEquals(0, $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     // We close the task
     $this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose'));
     $this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen'));
     $this->assertTrue($ts->close(1));
     $this->assertTrue($ts->isClosed(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']);
     $this->assertEquals(time(), $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     // We open the task again
     $this->assertTrue($ts->open(1));
     $this->assertTrue($ts->isOpen(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
     $this->assertEquals(0, $task['date_completed']);
     $this->assertEquals(time(), $task['date_modification']);
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey('task.close.TaskStatusTest::onTaskClose', $called);
     $this->assertArrayHasKey('task.open.TaskStatusTest::onTaskOpen', $called);
 }
 public function testExecute()
 {
     $action = new Action\TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
     $action->setParam('link_id', 2);
     $action->setParam('color_id', 'green');
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $tl = new TaskLink($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     // The color should be yellow
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('yellow', $task['color_id']);
     $event = array('project_id' => 1, 'task_id' => 1, 'link_id' => 2);
     // Our event should be executed
     $this->assertTrue($action->execute(new TaskLinkEvent($event)));
     // The color should be green
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('green', $task['color_id']);
 }
Esempio n. 25
0
 public function testDuplicateRecurringTask()
 {
     $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);
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'date_due' => 1436561776, 'recurrence_status' => Task::RECURRING_STATUS_PENDING, 'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE, 'recurrence_factor' => 2, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE)));
     $this->assertEquals(2, $td->duplicateRecurringTask(1));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
     $this->assertEquals(2, $task['recurrence_child']);
     $this->assertEquals(1436561776, $task['date_due'], '', 2);
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']);
     $this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
     $this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
     $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
     $this->assertEquals(1, $task['recurrence_parent']);
     $this->assertEquals(2, $task['recurrence_factor']);
     $this->assertEquals(strtotime('+2 days'), $task['date_due'], '', 2);
 }
Esempio n. 26
0
 public function testGetAll()
 {
     $wn = new WebNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $u = new User($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $wn->send($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
     $wn->send($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
     $this->assertEmpty($wn->getAll(2));
     $notifications = $wn->getAll(1);
     $this->assertCount(2, $notifications);
     $this->assertArrayHasKey('title', $notifications[0]);
     $this->assertTrue(is_array($notifications[0]['event_data']));
 }
Esempio n. 27
0
 public function testGetBoardWithSwimlane()
 {
     $b = new Board($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $s = new Swimlane($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $s->create(1, 'test 1'));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
     $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 3)));
     $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
     $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 3)));
     $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 4)));
     $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 4, 'swimlane_id' => 1)));
     $board = $b->getBoard(1);
     $this->assertNotEmpty($board);
     $this->assertEquals(2, count($board));
     $this->assertEquals(5, count($board[0]));
     $this->assertTrue(array_key_exists('nb_tasks', $board[0]));
     $this->assertTrue(array_key_exists('name', $board[0]));
     $this->assertTrue(array_key_exists('columns', $board[0]));
     $this->assertTrue(array_key_exists('tasks', $board[0]['columns'][2]));
     $this->assertTrue(array_key_exists('title', $board[0]['columns'][2]));
     $task = $tf->getById(1);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(1, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(0, $task['swimlane_id']);
     $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['id']);
     $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['column_id']);
     $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['position']);
     $this->assertEquals(0, $board[0]['columns'][0]['tasks'][0]['swimlane_id']);
     $task = $tf->getById(2);
     $this->assertEquals(2, $task['id']);
     $this->assertEquals(3, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(0, $task['swimlane_id']);
     $this->assertEquals(2, $board[0]['columns'][2]['tasks'][0]['id']);
     $this->assertEquals(3, $board[0]['columns'][2]['tasks'][0]['column_id']);
     $this->assertEquals(1, $board[0]['columns'][2]['tasks'][0]['position']);
     $this->assertEquals(0, $board[0]['columns'][2]['tasks'][0]['swimlane_id']);
     $task = $tf->getById(3);
     $this->assertEquals(3, $task['id']);
     $this->assertEquals(2, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(1, $task['swimlane_id']);
     $this->assertEquals(3, $board[1]['columns'][1]['tasks'][0]['id']);
     $this->assertEquals(2, $board[1]['columns'][1]['tasks'][0]['column_id']);
     $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['position']);
     $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['swimlane_id']);
     $task = $tf->getById(4);
     $this->assertEquals(4, $task['id']);
     $this->assertEquals(3, $task['column_id']);
     $this->assertEquals(2, $task['position']);
     $this->assertEquals(0, $task['swimlane_id']);
     $this->assertEquals(4, $board[0]['columns'][2]['tasks'][1]['id']);
     $this->assertEquals(3, $board[0]['columns'][2]['tasks'][1]['column_id']);
     $this->assertEquals(2, $board[0]['columns'][2]['tasks'][1]['position']);
     $this->assertEquals(0, $board[0]['columns'][2]['tasks'][1]['swimlane_id']);
     $task = $tf->getById(5);
     $this->assertEquals(5, $task['id']);
     $this->assertEquals(4, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(0, $task['swimlane_id']);
     $this->assertEquals(5, $board[0]['columns'][3]['tasks'][0]['id']);
     $this->assertEquals(4, $board[0]['columns'][3]['tasks'][0]['column_id']);
     $this->assertEquals(1, $board[0]['columns'][3]['tasks'][0]['position']);
     $this->assertEquals(0, $board[0]['columns'][3]['tasks'][0]['swimlane_id']);
     $task = $tf->getById(6);
     $this->assertEquals(6, $task['id']);
     $this->assertEquals(4, $task['column_id']);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(1, $task['swimlane_id']);
     $this->assertEquals(6, $board[1]['columns'][3]['tasks'][0]['id']);
     $this->assertEquals(4, $board[1]['columns'][3]['tasks'][0]['column_id']);
     $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['position']);
     $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['swimlane_id']);
 }
 public function testChangeTimeSpent()
 {
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tm = new TaskModification($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $task = $tf->getById(1);
     $this->assertEquals(0, $task['time_spent']);
     $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 13.3)));
     $task = $tf->getById(1);
     $this->assertEquals(13.3, $task['time_spent']);
 }
Esempio n. 29
0
 public function testRemove()
 {
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
     $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
     $task = $tf->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 = $tf->getById(1);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(0, $task['owner_id']);
     // Make sure that assigned subtasks are unassigned after removing the user
     $subtask = $s->getById(1);
     $this->assertEquals(1, $subtask['id']);
     $this->assertEquals(0, $subtask['user_id']);
     // Make sure that comments are not related to the user anymore
     $comment = $c->getById(1);
     $this->assertEquals(1, $comment['id']);
     $this->assertEquals(0, $comment['user_id']);
     // Make sure that private projects are also removed
     $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
     $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
     $this->assertNotFalse($user_id1);
     $this->assertNotFalse($user_id2);
     $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
     $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
     $this->assertTrue($u->remove($user_id1));
     $this->assertNotEmpty($p->getById(1));
     $this->assertNotEmpty($p->getById(3));
     $this->assertEmpty($p->getById(2));
 }
Esempio n. 30
0
 public function testScore()
 {
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotFalse($task);
     $this->assertEquals(3, $task['score']);
 }