Apply coding style that is in src

This commit is contained in:
Iain Cambridge 2014-05-14 14:06:05 +01:00
parent 6196f8df49
commit e9e0f39ca8
9 changed files with 592 additions and 433 deletions

View File

@ -3,15 +3,19 @@ namespace Mailgun\Tests\Connection;
use Mailgun\Tests\Mock\Mailgun;
class ConnectionTest extends \Mailgun\Tests\MailgunTestCase{
class ConnectionTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $client;
public function setUp(){
}
public function testNewClientInstantiation(){
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function setUp()
{
}
public function testNewClientInstantiation()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
}
?>

View File

@ -3,31 +3,48 @@ namespace Mailgun\Tests\Lists;
use Mailgun\Tests\Mock\Mailgun;
class OptInHandler extends \Mailgun\Tests\MailgunTestCase{
class OptInHandler extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $optInHandler;
private $client;
private $sampleDomain = "samples.mailgun.org";
private $optInHandler;
public function setUp(){
$this->client = new Mailgun("My-Super-Awesome-API-Key");
$this->optInHandler = $this->client->OptInHandler();
}
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
$this->optInHandler = $this->client->OptInHandler();
}
public function testReturnOfGenerateHash(){
$generatedHash = $this->optInHandler->generateHash('mytestlist@example.com', 'mysupersecretappid', 'testrecipient@example.com');
$knownHash = "eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D";
$this->assertEquals($generatedHash, $knownHash);
}
public function testReturnOfGenerateHash()
{
$generatedHash = $this->optInHandler->generateHash(
'mytestlist@example.com',
'mysupersecretappid',
'testrecipient@example.com'
);
$knownHash = "eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D";
$this->assertEquals($generatedHash, $knownHash);
}
public function testGoodHash(){
$validation = $this->optInHandler->validateHash('mysupersecretappid', 'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D');
$this->assertArrayHasKey('recipientAddress', $validation);
$this->assertArrayHasKey('mailingList', $validation);
}
public function testBadHash(){
$validation = $this->optInHandler->validateHash('mybadsecretappid', 'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D');
$this->assertFalse($validation);
}
public function testGoodHash()
{
$validation = $this->optInHandler->validateHash(
'mysupersecretappid',
'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D'
);
$this->assertArrayHasKey('recipientAddress', $validation);
$this->assertArrayHasKey('mailingList', $validation);
}
public function testBadHash()
{
$validation = $this->optInHandler->validateHash(
'mybadsecretappid',
'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D'
);
$this->assertFalse($validation);
}
}
?>

View File

@ -3,7 +3,8 @@ namespace Mailgun\Tests\Lists;
use Mailgun\Mailgun;
class MailgunTest extends \Mailgun\Tests\MailgunTestCase{
class MailgunTest extends \Mailgun\Tests\MailgunTestCase
{
public function testSendMessageMissingRequiredMIMEParametersExceptionGetsFlung()
{

View File

@ -4,6 +4,8 @@ namespace Mailgun\Tests;
use Guzzle\Tests\GuzzleTestCase;
abstract class MailgunTestCase extends GuzzleTestCase{}
abstract class MailgunTestCase extends GuzzleTestCase
{
}
?>

View File

@ -3,114 +3,136 @@ namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $client;
private $sampleDomain = "samples.mailgun.org";
public function setUp(){
$this->client = new Mailgun("My-Super-Awesome-API-Key");
}
public function testBlankInstantiation(){
$message = $this->client->BatchMessage($this->sampleDomain);
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddRecipient(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj= $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
}
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
public function testBlankInstantiation()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddRecipient()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['to']);
}
public function testRecipientVariablesOnTo(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj= $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
public function testRecipientVariablesOnTo()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
}
public function testRecipientVariablesOnCc(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj= $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
public function testRecipientVariablesOnCc()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
}
public function testRecipientVariablesOnBcc(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj= $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
public function testRecipientVariablesOnBcc()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
}
public function testAddMultipleBatchRecipients(){
$message = $this->client->BatchMessage($this->sampleDomain);
for($i=0; $i<100; $i++){
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj= $message->getMessage();
$this->assertEquals(100, count($messageObj["to"]));
}
public function testMaximumBatchSize(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
for($i=0; $i<1001; $i++){
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj= $message->getMessage();
$this->assertEquals(1, count($messageObj["to"]));
}
public function testAttributeResetOnEndBatchMessage(){
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
$message->finalize();
$messageObj= $message->getMessage();
$this->assertTrue(true, empty($messageObj));
}
public function testDefaultIDInVariables() {
}
public function testAddMultipleBatchRecipients()
{
$message = $this->client->BatchMessage($this->sampleDomain);
for ($i = 0; $i < 100; $i++) {
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj = $message->getMessage();
$this->assertEquals(100, count($messageObj["to"]));
}
public function testMaximumBatchSize()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
for ($i = 0; $i < 1001; $i++) {
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj = $message->getMessage();
$this->assertEquals(1, count($messageObj["to"]));
}
public function testAttributeResetOnEndBatchMessage()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
$message->finalize();
$messageObj = $message->getMessage();
$this->assertTrue(true, empty($messageObj));
}
public function testDefaultIDInVariables()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(True);
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals(1, $propertyValue['test-user@samples.mailgun.org']['id']);
}
public function testgetMessageIds() {
public function testgetMessageIds()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
$message->finalize();
$this->assertEquals(array("1234"), $message->getMessageIds());
@ -121,30 +143,34 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array(1,2,3));
$message->sendMessage(array(1, 2, 3));
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTo()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1, 2,3));
$message->sendMessage(array("from" => 1, 2, 3));
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoSubject()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1, "to" => 2,3));
$message->sendMessage(array("from" => 1, "to" => 2, 3));
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTextOrHtml()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1,"to" => 2,"subject" => 3));
$message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3));
}
}
?>

