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 #2
0
 public function testSingleAction()
 {
     $tp = new TaskPosition($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $board = new Board($this->container);
     $project = new Project($this->container);
     $action = new Action($this->container);
     // We create a project
     $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
     // We create a new action
     $this->assertEquals(1, $action->create(array('project_id' => 1, 'event_name' => Task::EVENT_MOVE_COLUMN, 'action_name' => 'TaskClose', 'params' => array('column_id' => 4))));
     // We create a task
     $this->assertEquals(1, $tc->create(array('title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', 'column_id' => 1)));
     // We attach events
     $action->attachEvents();
     // Our task should be open
     $t1 = $tf->getById(1);
     $this->assertEquals(1, $t1['is_active']);
     $this->assertEquals(1, $t1['column_id']);
     // We move our task
     $tp->movePosition(1, 1, 4, 1);
     // Our task should be closed
     $t1 = $tf->getById(1);
     $this->assertEquals(4, $t1['column_id']);
     $this->assertEquals(0, $t1['is_active']);
 }
 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']);
 }
 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());
 }
Example #5
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));
 }
 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']);
 }
Example #9
0
 public function testDuplicate()
 {
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $p = new Project($this->container);
     // We create a project
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     // We create 2 tasks
     $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
     $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
     // We create many subtasks for the first task
     $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
     $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
     // We duplicate our subtasks
     $this->assertTrue($s->duplicate(1, 2));
     $subtasks = $s->getAll(2);
     $this->assertNotFalse($subtasks);
     $this->assertNotEmpty($subtasks);
     $this->assertEquals(2, count($subtasks));
     $this->assertEquals('subtask #1', $subtasks[0]['title']);
     $this->assertEquals('subtask #2', $subtasks[1]['title']);
     $this->assertEquals(2, $subtasks[0]['task_id']);
     $this->assertEquals(2, $subtasks[1]['task_id']);
     $this->assertEquals(5, $subtasks[0]['time_estimated']);
     $this->assertEquals(0, $subtasks[1]['time_estimated']);
     $this->assertEquals(0, $subtasks[0]['time_spent']);
     $this->assertEquals(0, $subtasks[1]['time_spent']);
     $this->assertEquals(0, $subtasks[0]['status']);
     $this->assertEquals(0, $subtasks[1]['status']);
     $this->assertEquals(0, $subtasks[0]['user_id']);
     $this->assertEquals(0, $subtasks[1]['user_id']);
 }
 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 testFormat()
 {
     $dp = new DateParser($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFilterGanttFormatter($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
     $this->assertNotEmpty($tf->search('status:open')->format());
 }
Example #12
0
 public function testRemove()
 {
     $t = new Task($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
     $this->assertTrue($t->remove(1));
     $this->assertFalse($t->remove(1234));
 }
Example #13
0
 public function validateRemove()
 {
     $c = new Comment($this->container);
     $tc = new TaskCreation($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
     $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
     $this->assertTrue($c->remove(1));
     $this->assertFalse($c->remove(1));
     $this->assertFalse($c->remove(1111));
 }
Example #14
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)));
 }
