From e22da9d32addefa8d739171febcf6f6d0c06ba7b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 7 Jun 2015 22:17:50 -0400 Subject: Add Mailgun API as mail transport --- tests/units/Base.php | 10 +++++- tests/units/MailgunTest.php | 71 ++++++++++++++++++++++++++++++++++++++ tests/units/MailgunWebhookTest.php | 51 --------------------------- 3 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 tests/units/MailgunTest.php delete mode 100644 tests/units/MailgunWebhookTest.php (limited to 'tests/units') 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/MailgunTest.php b/tests/units/MailgunTest.php new file mode 100644 index 00000000..b33a66fe --- /dev/null +++ b/tests/units/MailgunTest.php @@ -0,0 +1,71 @@ +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 ', $data['to']); + $this->assertEquals('Bob ', $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('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->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/MailgunWebhookTest.php b/tests/units/MailgunWebhookTest.php deleted file mode 100644 index c2745180..00000000 --- a/tests/units/MailgunWebhookTest.php +++ /dev/null @@ -1,51 +0,0 @@ -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('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'))); - - // User is not member - $this->assertFalse($w->parsePayload(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'))); - - $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']); - } -} -- cgit v1.2.3