View File

@ -3,22 +3,28 @@ namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
public function setUp(){
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function testBlankInstantiation(){
$message = $this->client->MessageBuilder();
$this->assertTrue(is_array($message->getMessage()));
}
public function testCountersSetToZero(){
$message = $this->client->MessageBuilder();
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(True);
public function testBlankInstantiation()
{
$message = $this->client->MessageBuilder();
$this->assertTrue(is_array($message->getMessage()));
}
public function testCountersSetToZero()
{
$message = $this->client->MessageBuilder();
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals(0, $propertyValue['recipients']['to']);
$this->assertEquals(0, $propertyValue['recipients']['cc']);
@ -26,237 +32,322 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(0, $propertyValue['attributes']['attachment']);
$this->assertEquals(0, $propertyValue['attributes']['campaign_id']);
$this->assertEquals(0, $propertyValue['attributes']['custom_option']);
$this->assertEquals(0, $propertyValue['attributes']['tag']);
}
public function testAddToRecipient(){
$message = $this->client->MessageBuilder();
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testAddCcRecipient(){
$message = $this->client->MessageBuilder();
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testAddBccRecipient(){
$message = $this->client->MessageBuilder();
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testToRecipientCount() {
$this->assertEquals(0, $propertyValue['attributes']['tag']);
}
public function testAddToRecipient()
{
$message = $this->client->MessageBuilder();
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testAddCcRecipient()
{
$message = $this->client->MessageBuilder();
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testAddBccRecipient()
{
$message = $this->client->MessageBuilder();
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testToRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['to']);
}
public function testCcRecipientCount() {
public function testCcRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addCcRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['cc']);
}
public function testBccRecipientCount() {
public function testBccRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addBccRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['bcc']);
}
public function testSetFromAddress(){
$message = $this->client->MessageBuilder();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testSetReplyTo(){
$message = $this->client->MessageBuilder();
$message->setReplyToAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("h:reply-to" => "'Test User' <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject(){
$message = $this->client->MessageBuilder();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader(){
$message = $this->client->MessageBuilder();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody(){
$message = $this->client->MessageBuilder();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody(){
$message = $this->client->MessageBuilder();
$message->setHtmlBody("<html><body>This is an awesome email</body></html>");
$messageObj = $message->getMessage();
$this->assertEquals(array("html" => "<html><body>This is an awesome email</body></html>"), $messageObj);
}
public function testAddAttachments(){
$message = $this->client->MessageBuilder();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getFiles();
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null),
array('filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null)), $messageObj["attachment"]);
}
public function testAddInlineImages(){
$message = $this->client->MessageBuilder();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getFiles();
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null),
array('filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null)), $messageObj['inline']);
}
public function testAddAttachmentsPostName(){
$message = $this->client->MessageBuilder();
$message->addAttachment('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'),
array('filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png')), $messageObj["attachment"]);
}
public function testAddInlineImagePostName(){
$message = $this->client->MessageBuilder();
$message->addInlineImage('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'),
array('filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png')), $messageObj['inline']);
}
public function testsetTestMode(){
$message = $this->client->MessageBuilder();
$message->setTestMode(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
$message->setTestMode("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
}
public function addCampaignId(){
$message = $this->client->MessageBuilder();
$message->addCampaignId("ABC123");
$message->addCampaignId("XYZ987");
$message->addCampaignId("TUV456");
$message->addCampaignId("NONO123");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj);
}
public function testSetDkim(){
$message = $this->client->MessageBuilder();
$message->setDkim(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
$message->setDkim("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
}
public function testSetClickTracking(){
$message = $this->client->MessageBuilder();
$message->setClickTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
$message->setClickTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
}
public function testSetOpenTracking(){
$message = $this->client->MessageBuilder();
$message->setOpenTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
$message->setOpenTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
}
public function testSetDeliveryTime(){
$message = $this->client->MessageBuilder();
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj);
$message->setDeliveryTime("January 15, 2014 8:00AM", "UTC");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
$message->setDeliveryTime("January 15, 2014 8:00AM");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
$message->setDeliveryTime("1/15/2014 13:50:01", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 13:50:01 -0600"), $messageObj);
public function testSetFromAddress()
{
$message = $this->client->MessageBuilder();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
}
public function testSetReplyTo()
{
$message = $this->client->MessageBuilder();
$message->setReplyToAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("h:reply-to" => "'Test User' <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject()
{
$message = $this->client->MessageBuilder();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader()
{
$message = $this->client->MessageBuilder();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody()
{
$message = $this->client->MessageBuilder();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody()
{
$message = $this->client->MessageBuilder();
$message->setHtmlBody("<html><body>This is an awesome email</body></html>");
$messageObj = $message->getMessage();
$this->assertEquals(array("html" => "<html><body>This is an awesome email</body></html>"), $messageObj);
}
public function testAddAttachments()
{
$message = $this->client->MessageBuilder();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null
),
array(
'filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null
)
),
$messageObj["attachment"]
);
}
public function testAddInlineImages()
{
$message = $this->client->MessageBuilder();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null
),
array(
'filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null
)
),
$messageObj['inline']
);
}
public function testAddAttachmentsPostName()
{
$message = $this->client->MessageBuilder();
$message->addAttachment('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'
),
array(
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png'
)
),
$messageObj["attachment"]
);
}
public function testAddInlineImagePostName()
{
$message = $this->client->MessageBuilder();
$message->addInlineImage('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'
),
array(
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png'
)
),
$messageObj['inline']
);
}
public function testsetTestMode()
{
$message = $this->client->MessageBuilder();
$message->setTestMode(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
$message->setTestMode("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
}
public function addCampaignId()
{
$message = $this->client->MessageBuilder();
$message->addCampaignId("ABC123");
$message->addCampaignId("XYZ987");
$message->addCampaignId("TUV456");
$message->addCampaignId("NONO123");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj);
}
public function testSetDkim()
{
$message = $this->client->MessageBuilder();
$message->setDkim(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
$message->setDkim("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
}
public function testSetClickTracking()
{
$message = $this->client->MessageBuilder();
$message->setClickTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
$message->setClickTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
}
public function testSetOpenTracking()
{
$message = $this->client->MessageBuilder();
$message->setOpenTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
$message->setOpenTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
}
public function testSetDeliveryTime()
{
$message = $this->client->MessageBuilder();
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj);
$message->setDeliveryTime("January 15, 2014 8:00AM", "UTC");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
$message->setDeliveryTime("January 15, 2014 8:00AM");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
$message->setDeliveryTime("1/15/2014 13:50:01", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 13:50:01 -0600"), $messageObj);
// https://github.com/mailgun/mailgun-php/pull/42
// https://github.com/mailgun/mailgun-php/issues/43
//$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
//$messageObj = $message->getMessage();
//$this->assertEquals(array("o:deliverytime" => "Sat, 06 Jul 2013 08:00:00 -0500"), $messageObj);
}
public function testAddCustomData(){
$message = $this->client->MessageBuilder();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
$messageObj = $message->getMessage();
$this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj);
}
public function testAddCustomParameter(){
$message = $this->client->MessageBuilder();
$message->addCustomParameter("my-option", "yes");
$message->addCustomParameter("o:my-other-option", "no");
$messageObj = $message->getMessage();
$this->assertEquals(array("my-option" => array("yes"), "o:my-other-option" => array("no")), $messageObj);
}
//$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
//$messageObj = $message->getMessage();
//$this->assertEquals(array("o:deliverytime" => "Sat, 06 Jul 2013 08:00:00 -0500"), $messageObj);
}
public function testSetMessage(){
$message = [1,2,3,4,5];
public function testAddCustomData()
{
$message = $this->client->MessageBuilder();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
$messageObj = $message->getMessage();
$this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj);
}
public function testAddCustomParameter()
{
$message = $this->client->MessageBuilder();
$message->addCustomParameter("my-option", "yes");
$message->addCustomParameter("o:my-other-option", "no");
$messageObj = $message->getMessage();
$this->assertEquals(array("my-option" => array("yes"), "o:my-other-option" => array("no")), $messageObj);
}
public function testSetMessage()
{
$message = [1, 2, 3, 4, 5];
$messageBuilder = $this->client->MessageBuilder();
$messageBuilder->setMessage($message);

View File

@ -3,16 +3,20 @@ namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase{
class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $client;
private $sampleDomain = "samples.mailgun.org";
public function setUp(){
$this->client = new Mailgun("My-Super-Awesome-API-Key");
}
public function testSendMIMEMessage(){
$customMime = "Received: by luna.mailgun.net with SMTP mgrt 8728174999085; Mon, 10 Jun 2013 09:50:58 +0000
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
}
public function testSendMIMEMessage()
{
$customMime = "Received: by luna.mailgun.net with SMTP mgrt 8728174999085; Mon, 10 Jun 2013 09:50:58 +0000
Mime-Version: 1.0
Content-Type: text/plain; charset=\"ascii\"
Subject: This is the Subject!
@ -25,16 +29,22 @@ class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase{
Sender: test@test.mailgun.com
Mailgun is testing!";
$envelopeFields = array('to' => 'test@test.mailgun.org');
$result = $this->client->sendMessage("test.mailgun.org", $envelopeFields, $customMime);
$this->assertEquals("test.mailgun.org/messages.mime", $result->http_endpoint_url);
}
$envelopeFields = array('to' => 'test@test.mailgun.org');
$result = $this->client->sendMessage("test.mailgun.org", $envelopeFields, $customMime);
$this->assertEquals("test.mailgun.org/messages.mime", $result->http_endpoint_url);
}
public function testSendMessage(){
$message = array('to' => 'test@test.mailgun.org', 'from' => 'sender@test.mailgun.org', 'subject' => 'This is my test subject', 'text' => 'Testing!');
$result = $this->client->sendMessage("test.mailgun.org", $message);
$this->assertEquals("test.mailgun.org/messages", $result->http_endpoint_url);
public function testSendMessage()
{
$message = array('to' => 'test@test.mailgun.org',
'from' => 'sender@test.mailgun.org',
'subject' => 'This is my test subject',
'text' => 'Testing!'
);
$result = $this->client->sendMessage("test.mailgun.org", $message);
$this->assertEquals("test.mailgun.org/messages", $result->http_endpoint_url);
}
}
}
?>

View File

@ -3,58 +3,65 @@ namespace Mailgun\Tests\Mock\Connection;
use Mailgun\Connection\RestClient;
class TestBroker extends RestClient {
private $apiKey;
class TestBroker extends RestClient
{
private $apiKey;
protected $apiEndpoint;
protected $apiEndpoint;
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2"){
$this->apiKey = $apiKey;
$this->apiEndpoint = $apiEndpoint;
}
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2")
{
$this->apiKey = $apiKey;
$this->apiEndpoint = $apiEndpoint;
}
public function post($endpointUrl, $postData = array(), $files = array()){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function get($endpointUrl, $queryString = array()){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function delete($endpointUrl){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function put($endpointUrl, $queryString){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function post($endpointUrl, $postData = array(), $files = array())
{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function responseHandler($endpointUrl, $httpResponseCode = 200){
if($httpResponseCode === 200){
$result = new \stdClass();
$result->http_response_body = new \stdClass();
$jsonResponseData = json_decode('{"message": "Some JSON Response Data", "id": "1234"}');
foreach($jsonResponseData as $key => $value){
$result->http_response_body->$key = $value;
}
}
elseif($httpStatusCode == 400){
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
}
elseif($httpStatusCode == 401){
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
}
elseif($httpStatusCode == 401){
throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS);
}
elseif($httpStatusCode == 404){
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
}
else{
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
return false;
}
$result->http_response_code = $httpResponseCode;
$result->http_endpoint_url = $endpointUrl;
return $result;
}
public function get($endpointUrl, $queryString = array())
{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function delete($endpointUrl)
{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function put($endpointUrl, $queryString)
{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
public function responseHandler($endpointUrl, $httpResponseCode = 200)
{
if ($httpResponseCode === 200) {
$result = new \stdClass();
$result->http_response_body = new \stdClass();
$jsonResponseData = json_decode('{"message": "Some JSON Response Data", "id": "1234"}');
foreach ($jsonResponseData as $key => $value) {
$result->http_response_body->$key = $value;
}
} elseif ($httpStatusCode == 400) {
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
} elseif ($httpStatusCode == 401) {
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
} elseif ($httpStatusCode == 401) {
throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS);
} elseif ($httpStatusCode == 404) {
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
} else {
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
return false;
}
$result->http_response_code = $httpResponseCode;
$result->http_endpoint_url = $endpointUrl;
return $result;
}
}

View File

@ -7,12 +7,13 @@ use Mailgun\Tests\Mock\Connection\TestBroker;
class Mailgun extends Base
{
protected $debug;
protected $restClient;
protected $debug;
protected $restClient;
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2"){
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
}
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2")
{
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
}
}