diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-06-07 22:17:50 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-06-07 22:17:50 -0400 |
commit | e22da9d32addefa8d739171febcf6f6d0c06ba7b (patch) | |
tree | affb9f8729ac9d4f07dd7f24dff39bfaa9cda0ff /tests/units | |
parent | 4f32352fe62e47ad5ea760eb00493bdc061b2407 (diff) |
Add Mailgun API as mail transport
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Base.php | 10 | ||||
-rw-r--r-- | tests/units/MailgunTest.php (renamed from tests/units/MailgunWebhookTest.php) | 36 |
2 files changed, 37 insertions, 9 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index a90987ab..bc6518fb 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -53,7 +53,15 @@ class FakeHttpClient return json_encode($this->data, JSON_PRETTY_PRINT); } - public function post($url, array $data, array $headers = array()) + public function postJson($url, array $data, array $headers = array()) + { + $this->url = $url; + $this->data = $data; + $this->headers = $headers; + return true; + } + + public function postForm($url, array $data, array $headers = array()) { $this->url = $url; $this->data = $data; diff --git a/tests/units/MailgunWebhookTest.php b/tests/units/MailgunTest.php index c2745180..b33a66fe 100644 --- a/tests/units/MailgunWebhookTest.php +++ b/tests/units/MailgunTest.php @@ -2,18 +2,38 @@ require_once __DIR__.'/Base.php'; -use Integration\MailgunWebhook; +use Integration\Mailgun; use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; use Model\User; -class MailgunWebhookTest extends Base +class MailgunTest extends Base { + public function testSendEmail() + { + $pm = new Mailgun($this->container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertStringStartsWith('https://api.mailgun.net/v3/', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('from', $data); + $this->assertArrayHasKey('to', $data); + $this->assertArrayHasKey('subject', $data); + $this->assertArrayHasKey('html', $data); + + $this->assertEquals('Me <test@localhost>', $data['to']); + $this->assertEquals('Bob <notifications@kanboard.local>', $data['from']); + $this->assertEquals('Test', $data['subject']); + $this->assertEquals('Content', $data['html']); + } + public function testHandlePayload() { - $w = new MailgunWebhook($this->container); + $w = new Mailgun($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); @@ -26,20 +46,20 @@ class MailgunWebhookTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); // Empty payload - $this->assertFalse($w->parsePayload(array())); + $this->assertFalse($w->receiveEmail(array())); // Unknown user - $this->assertFalse($w->parsePayload(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); // Project not found - $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); + $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->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $this->assertTrue($pp->addMember(2, 2)); // The task must be created - $this->assertTrue($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $task = $tf->getById(1); $this->assertNotEmpty($task); |