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']); }
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']); }
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']); }
public function testNotifyUserWithWebhookNotConfigured() { $this->container['userMetadataModel']->save(1, array('rocketchat_webhook_url' => '')); $this->container['httpClient']->expects($this->never())->method('postFormAsync'); $userModel = new UserModel($this->container); $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'))); $user = $userModel->getById(1); $task = $taskFinderModel->getDetails(1); $event = array('task' => $task); $event['task']['task_id'] = $task['id']; $handler->notifyUser($user, TaskModel::EVENT_MOVE_COLUMN, $event); }
public function testUnlink() { $userModel = new UserModel($this->container); $provider = new GoogleAuthProvider($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'google_id' => '1234'))); $this->assertNotEmpty($userModel->getByExternalId('google_id', 1234)); $this->assertTrue($provider->unlink(2)); $this->assertEmpty($userModel->getByExternalId('google_id', 1234)); }
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 testIssueAssignedWithNoPermission() { $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' => 1, 'project_id' => 1))); $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); $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()); }