summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-16 20:50:12 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-16 20:50:12 -0400
commitf99a3c501fd6ed7b4914b8d6e855489c2ce5b219 (patch)
tree976276d6acfff78923e4549b0ef9ea94c5e2cb0d /tests
parent9c9ed02cd7ebc5dbbc99bcaed6f80988ce8a9677 (diff)
Make mail transports pluggable and move integrations to plugins
- Postmark: https://github.com/kanboard/plugin-postmark - Mailgun: https://github.com/kanboard/plugin-mailgun - Sendgrid: https://github.com/kanboard/plugin-sendgrid
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Integration/MailgunTest.php71
-rw-r--r--tests/units/Integration/PostmarkTest.php106
-rw-r--r--tests/units/Integration/SendgridTest.php135
-rw-r--r--tests/units/Model/EmailNotificationTest.php4
4 files changed, 2 insertions, 314 deletions
diff --git a/tests/units/Integration/MailgunTest.php b/tests/units/Integration/MailgunTest.php
deleted file mode 100644
index 25599f8e..00000000
--- a/tests/units/Integration/MailgunTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Integration\Mailgun;
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\Project;
-use Kanboard\Model\ProjectPermission;
-use Kanboard\Model\User;
-
-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 Mailgun($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('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->addMember(2, 2));
-
- // The task must be created
- $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);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('Email task', $task['title']);
- $this->assertEquals('boo', $task['description']);
- $this->assertEquals(2, $task['creator_id']);
- }
-}
diff --git a/tests/units/Integration/PostmarkTest.php b/tests/units/Integration/PostmarkTest.php
deleted file mode 100644
index fba6dbba..00000000
--- a/tests/units/Integration/PostmarkTest.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Integration\Postmark;
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\Project;
-use Kanboard\Model\ProjectPermission;
-use Kanboard\Model\User;
-
-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 Postmark($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('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('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo')));
-
- // Project not found
- $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo')));
-
- // User is not member
- $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->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
-
- $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 testHtml2Markdown()
- {
- $w = new Postmark($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('username' => 'me', 'email' => 'me@localhost')));
- $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
- $this->assertTrue($pp->addMember(1, 2));
-
- $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']);
- }
-}
diff --git a/tests/units/Integration/SendgridTest.php b/tests/units/Integration/SendgridTest.php
deleted file mode 100644
index 85303ce7..00000000
--- a/tests/units/Integration/SendgridTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Integration\Sendgrid;
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\Project;
-use Kanboard\Model\ProjectPermission;
-use Kanboard\Model\User;
-
-class SendgridTest extends Base
-{
- public function testSendEmail()
- {
- $pm = new Sendgrid($this->container);
- $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob');
-
- $this->assertEquals('https://api.sendgrid.com/api/mail.send.json', $this->container['httpClient']->getUrl());
-
- $data = $this->container['httpClient']->getData();
-
- $this->assertArrayHasKey('api_user', $data);
- $this->assertArrayHasKey('api_key', $data);
- $this->assertArrayHasKey('from', $data);
- $this->assertArrayHasKey('fromname', $data);
- $this->assertArrayHasKey('to', $data);
- $this->assertArrayHasKey('toname', $data);
- $this->assertArrayHasKey('subject', $data);
- $this->assertArrayHasKey('html', $data);
-
- $this->assertEquals('test@localhost', $data['to']);
- $this->assertEquals('Me', $data['toname']);
- $this->assertEquals('notifications@kanboard.local', $data['from']);
- $this->assertEquals('Bob', $data['fromname']);
- $this->assertEquals('Test', $data['subject']);
- $this->assertEquals('Content', $data['html']);
- $this->assertEquals('', $data['api_key']);
- $this->assertEquals('', $data['api_user']);
- }
-
- public function testHandlePayload()
- {
- $w = new Sendgrid($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('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->addMember(2, 2));
-
- // 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']);
- }
-}
diff --git a/tests/units/Model/EmailNotificationTest.php b/tests/units/Model/EmailNotificationTest.php
index afe8d196..342f0aa9 100644
--- a/tests/units/Model/EmailNotificationTest.php
+++ b/tests/units/Model/EmailNotificationTest.php
@@ -74,7 +74,7 @@ class EmailNotificationTest extends Base
$this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
$this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\EmailClient')
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
->setConstructorArgs(array($this->container))
->setMethods(array('send'))
->getMock();
@@ -104,7 +104,7 @@ class EmailNotificationTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
$this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\EmailClient')
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
->setConstructorArgs(array($this->container))
->setMethods(array('send'))
->getMock();