Esempio n. 1
0
 public function testGetTitle()
 {
     $wn = new WebNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $f = new File($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
     $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
     $task = $tf->getDetails(1);
     $subtask = $s->getById(1, true);
     $comment = $c->getById(1);
     $file = $c->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotEmpty($subtask);
     $this->assertNotEmpty($comment);
     $this->assertNotEmpty($file);
     foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
         $title = $wn->getTitleFromEvent($event_name, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array()));
         $this->assertNotEmpty($title);
     }
     $this->assertNotEmpty($wn->getTitleFromEvent(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
     $this->assertNotEmpty($wn->getTitleFromEvent('unkown', array()));
 }
Esempio n. 2
0
 public function testGetMailContent()
 {
     $en = new EmailNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $f = new File($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
     $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
     $task = $tf->getDetails(1);
     $subtask = $s->getById(1, true);
     $comment = $c->getById(1);
     $file = $c->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotEmpty($subtask);
     $this->assertNotEmpty($comment);
     $this->assertNotEmpty($file);
     foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) {
         $this->assertNotEmpty($en->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())));
         $this->assertNotEmpty($en->getMailSubject($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())));
     }
 }
Esempio n. 3
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']);
 }
Esempio n. 4
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']);
     }
 }
Esempio n. 5
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));
 }
 public function testSearchWithAssigneeIncludingSubtasks()
 {
     $p = new Project($this->container);
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $tf = new TaskFilter($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Paul Ryan')));
     $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 2)));
     $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'user_id' => 0)));
     $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'task2', 'owner_id' => 0)));
     $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 2, 'status' => 1, 'user_id' => 2)));
     $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'task3', 'owner_id' => 0)));
     $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 3, 'user_id' => 1)));
     $tf->search('assignee:bob');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(2, $tasks);
     $this->assertEquals('task1', $tasks[0]['title']);
     $this->assertEquals('task2', $tasks[1]['title']);
     $tf->search('assignee:"Paul Ryan"');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(2, $tasks);
     $this->assertEquals('task1', $tasks[0]['title']);
     $this->assertEquals('task2', $tasks[1]['title']);
     $tf->search('assignee:nobody');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(2, $tasks);
     $this->assertEquals('task2', $tasks[0]['title']);
     $this->assertEquals('task3', $tasks[1]['title']);
     $tf->search('assignee:admin');
     $tasks = $tf->findAll();
     $this->assertNotEmpty($tasks);
     $this->assertCount(1, $tasks);
     $this->assertEquals('task3', $tasks[0]['title']);
 }
 public function testGetCalendarEvents()
 {
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $st = new SubtaskTimeTracking($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2')));
     $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
     $this->assertEquals(2, $tc->create(array('title' => 'test 1', 'project_id' => 2)));
     $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->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
     $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2)));
     $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 2)));
     $this->assertEquals(6, $s->create(array('title' => 'subtask #6', 'task_id' => 2)));
     $this->assertEquals(7, $s->create(array('title' => 'subtask #7', 'task_id' => 2)));
     $this->assertEquals(8, $s->create(array('title' => 'subtask #8', 'task_id' => 2)));
     // Slot start before and finish inside the calendar time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 1, 'start' => strtotime('-1 day'), 'end' => strtotime('+1 hour')));
     // Slot start inside time range and finish after the time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 2, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 days')));
     // Start before time range and finish inside time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 3, 'start' => strtotime('-1 day'), 'end' => strtotime('+1.5 days')));
     // Start and finish inside time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 4, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 hours')));
     // Start and finish after the time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 5, 'start' => strtotime('+2 days'), 'end' => strtotime('+3 days')));
     // Start and finish before the time range
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 6, 'start' => strtotime('-2 days'), 'end' => strtotime('-1 day')));
     // Start before time range and not finished
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 7, 'start' => strtotime('-1 day')));
     // Start inside time range and not finish
     $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 8, 'start' => strtotime('+3200 seconds')));
     $timesheet = $st->getUserTimesheet(1);
     $this->assertNotEmpty($timesheet);
     $this->assertCount(8, $timesheet);
     $events = $st->getUserCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 day')));
     $this->assertNotEmpty($events);
     $this->assertCount(6, $events);
     $this->assertEquals(1, $events[0]['subtask_id']);
     $this->assertEquals(2, $events[1]['subtask_id']);
     $this->assertEquals(3, $events[2]['subtask_id']);
     $this->assertEquals(4, $events[3]['subtask_id']);
     $this->assertEquals(7, $events[4]['subtask_id']);
     $this->assertEquals(8, $events[5]['subtask_id']);
     $events = $st->getProjectCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 days')));
     $this->assertNotEmpty($events);
     $this->assertCount(3, $events);
     $this->assertEquals(1, $events[0]['subtask_id']);
     $this->assertEquals(2, $events[1]['subtask_id']);
     $this->assertEquals(3, $events[2]['subtask_id']);
     $events = $st->getProjectCalendarEvents(2, date('Y-m-d'), date('Y-m-d', strtotime('+2 days')));
     $this->assertNotEmpty($events);
     $this->assertCount(3, $events);
     $this->assertEquals(4, $events[0]['subtask_id']);
     $this->assertEquals(7, $events[1]['subtask_id']);
     $this->assertEquals(8, $events[2]['subtask_id']);
 }
Esempio n. 8
0
#!/usr/bin/env php
<?php 
require __DIR__ . '/../app/common.php';
use Model\TaskCreation;
use Model\Subtask;
use Model\Project;
use Model\ProjectPermission;
use Model\User;
$task_per_column = 200;
$userModel = new User($container);
$projectModel = new Project($container);
$permissionModel = new ProjectPermission($container);
$taskModel = new TaskCreation($container);
$subtaskModel = new Subtask($container);
$project_id = $projectModel->create(array('name' => 'Project #1'));
$permissionModel->addMember($project_id, 1);
for ($i = 0; $i <= 5; $i++) {
    $userModel->create(array('username' => 'user' . $i, 'password' => 'password' . $i, 'name' => 'User #' . $i, 'email' => 'user' . $i . '@localhost'));
}
foreach (array(1, 2, 3, 4) as $column_id) {
    for ($i = 1; $i <= $task_per_column; $i++) {
        $task = array('title' => 'Task #' . $i . '-' . $column_id, 'project_id' => 1, 'column_id' => $column_id, 'owner_id' => 1, 'color_id' => mt_rand(0, 1) === 0 ? 'green' : 'purple', 'score' => mt_rand(0, 21), 'is_active' => mt_rand(0, 1));
        $id = $taskModel->create($task);
        $subtaskModel->create(array('title' => 'Subtask of task #' . $id, 'user_id' => 1, 'status' => mt_rand(0, 2), 'task_id' => $id));
    }
}