2013-07-24 01:29:45 +04:00
|
|
|
<?PHP
|
2013-08-13 23:26:34 +04:00
|
|
|
namespace Mailgun\Tests\Messages;
|
2013-07-24 01:29:45 +04:00
|
|
|
|
2013-08-08 21:39:44 +04:00
|
|
|
use Mailgun\Tests\MailgunTest;
|
2013-07-24 01:29:45 +04:00
|
|
|
|
|
|
|
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
|
|
|
|
|
|
|
|
private $client;
|
2013-08-08 21:39:44 +04:00
|
|
|
private $sampleDomain = "samples.mailgun.org";
|
2013-07-24 01:29:45 +04:00
|
|
|
|
|
|
|
public function setUp(){
|
2013-08-13 23:26:34 +04:00
|
|
|
$this->client = new MailgunTest("My-Super-Awesome-API-Key");
|
2013-07-24 01:29:45 +04:00
|
|
|
}
|
|
|
|
public function testBlankInstantiation(){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
2013-07-24 01:29:45 +04:00
|
|
|
$this->assertTrue(is_array($message->getMessage()));
|
|
|
|
}
|
2013-08-08 21:39:44 +04:00
|
|
|
public function testaddToRecipient(){
|
|
|
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
|
|
|
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
|
2013-07-24 01:29:45 +04:00
|
|
|
$messageObj= $message->getMessage();
|
2013-08-13 23:26:34 +04:00
|
|
|
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
|
2013-07-24 01:29:45 +04:00
|
|
|
}
|
|
|
|
public function testAddMultipleBatchRecipients(){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
2013-07-24 01:29:45 +04:00
|
|
|
for($i=0; $i<100; $i++){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
|
2013-07-24 01:29:45 +04:00
|
|
|
}
|
|
|
|
$messageObj= $message->getMessage();
|
|
|
|
$this->assertEquals(100, count($messageObj["to"]));
|
|
|
|
}
|
|
|
|
public function testMaximumBatchSize(){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
2013-07-25 03:25:24 +04:00
|
|
|
$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!");
|
2013-07-24 01:29:45 +04:00
|
|
|
for($i=0; $i<1001; $i++){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
|
2013-07-24 01:29:45 +04:00
|
|
|
}
|
|
|
|
$messageObj= $message->getMessage();
|
|
|
|
$this->assertEquals(1, count($messageObj["to"]));
|
|
|
|
}
|
|
|
|
public function testResetOnEndBatchMessage(){
|
2013-08-08 21:39:44 +04:00
|
|
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
|
|
|
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
|
2013-07-25 03:25:24 +04:00
|
|
|
$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!");
|
2013-08-09 03:28:02 +04:00
|
|
|
$message->finalize();
|
2013-07-24 01:29:45 +04:00
|
|
|
$messageObj= $message->getMessage();
|
|
|
|
$this->assertTrue(true, empty($messageObj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|