public function testGetMailContent() { $en = new Mail($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 TaskFile($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 (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()))); } }
public function testGetTitle() { $wn = new Notification($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 TaskFile($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 (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) { $title = $wn->getTitleWithoutAuthor($event_name, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())); $this->assertNotEmpty($title); $title = $wn->getTitleWithAuthor('foobar', $event_name, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())); $this->assertNotEmpty($title); } $this->assertNotEmpty($wn->getTitleWithoutAuthor(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); $this->assertNotEmpty($wn->getTitleWithoutAuthor('unkown', array())); }
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)); }
public function testSuccess() { $this->container['sessionStorage']->user = array('id' => 1); $projectModel = new Project($this->container); $commentModel = new Comment($this->container); $taskCreationModel = new TaskCreation($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 CommentCreationMoveTaskColumn($this->container); $action->setProjectId(1); $action->setParam('column_id', 2); $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals(1, $comment['task_id']); $this->assertEquals(1, $comment['user_id']); $this->assertEquals('Moved to column Ready', $comment['comment']); }
public function testWithNoUser() { $action = new 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']); }
public function testWithUserNotAssignable() { $userModel = new User($this->container); $projectModel = new Project($this->container); $projectUserRoleModel = new ProjectUserRole($this->container); $commentModel = new Comment($this->container); $taskCreationModel = new TaskCreation($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'user_id' => 2)); $action = new CommentCreation($this->container); $action->setProjectId(1); $action->addEvent('test.event', 'Test Event'); $this->assertTrue($action->execute($event, 'test.event')); $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals(1, $comment['task_id']); $this->assertEquals('test123', $comment['comment']); $this->assertEquals('', $comment['reference']); $this->assertEquals(0, $comment['user_id']); }
public function testCommentCreation() { $c = new Config($this->container); $p = new Project($this->container); $tc = new TaskCreation($this->container); $cm = new Comment($this->container); $this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container)); $c->save(array('webhook_url' => 'http://localhost/comment')); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1))); $this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl()); $event = $this->container['httpClient']->getData(); $this->assertNotEmpty($event); $this->assertArrayHasKey('event_name', $event); $this->assertArrayHasKey('event_data', $event); $this->assertEquals('comment.create', $event['event_name']); $this->assertNotEmpty($event['event_data']); $this->assertArrayHasKey('task_id', $event['event_data']['comment']); $this->assertArrayHasKey('user_id', $event['event_data']['comment']); $this->assertArrayHasKey('comment', $event['event_data']['comment']); $this->assertArrayHasKey('id', $event['event_data']['comment']); $this->assertEquals('test comment', $event['event_data']['comment']['comment']); }
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 testValidateModification() { $c = new Comment($this->container); $result = $c->validateModification(array('id' => 1, 'comment' => 'bla')); $this->assertTrue($result[0]); $result = $c->validateModification(array('id' => 1, 'comment' => '')); $this->assertFalse($result[0]); $result = $c->validateModification(array('comment' => 'bla')); $this->assertFalse($result[0]); $result = $c->validateModification(array('id' => 'b', 'comment' => 'bla')); $this->assertFalse($result[0]); $result = $c->validateModification(array()); $this->assertFalse($result[0]); }