Example #15
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));
 }
 public function testUpdateTotals()
 {
     $p = new Project($this->container);
     $pds = new ProjectDailyColumnStats($this->container);
     $tc = new TaskCreation($this->container);
     $ts = new TaskStatus($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     $this->assertEquals(0, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
     for ($i = 0; $i < 10; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 1)));
     }
     for ($i = 0; $i < 5; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 4)));
     }
     $pds->updateTotals(1, date('Y-m-d', strtotime('-2days')));
     for ($i = 0; $i < 15; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 3)));
     }
     for ($i = 0; $i < 25; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 2)));
     }
     $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day')));
     $this->assertNotFalse($ts->close(1));
     $this->assertNotFalse($ts->close(2));
     for ($i = 0; $i < 3; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 3)));
     }
     for ($i = 0; $i < 5; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 2)));
     }
     for ($i = 0; $i < 4; $i++) {
         $this->assertNotFalse($tc->create(array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 4)));
     }
     $pds->updateTotals(1, date('Y-m-d'));
     $this->assertEquals(3, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
     $metrics = $pds->getAggregatedMetrics(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'));
     $this->assertNotEmpty($metrics);
     $this->assertEquals(4, count($metrics));
     $this->assertEquals(5, count($metrics[0]));
     $this->assertEquals('Date', $metrics[0][0]);
     $this->assertEquals('Backlog', $metrics[0][1]);
     $this->assertEquals('Ready', $metrics[0][2]);
     $this->assertEquals('Work in progress', $metrics[0][3]);
     $this->assertEquals('Done', $metrics[0][4]);
     $this->assertEquals(date('Y-m-d', strtotime('-2days')), $metrics[1][0]);
     $this->assertEquals(10, $metrics[1][1]);
     $this->assertEquals(0, $metrics[1][2]);
     $this->assertEquals(0, $metrics[1][3]);
     $this->assertEquals(5, $metrics[1][4]);
     $this->assertEquals(date('Y-m-d', strtotime('-1day')), $metrics[2][0]);
     $this->assertEquals(10, $metrics[2][1]);
     $this->assertEquals(25, $metrics[2][2]);
     $this->assertEquals(15, $metrics[2][3]);
     $this->assertEquals(5, $metrics[2][4]);
     $this->assertEquals(date('Y-m-d'), $metrics[3][0]);
     $this->assertEquals(10, $metrics[3][1]);
     $this->assertEquals(30, $metrics[3][2]);
     $this->assertEquals(18, $metrics[3][3]);
     $this->assertEquals(9, $metrics[3][4]);
 }
Example #17
0
 public function testCreationFileNameTooLong()
 {
     $p = new Project($this->container);
     $f = new File($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' => 'test')));
     $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10));
     $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10));
     $files = $f->getAll(1);
     $this->assertNotEmpty($files);
     $this->assertCount(2, $files);
     $this->assertEquals(str_repeat('a', 255), $files[0]['name']);
     $this->assertEquals('test', $files[1]['name']);
 }
Example #18
0
 public function testRemove()
 {
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($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)));
     $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 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));
 }
Example #19
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 testParsePayload()
 {
     $g = new BitbucketWebhook($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, function () {
     });
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $g->setProjectId(1);
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $event = json_decode($this->post_payload, true);
     $this->assertTrue($g->parsePayload($event));
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT . '.closure', $called);
 }
Example #21
0
 public function testThatAllSubtasksAreClosed()
 {
     $ts = new TaskStatus($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
     $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
     $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
     $this->assertTrue($ts->close(1));
     $subtasks = $s->getAll(1);
     $this->assertNotEmpty($subtasks);
     foreach ($subtasks as $subtask) {
         $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
     }
 }
 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']);
 }
Example #23
0
 public function testIsLastModified()
 {
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $now = time();
     $p->attachEvents();
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     $project = $p->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals($now, $project['last_modified']);
     sleep(1);
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
     $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
     $this->assertEquals('Event\\ProjectModificationDateListener', $this->container['event']->getLastListenerExecuted());
     $project = $p->getById(1);
     $this->assertNotEmpty($project);
     $this->assertTrue($p->isModifiedSince(1, $now));
 }
Example #24
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']);
 }
Example #25
0
 public function testRemove()
 {
     $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->assertTrue($tl->create(1, 2, 2));
     $links = $tl->getLinks(1);
     $this->assertNotEmpty($links);
     $links = $tl->getLinks(2);
     $this->assertNotEmpty($links);
     $this->assertTrue($tl->remove($links[0]['id']));
     $links = $tl->getLinks(1);
     $this->assertEmpty($links);
     $links = $tl->getLinks(2);
     $this->assertEmpty($links);
 }
 public function testWithNoUser()
 {
     $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $p = new Project($this->container);
     $c = new Comment($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, 'user_id' => 0, 'comment' => 'youpi');
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
     $comment = $c->getById(1);
     $this->assertNotEmpty($comment);
     $this->assertEquals(1, $comment['task_id']);
     $this->assertEquals(0, $comment['user_id']);
     $this->assertEquals('youpi', $comment['comment']);
 }
Example #27
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]);
 }
Example #28
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']);
 }
Example #29
0
 public function testTaskClose()
 {
     $action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE);
     $action->setParam('column_id', 2);
     $action->setParam('user_id', 1);
     $action->setParam('subject', 'My email subject');
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($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, 'column_id' => 1)));
     $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost')));
     // We create an event
     $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2);
     // Email should be sent
     $this->container['emailClient']->expects($this->once())->method('send')->with($this->equalTo('admin@localhost'), $this->equalTo('admin'), $this->equalTo('My email subject'), $this->stringContains('test'));
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
 }
Example #30
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']);
 }