Exemplo n.º 1
0
 public function testHtml2Markdown()
 {
     $w = new EmailHandler($this->container);
     $p = new ProjectModel($this->container);
     $pp = new ProjectUserRoleModel($this->container);
     $u = new UserModel($this->container);
     $tf = new TaskFinderModel($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**boo**', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }
Exemplo n.º 2
0
 public function testHandlePayload()
 {
     $w = new EmailHandler($this->container);
     $p = new ProjectModel($this->container);
     $pp = new ProjectUserRoleModel($this->container);
     $u = new UserModel($this->container);
     $tf = new TaskFinderModel($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']);
 }
Exemplo n.º 3
0
 public function testHandlePayload()
 {
     $w = new EmailHandler($this->container);
     $p = new ProjectModel($this->container);
     $pp = new ProjectUserRoleModel($this->container);
     $u = new UserModel($this->container);
     $tf = new TaskFinderModel($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
     // Empty payload
     $this->assertFalse($w->receiveEmail(array()));
     // Unknown user
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', 'subject' => 'Email task')));
     // Project not found
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', 'subject' => 'Email task')));
     // User is not member
     $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
     // The task must be created
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task')));
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> text')));
     $task = $tf->getById(2);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'text' => '**bold** text')));
     $task = $tf->getById(3);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** text', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
     // Text + html content
     $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> html', 'text' => '**bold** text')));
     $task = $tf->getById(4);
     $this->assertNotEmpty($task);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals('Email task', $task['title']);
     $this->assertEquals('**bold** html', $task['description']);
     $this->assertEquals(2, $task['creator_id']);
 }
Exemplo n.º 4
0
 public function testNotifyProjectWithWebhookNotConfigured()
 {
     $this->container['httpClient']->expects($this->never())->method('postFormAsync');
     $projectModel = new ProjectModel($this->container);
     $taskCreationModel = new TaskCreationModel($this->container);
     $taskFinderModel = new TaskFinderModel($this->container);
     $handler = new RocketChat($this->container);
     $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
     $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $this->container['projectMetadataModel']->save(1, array('rocketchat_webhook_url' => ''));
     $project = $projectModel->getById(1);
     $task = $taskFinderModel->getDetails(1);
     $event = array('task' => $task);
     $event['task']['task_id'] = $task['id'];
     $handler->notifyProject($project, TaskModel::EVENT_MOVE_COLUMN, $event);
 }
 public function testHandlePush()
 {
     $this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onCommit'));
     $tc = new TaskCreationModel($this->container);
     $p = new ProjectModel($this->container);
     $handler = new WebhookHandler($this->container);
     $payload = json_decode(file_get_contents(__DIR__ . '/fixtures/push.json'), true);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $handler->setProjectId(1);
     // No task
     $this->assertFalse($handler->parsePayload('push', $payload));
     // Create task with the wrong id
     $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1)));
     $this->assertFalse($handler->parsePayload('push', $payload));
     // Create task with the right id
     $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1)));
     $this->assertTrue($handler->parsePayload('push', $payload));
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey(WebhookHandler::EVENT_COMMIT . '.WebhookHandlerTest::onCommit', $called);
 }
 public function testCommentCreatedWithUser()
 {
     $this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser'));
     $p = new ProjectModel($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'foobar')));
     $tc = new TaskCreationModel($this->container);
     $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1268888, 'project_id' => 1)));
     $u = new UserModel($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'kanboard')));
     $pp = new ProjectUserRoleModel($this->container);
     $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
     $g = new WebhookHandler($this->container);
     $g->setProjectId(1);
     $this->assertNotFalse($g->parsePayload(json_decode(file_get_contents(__DIR__ . '/fixtures/gitlab_comment_created.json'), true)));
 }
 public function testPush()
 {
     $this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onPush'));
     $p = new ProjectModel($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'foobar')));
     $tc = new TaskCreationModel($this->container);
     $this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1)));
     $g = new WebhookHandler($this->container);
     $g->setProjectId(1);
     $this->assertNotFalse($g->parsePayload('push', json_decode(file_get_contents(__DIR__ . '/fixtures/github_push.json'), true)));
 }
 public function testIssueAssignedWithNoTask()
 {
     $this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_ASSIGNEE_CHANGE, function () {
     });
     $p = new ProjectModel($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'foobar')));
     $tc = new TaskCreationModel($this->container);
     $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1)));
     $g = new WebhookHandler($this->container);
     $g->setProjectId(1);
     $this->assertFalse($g->parsePayload('issue:updated', json_decode(file_get_contents(__DIR__ . '/fixtures/bitbucket_issue_assigned.json'), true)));
     $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
 }