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 testExecute()
 {
     $action = new 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 testExecute()
 {
     $action = new 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(new GenericEvent($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(new GenericEvent($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 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 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']);
 }
 public function testHandlePayload()
 {
     $w = new EmailHandler($this->container);
     $p = new Project($this->container);
     $pp = new ProjectUserRole($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('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo')));
     // Project not found
     $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo')));
     // User is not member
     $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
     $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
     // The task must be created
     $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-html' => '<strong>boo</strong>')));
     $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']);
 }
 public function testAverageWithTransitions()
 {
     $transitionModel = new Transition($this->container);
     $taskFinderModel = new TaskFinder($this->container);
     $taskCreationModel = new TaskCreation($this->container);
     $projectModel = new Project($this->container);
     $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container);
     $now = time();
     $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
     $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600));
     $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800));
     foreach (array(1, 2) as $task_id) {
         $task = $taskFinderModel->getById($task_id);
         $task['task_id'] = $task['id'];
         $task['date_moved'] = $now - 900;
         $task['src_column_id'] = 3;
         $task['dst_column_id'] = 1;
         $this->assertTrue($transitionModel->save(1, $task));
     }
     $stats = $averageLeadCycleTimeAnalytic->build(1);
     $expected = array(1 => array('count' => 2, 'time_spent' => 3600 + 1800, 'average' => (int) ((3600 + 1800) / 2), 'title' => 'Backlog'), 2 => array('count' => 0, 'time_spent' => 0, 'average' => 0, 'title' => 'Ready'), 3 => array('count' => 2, 'time_spent' => 1800, 'average' => 900, 'title' => 'Work in progress'), 4 => array('count' => 0, 'time_spent' => 0, 'average' => 0, 'title' => 'Done'));
     $this->assertEquals($expected, $stats);
 }
 public function testAssignCategory()
 {
     $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', 1);
     $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(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
     $task = $tf->getById(1);
     $this->assertEquals(0, $task['category_id']);
     $event = array('project_id' => 1, 'task_id' => 1, 'opposite_task_id' => 2, 'link_id' => 2);
     $this->assertTrue($action->execute(new TaskLinkEvent($event)));
     $task = $tf->getById(1);
     $this->assertEquals(1, $task['category_id']);
 }
Example #9
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']);
 }
 public function testClose()
 {
     $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(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days')));
     $tasks = $taskFinderModel->getAll(1);
     $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
     $action = new TaskCloseNoActivity($this->container);
     $action->setProjectId(1);
     $action->setParam('duration', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['is_active']);
     $task = $taskFinderModel->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['is_active']);
 }
 public function testExecute()
 {
     $action = new TaskUpdateStartDate($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)));
     // The start date must be empty
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEmpty($task['date_started']);
     // 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 updated
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(time(), $task['date_started'], '', 2);
 }
Example #12
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'], '', 1);
     // 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'], 'Bad completion timestamp', 1);
     $this->assertEquals(time(), $task['date_modification'], 'Bad modification timestamp', 1);
     // 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'], '', 1);
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey('task.close.TaskStatusTest::onTaskClose', $called);
     $this->assertArrayHasKey('task.open.TaskStatusTest::onTaskOpen', $called);
 }
 public function testExecute()
 {
     $action = new 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']);
 }
 public function testClose()
 {
     $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')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
     $action = new TaskClose($this->container);
     $action->setProjectId(1);
     $action->addEvent('test.event', 'Test Event');
     $this->assertTrue($action->execute($event, 'test.event'));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(0, $task['is_active']);
 }
 public function testSuccess()
 {
     $projectModel = new Project($this->container);
     $taskFinderModel = new TaskFinder($this->container);
     $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'title' => 'test123', 'reference' => 'ref123', 'description' => 'test'));
     $action = new TaskCreationAction($this->container);
     $action->setProjectId(1);
     $action->addEvent('test.event', 'Test Event');
     $this->assertTrue($action->execute($event, 'test.event'));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('test123', $task['title']);
     $this->assertEquals('ref123', $task['reference']);
     $this->assertEquals('test', $task['description']);
 }
 public function testChangeUser()
 {
     $this->container['sessionStorage']->user = array('id' => 1);
     $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')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
     $action = new TaskAssignCurrentUser($this->container);
     $action->setProjectId(1);
     $this->assertTrue($action->execute($event, Task::EVENT_CREATE));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['owner_id']);
 }
 public function testClose()
 {
     $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')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
     $action = new TaskUpdateStartDate($this->container);
     $action->setProjectId(1);
     $action->setParam('column_id', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(time(), $task['date_started'], 'Date started delta', 2);
 }
 public function testChangeColumn()
 {
     $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')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
     $action = new TaskAssignColorColumn($this->container);
     $action->setProjectId(1);
     $action->setParam('color_id', 'red');
     $action->setParam('column_id', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('red', $task['color_id']);
 }
 public function testColorChange()
 {
     $action = new 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']);
 }
 public function testSuccess()
 {
     $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(2, $projectModel->create(array('name' => 'test2')));
     $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
     $action = new TaskMoveColumnAssigned($this->container);
     $action->setProjectId(1);
     $action->setParam('src_column_id', 1);
     $action->setParam('dest_column_id', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('test', $task['title']);
     $this->assertEquals(2, $task['column_id']);
 }
 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 testSuccess()
 {
     $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(2, $projectModel->create(array('name' => 'test2')));
     $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
     $action = new TaskDuplicateAnotherProject($this->container);
     $action->setProjectId(1);
     $action->setParam('project_id', 2);
     $action->setParam('column_id', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
     $task = $taskFinderModel->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals('test', $task['title']);
     $this->assertEquals(2, $task['project_id']);
 }
 public function testExecute()
 {
     $action = new TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
     $action->setParam('column_id', 2);
     $action->setParam('user_id', 1);
     // 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 assigned to the user 1
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['owner_id']);
 }
 public function testChangeCategory()
 {
     $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, 'label' => 'foobar'));
     $action = new TaskAssignCategoryLabel($this->container);
     $action->setProjectId(1);
     $action->addEvent('test.event', 'Test Event');
     $action->setParam('label', 'foobar');
     $action->setParam('category_id', 1);
     $this->assertTrue($action->execute($event, 'test.event'));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['category_id']);
 }
Example #25
0
 public function testCreation()
 {
     $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)));
     $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
     $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
     $this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2))));
     $this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1))));
     $events = $e->getProject(1);
     $this->assertNotEmpty($events);
     $this->assertTrue(is_array($events));
     $this->assertEquals(2, count($events));
     $this->assertEquals(time(), $events[0]['date_creation'], '', 1);
     $this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']);
     $this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']);
 }
 public function testChangeUser()
 {
     $userModel = new User($this->container);
     $projectModel = new Project($this->container);
     $projectUserRoleModel = new ProjectUserRole($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', 'owner_id' => 0)));
     $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
     $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2));
     $action = new TaskAssignUser($this->container);
     $action->setProjectId(1);
     $action->addEvent('test.event', 'Test Event');
     $this->assertTrue($action->execute($event, 'test.event'));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['owner_id']);
 }
 public function testSuccess()
 {
     $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(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1));
     $action = new TaskMoveColumnCategoryChange($this->container);
     $action->setProjectId(1);
     $action->setParam('category_id', 1);
     $action->setParam('dest_column_id', 2);
     $this->assertTrue($action->execute($event, Task::EVENT_UPDATE));
     $task = $taskFinderModel->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals('test', $task['title']);
     $this->assertEquals(2, $task['column_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']);
 }
Example #29
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);
 }
Example #30
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));
 }