summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-06 14:10:31 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-06 14:10:31 -0400
commit9d9e3afba2054bfa23ba6f019b7c8885c2d8415e (patch)
tree1113e318c3d5e15bed48480f90f5498347343783 /tests/units
parentc87e1fbc33416e7b2f59b98c2ffed173958b3146 (diff)
Improve email sending system and add Postmark as mail transport
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Base.php10
-rw-r--r--tests/units/PostmarkTest.php (renamed from tests/units/PostmarkWebhookTest.php)45
2 files changed, 42 insertions, 13 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 20f4a8cc..d5fea977 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -15,6 +15,7 @@ class FakeHttpClient
{
private $url = '';
private $data = array();
+ private $headers = array();
public function getUrl()
{
@@ -26,16 +27,21 @@ class FakeHttpClient
return $this->data;
}
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
public function toPrettyJson()
{
return json_encode($this->data, JSON_PRETTY_PRINT);
}
- public function post($url, array $data)
+ public function post($url, array $data, array $headers = array())
{
$this->url = $url;
$this->data = $data;
- //echo $this->toPrettyJson();
+ $this->headers = $headers;
return true;
}
}
diff --git a/tests/units/PostmarkWebhookTest.php b/tests/units/PostmarkTest.php
index 34be8515..b708217d 100644
--- a/tests/units/PostmarkWebhookTest.php
+++ b/tests/units/PostmarkTest.php
@@ -2,18 +2,41 @@
require_once __DIR__.'/Base.php';
-use Integration\PostmarkWebhook;
+use Integration\Postmark;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\ProjectPermission;
use Model\User;
-class PostmarkWebhookTest extends Base
+class PostmarkTest extends Base
{
+ public function testSendEmail()
+ {
+ $pm = new Postmark($this->container);
+ $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob');
+
+ $this->assertEquals('https://api.postmarkapp.com/email', $this->container['httpClient']->getUrl());
+
+ $data = $this->container['httpClient']->getData();
+
+ $this->assertArrayHasKey('From', $data);
+ $this->assertArrayHasKey('To', $data);
+ $this->assertArrayHasKey('Subject', $data);
+ $this->assertArrayHasKey('HtmlBody', $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['HtmlBody']);
+
+ $this->assertContains('Accept: application/json', $this->container['httpClient']->getHeaders());
+ $this->assertContains('X-Postmark-Server-Token: ', $this->container['httpClient']->getHeaders());
+ }
+
public function testHandlePayload()
{
- $w = new PostmarkWebhook($this->container);
+ $w = new Postmark($this->container);
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new User($this->container);
@@ -26,20 +49,20 @@ class PostmarkWebhookTest 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('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo')));
+ $this->assertFalse($w->receiveEmail(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo')));
// Project not found
- $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo')));
+ $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo')));
// User is not member
- $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
+ $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
$this->assertTrue($pp->addMember(2, 2));
// The task must be created
- $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
+ $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
@@ -51,7 +74,7 @@ class PostmarkWebhookTest extends Base
public function testHtml2Markdown()
{
- $w = new PostmarkWebhook($this->container);
+ $w = new Postmark($this->container);
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new User($this->container);
@@ -62,7 +85,7 @@ class PostmarkWebhookTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
$this->assertTrue($pp->addMember(1, 2));
- $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>')));
+ $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);
@@ -71,7 +94,7 @@ class PostmarkWebhookTest extends Base
$this->assertEquals('**boo**', $task['description']);
$this->assertEquals(2, $task['creator_id']);
- $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
+ $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
$task = $tf->getById(2);
$this->assertNotEmpty($task);