Added test cases for all available methods.

This commit is contained in:
Travis Swientek 2013-07-23 14:29:45 -07:00
parent 425cdc5863
commit e5ae7e47d3
12 changed files with 725 additions and 68 deletions

View File

@ -12,7 +12,9 @@
<testsuites>
<testsuite>
<directory>./tests/Mailgun/Tests</directory>
<exclude>./tests/Mailgun/Tests/Connection/ConnectionTest.php</exclude>
</testsuite>
</testsuites>
</phpunit>

View File

@ -4,8 +4,6 @@
namespace Mailgun\Common;
require dirname(__DIR__) . '/globals.php';
use Guzzle\Http\Client as Guzzler;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
@ -14,26 +12,39 @@ class BatchMessage extends Message{
private $batchRecipientAttributes;
private $client;
private $autoSend;
public function __construct($client){
public function __construct($client, $debug = false){
parent::__construct($this->client);
$this->batchRecipientAttributes = array();
$this->client = $client;
$this->debug = $debug;
}
public function addBatchRecipient($address, $attributes){
//Check for maximum recipient count
if($this->toRecipientCount == 1000){
$this->sendBatchMessage();
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
//If autoSend is off, do things here.
if($this->debug == true){
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
}
else{
//Send current set and reset recipient parameters
$this->sendBatchMessage();
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
}
}
if(array_key_exists("first", $attributes)){
$name = $attributes["first"];
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
}
$name = $attributes["first"];
}
}
$addr = $name . " <" . $address . ">";
if(isset($this->message["to"])){
@ -49,11 +60,19 @@ class BatchMessage extends Message{
}
public function endBatchMessage(){
if($this->debug == true){
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
$this->message = array();
return true;
}
$this->sendBatchMessage();
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
$this->message = array();
return true;
}
private function sendBatchMessage(){
if(array_key_exists("from", $this->message)){
if($this->toRecipientCount > 0){

View File

@ -4,7 +4,7 @@ namespace Mailgun\Common;
require dirname(__DIR__) . '/globals.php';
use Guzzle\Http\Client as Guzzler;
use Guzzle\Http\Client as Guzzle;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
@ -27,14 +27,14 @@ class Client{
$this->domain = $domain;
$this->debug = $debug;
if($this->debug){
$this->client = new Guzzler('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
$this->validateCredentials();
}
else{
$this->client = new Guzzler('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);

View File

@ -32,14 +32,20 @@ class Message{
public function addToRecipient($address, $attributes){
if($this->toRecipientCount < 1000){
if(array_key_exists("first", $attributes)){
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
if(is_array($attributes)){
if(array_key_exists("first", $attributes)){
$name = $attributes["first"];
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
}
$name = $attributes["first"];
}
}
if(isset($name)){
$addr = $name . " <" . $address . ">";
}
else{
$addr = $address;
}
$addr = $name . " <" . $address . ">";
if(isset($this->message["to"])){
array_push($this->message["to"], $addr);
}
@ -49,19 +55,27 @@ class Message{
$this->toRecipientCount++;
return true;
}
else{
//DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS
}
}
public function addCcRecipient($address, $name = NULL){
public function addCcRecipient($address, $attributes){
if($this->ccRecipientCount < 1000){
if(array_key_exists("first", $attributes)){
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
if(is_array($attributes)){
if(array_key_exists("first", $attributes)){
$name = $attributes["first"];
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
}
$name = $attributes["first"];
}
}
if(isset($name)){
$addr = $name . " <" . $address . ">";
}
else{
$addr = $address;
}
$addr = $name . " <" . $address . ">";
if(isset($this->message["cc"])){
array_push($this->message["cc"], $addr);
}
@ -71,18 +85,26 @@ class Message{
$this->ccRecipientCount++;
return true;
}
else{
//DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS
}
}
public function addBccRecipient($address, $name = NULL){
public function addBccRecipient($address, $attributes){
if($this->bccRecipientCount < 1000){
if(array_key_exists("first", $attributes)){
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
if(is_array($attributes)){
if(array_key_exists("first", $attributes)){
$name = $attributes["first"];
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
}
$name = $attributes["first"];
}
}
if(isset($name)){
$addr = $name . " <" . $address . ">";
}
else{
$addr = $address;
}
$addr = $name . " <" . $address . ">";
if(isset($this->message["bcc"])){
array_push($this->message["bcc"], $addr);
}
@ -92,16 +114,27 @@ class Message{
$this->bccRecipientCount++;
return true;
}
else{
//DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS
}
}
public function setFromAddress($address, $name = NULL){
if($name != NULL){
public function setFromAddress($address, $attributes){
if(is_array($attributes)){
if(array_key_exists("first", $attributes)){
$name = $attributes["first"];
if(array_key_exists("last", $attributes)){
$name = $attributes["first"] . " " . $attributes["last"];
}
}
}
if(isset($name)){
$addr = $name . " <" . $address . ">";
}
else{
$addr = $address . " <" . $address . ">";
$addr = $address;
}
$this->message['from'] = $addr;
return true;
$this->message['from'] = $addr;
return true;
}
public function setSubject($data = NULL){
if($data == NULL || $data == ""){
@ -115,7 +148,7 @@ class Message{
$headerName = "h:" . $headerName;
}
$this->addCustomOption($headerName, $data);
$this->message[$headerName] = array($data);
return true;
}
@ -167,11 +200,18 @@ class Message{
}
public function addCampaignId($data){
if($this->campaignIdCount < 3){
$arr = "o:campaign[".$this->campaignIdCount."]";
$this->message[$arr] = $data;
if(isset($this->message['o:campaign'])){
array_push($this->message['o:campaign'] , $data);
}
else{
$this->message['o:campaign'] = array($data);
}
$this->campaignIdCount++;
return true;
}
else{
//THROW AN EXCEPTION HERE!! CANT HAVE MORE THAN 3 CAMPAIGNS
}
}
public function setDkim($data){
if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){
@ -204,11 +244,11 @@ class Message{
return true;
}
public function setDeliveryTime($timeDate, $timeZone = NULL){
if($timeZone == NULL){
$timeZoneObj = new \DateTimeZone(DEFAULT_TIME_ZONE);
if(isset($timeZone)){
$timeZoneObj = new \DateTimeZone("$timeZone");
}
else{
$timeZoneObj = new \DateTimeZone("$timeZone");
$timeZoneObj = new \DateTimeZone(\DEFAULT_TIME_ZONE);
}
$dateTimeObj = new \DateTime($timeDate, $timeZoneObj);
@ -223,12 +263,15 @@ class Message{
$this->message['v:'.$customName] = $jsonArray;
}
else{
//throw exception here!
//throw exception here data is not in an array form!
return false;
}
}
public function addCustomOption($optionName, $data){
if(!preg_match("/^o:/i", $optionName)){
$optionName = "o:" . $optionName;
}
if(isset($this->message['options'][$optionName])){
array_push($this->message['options'][$optionName], $data);
return true;

View File

@ -6,7 +6,8 @@ const API_ENDPOINT = "api.mailgun.net";
const API_USER = "api";
const SDK_VERSION = "0.1";
const SDK_USER_AGENT = "mailgun-sdk-php";
const DEFAULT_TIME_ZONE = "UTC";
const DEFAULT_MG_API_KEY = "key-3ax6xnjp29jd6fds4gc373sgvjxteol0";
const DEFAULT_MG_DOMAIN = "samples.mailgun.org";
?>

View File

@ -12,10 +12,9 @@ use Mailgun\Exceptions\HTTPError;
$client = new Client("key-ca6d168e492611df8307001d60d24a9c-0b27e", "aawdawdad.ninomail.com", true);
//$message = new Message();
$response = $client->sendMessage(array('from' =>"travis@aawdawdad.ninomail.com", 'to' => "travis@tswientek.com", "subject" => "subject here", "text" => "hello", "o:testmode" =>true));
echo $response->getBody();
$message = new Message();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
var_dump($message->getMessage());
//$message = new Mailgun\Common\Message($client);

View File

@ -4,22 +4,21 @@ namespace Mailgun\Tests\Connection;
use Mailgun\Common\Client;
class ConnectionTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
//Do we need to setup anything? Not sure yet. Leaving this function here until I need it!
$this->client = new Client(\DEFAULT_MG_API_KEY, \DEFAULT_MG_DOMAIN, false);
}
public function testNewClientConnection(){
$client = new Client("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org", false);
$result = $client->validateCredentials();
$result = $this->client->validateCredentials();
$this->assertTrue($result);
}
/**
* @depends testNewClientConnection
*/
public function sendSimpleTestMessage(){
$client = new Client("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org", false);
$result = $client->sendMessage(array("from" => "Excited User <me@samples.mailgun.org>", "to" => "travis@tswientek.com", "subject" => "Hello", "Text" => "PHP Unit Test Success!", "o:testmode" => false));
$results = $result->getResponseCode();
$this->assertEquals("20", $results);
public function testSendSimpleTestMessage(){
$result = $this->client->sendMessage(array("from" => "Excited User <me@samples.mailgun.org>", "to" => "travis@tswientek.com", "subject" => "Hello", "text" => "PHP Unit Test Success!", "o:testmode" => true));
$status = $result->getStatusCode();
$this->assertEquals("200", $status);
}
}

View File

@ -0,0 +1,118 @@
<?PHP
namespace Mailgun\Tests\BatchMessage;
use Mailgun\Common\Client;
use Mailgun\Common\BatchMessage;
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
$this->client = new Client(DEFAULT_MG_API_KEY, DEFAULT_MG_DOMAIN, false);
}
public function testBlankInstantiation(){
$message = new BatchMessage($this->client, true);
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddBatchRecipient(){
$message = new BatchMessage($this->client, true);
$message->addBatchRecipient("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 testAddMultipleBatchRecipients(){
$message = new BatchMessage($this->client, true);
for($i=0; $i<100; $i++){
$message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj= $message->getMessage();
$this->assertEquals(100, count($messageObj["to"]));
}
public function testMaximumBatchSize(){
$message = new BatchMessage($this->client, true);
for($i=0; $i<1001; $i++){
$message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
$messageObj= $message->getMessage();
$this->assertEquals(1, count($messageObj["to"]));
}
public function testResetOnEndBatchMessage(){
$message = new BatchMessage($this->client, true);
$message->addBatchRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->endBatchMessage();
$messageObj= $message->getMessage();
$this->assertTrue(true, empty($messageObj));
}
}
?>

View File

@ -0,0 +1,246 @@
<?PHP
namespace Mailgun\Tests\Message;
use Mailgun\Common\Message;
class MessageTest extends \Mailgun\Tests\MailgunTestCase{
public function setUp(){
//Do we need to setup anything? Not sure yet. Leaving this function here until I need it!
}
public function testBlankInstantiation(){
$message = new Message();
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddToRecipient(){
$message = new Message();
$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 = new Message();
$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 = new Message();
$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 testSetFromAddress(){
$message = new Message();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => "Test User <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject(){
$message = new Message();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader(){
$message = new Message();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody(){
$message = new Message();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody(){
$message = new Message();
$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 = new Message();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testAddInlineImages(){
$message = new Message();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testsetTestMode(){
$message = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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("1/15/2014 13:50:01", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 13:50:01 -0600"), $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 testAddCustomData(){
$message = new Message();
$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 testAddCustomOption(){
$message = new Message();
$message->addCustomOption("my-option", "yes");
$message->addCustomOption("o:my-other-option", "no");
$messageObj = $message->getMessage();
$this->assertEquals(array("options" => array("o:my-option" => array("yes"), "o:my-other-option" => array("no"))), $messageObj);
}
}
?>

View File

@ -5,12 +5,242 @@ use Mailgun\Common\Message;
class MessageTest extends \Mailgun\Tests\MailgunTestCase{
public function setUp(){
//Do we need to setup anything? Not sure yet. Leaving this function here until I need it!
}
public function testBlankInstantiation(){
$message = new Message();
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddToRecipient(){
$message = new Message();
$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 = new Message();
$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 = new Message();
$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 testSetFromAddress(){
$message = new Message();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => "Test User <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject(){
$message = new Message();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader(){
$message = new Message();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody(){
$message = new Message();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody(){
$message = new Message();
$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 = new Message();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testAddInlineImages(){
$message = new Message();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testsetTestMode(){
$message = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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 = new Message();
$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("1/15/2014 13:50:01", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 13:50:01 -0600"), $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 testAddCustomData(){
$message = new Message();
$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 testAddCustomOption(){
$message = new Message();
$message->addCustomOption("my-option", "yes");
$message->addCustomOption("o:my-other-option", "no");
$messageObj = $message->getMessage();
$this->assertEquals(array("options" => array("o:my-option" => array("yes"), "o:my-other-option" => array("no"))), $messageObj);
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB