diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-04-19 19:23:42 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-04-19 19:23:42 -0400 |
commit | f190be9e2d4d285fb71d84e5d3884206067cf7af (patch) | |
tree | ca0c4bd21eeb85102731b79eb5dda526655ce82b /tests | |
parent | ac86c3100a1030026024c33c1cf02ec79f08ff51 (diff) |
Add Sendgrid integration (incoming email handling)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/ProjectTest.php | 3 | ||||
-rw-r--r-- | tests/units/SendgridWebhookTest.php | 107 | ||||
-rw-r--r-- | tests/units/ToolTest.php | 15 | ||||
-rw-r--r-- | tests/units/UserTest.php | 10 |
4 files changed, 135 insertions, 0 deletions
diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php index 231d403f..9f49af8a 100644 --- a/tests/units/ProjectTest.php +++ b/tests/units/ProjectTest.php @@ -231,6 +231,9 @@ class ProjectTest extends Base $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); + $project = $p->getByIdentifier(''); + $this->assertFalse($project); + // Validation rules $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); $this->assertFalse($r[0]); diff --git a/tests/units/SendgridWebhookTest.php b/tests/units/SendgridWebhookTest.php new file mode 100644 index 00000000..3b30d212 --- /dev/null +++ b/tests/units/SendgridWebhookTest.php @@ -0,0 +1,107 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Integration\SendgridWebhook; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\ProjectPermission; +use Model\User; + +class SendgridWebhookTest extends Base +{ + public function testHandlePayload() + { + $w = new SendgridWebhook($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(2, $u->create(array('name' => '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->parsePayload(array())); + + // Unknown user + $this->assertFalse($w->parsePayload(array( + 'envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', + 'subject' => 'Email task' + ))); + + // Project not found + $this->assertFalse($w->parsePayload(array( + 'envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', + 'subject' => 'Email task' + ))); + + // User is not member + $this->assertFalse($w->parsePayload(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task' + ))); + + $this->assertTrue($pp->addMember(2, 2)); + + // The task must be created + $this->assertTrue($w->parsePayload(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->parsePayload(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->parsePayload(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->parsePayload(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']); + } +} diff --git a/tests/units/ToolTest.php b/tests/units/ToolTest.php new file mode 100644 index 00000000..4a62fe3b --- /dev/null +++ b/tests/units/ToolTest.php @@ -0,0 +1,15 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Core\Tool; + +class ToolTest extends Base +{ + public function testMailboxHash() + { + $this->assertEquals('test1', Tool::getMailboxHash('a+test1@localhost')); + $this->assertEquals('', Tool::getMailboxHash('test1@localhost')); + $this->assertEquals('', Tool::getMailboxHash('test1')); + } +} diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php index c4094ea2..a946621c 100644 --- a/tests/units/UserTest.php +++ b/tests/units/UserTest.php @@ -10,6 +10,16 @@ use Model\Project; class UserTest extends Base { + public function testGetByEmail() + { + $u = new User($this->container); + $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost'))); + $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => ''))); + + $this->assertNotEmpty($u->getByEmail('user1@localhost')); + $this->assertEmpty($u->getByEmail('')); + } + public function testPassword() { $password = 'test123'; |