summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php159
-rw-r--r--test/unit/SendGridCompatibiility/SendGridTest.php3
-rw-r--r--test/unit/SparkPostTest.php6
-rw-r--r--test/unit/TransmissionTest.php26
4 files changed, 178 insertions, 16 deletions
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
new file mode 100644
index 0000000..dbabb77
--- /dev/null
+++ b/test/unit/SendGridCompatibiility/EmailTest.php
@@ -0,0 +1,159 @@
+<?php
+use SparkPost\SendGridCompatibility\Email;
+
+class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
+
+ private $email;
+
+ public function setup() {
+ $this->email = new Email();
+ }
+
+ public function testConstruct() {
+ $email = new Email();
+
+ $this->assertInstanceOf('SparkPost\SendGridCompatibility\Email', $email);
+ $this->assertInternalType('array', $email->model);
+ }
+
+ public function testAddTo() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $this->email->addTo($fakeEmail);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail))), $this->email->model['recipients']);
+ }
+
+ public function testAddToWithName() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $fakeName = 'Joe Schmoe';
+ $this->email->addTo($fakeEmail, $fakeName);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail, 'name'=>$fakeName))), $this->email->model['recipients']);
+ }
+
+ public function testSetTos() {
+ $tos = array();
+ array_push($tos, array('address'=>array('email'=>'joe.schmoe@test.com', 'name'=>'Joe Schmoe')));
+ array_push($tos, array('address'=>array('email'=>'jill.schmoe@test.com', 'name'=>'Jill Schmoe')));
+ $this->email->setTos($tos);
+
+ $this->assertEquals($tos, $this->email->model['recipients']);
+ }
+
+ public function testSetFrom() {
+ $this->email->setFrom('test@email.com');
+
+ $this->assertEquals(array('email'=>'test@email.com'), $this->email->model['from']);
+ }
+
+
+ public function testSetFromName() {
+ $this->email->setFrom('test@email.com');
+ $this->email->setFromName('Test Bot');
+
+ $this->assertEquals(array('email'=>'test@email.com', 'name'=>'Test Bot'), $this->email->model['from']);
+ }
+
+ /**
+ * @desc Tests that setting the fromName prior to setting the From field throws an exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Must set "From" prior to setting "From Name".
+ */
+ public function testSetFromNameWithoutAddress() {
+ $this->email->setFromName('Test Bot');
+ }
+
+ public function testSetReplyto() {
+ $this->email->setReplyTo('test@email.com');
+
+ $this->assertEquals('test@email.com', $this->email->model['replyTo']);
+ }
+
+
+ public function testAddBcc() {
+ $this->email->addBcc('test@email.com');
+
+ $this->assertEquals(array('test@email.com'), $this->email->model['bcc']);
+ }
+
+ public function testSetSubject() {
+ $this->email->setSubject('Awesome Subject');
+
+ $this->assertEquals('Awesome Subject', $this->email->model['subject']);
+ }
+
+ public function testSetText() {
+ $value = 'This is some plain/text';
+ $this->email->setText($value);
+
+ $this->assertEquals($value, $this->email->model['text']);
+ }
+
+ public function testSetHtml() {
+ $value = '<html><body><p>This is some html</p></body></html>';
+ $this->email->setHtml($value);
+
+ $this->assertEquals($value, $this->email->model['html']);
+ }
+
+ public function testAddCategory() {
+ $value = 'Category A';
+ $this->email->addCategory($value);
+
+ $this->assertEquals(array($value), $this->email->model['tags']);
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding attachments is not yet supported
+ */
+ public function testAddAttachment() {
+ $this->email->addAttachment('blah');
+ }
+
+ public function testAddSubstitution() {
+ $this->email->addSubstitution('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ public function testAddSection() {
+ $this->email->addSection('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding Unique Arguments is not yet supported
+ */
+ public function testAddUniqueArguement() {
+ $this->email->addUniqueArg('blah', 'someblah');
+ }
+
+
+ /**
+ * @desc Tests that setting an unique argument throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Setting Unique Arguments is not yet supported
+ */
+ public function testSetUniqueArgs() {
+ $this->email->setUniqueArgs(['blah', 'andBlah']);
+ }
+
+
+ public function testAddHeader() {
+ $value = 'My Header';
+ $this->email->addHeader('X-header', $value);
+
+ $this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']);
+ }
+
+ public function testToMsysTransmission() {
+ $this->assertInternalType('array', $this->email->toMsysTransmission());
+ }
+}
+
+?> \ No newline at end of file
diff --git a/test/unit/SendGridCompatibiility/SendGridTest.php b/test/unit/SendGridCompatibiility/SendGridTest.php
new file mode 100644
index 0000000..15c5adc
--- /dev/null
+++ b/test/unit/SendGridCompatibiility/SendGridTest.php
@@ -0,0 +1,3 @@
+<?php
+
+?> \ No newline at end of file
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index cc1c9c9..650cb36 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -29,7 +29,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage You must provide an API key
*/
public function testSetConfigAPIKeyNotSetException() {
- SparkPost::setConfig(['something'=>'other than an API Key']);
+ SparkPost::setConfig(array('something'=>'other than an API Key'));
}
/**
@@ -38,14 +38,14 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage You must provide an API key
*/
public function testSetConfigAPIKeyEmptyException() {
- SparkPost::setConfig(['key'=>'']);
+ SparkPost::setConfig(array('key'=>''));
}
/**
* @desc Tests overridable values are set while invalid values are ignored
*/
public function testSetConfigMultipleValuesAndGetConfig() {
- SparkPost::setConfig(['key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue']);
+ SparkPost::setConfig(array('key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue'));
$testConfig = SparkPost::getConfig();
$this->assertEquals('lala', $testConfig['key']);
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index 2a0bcfe..2945bc6 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -33,7 +33,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @see PHPUnit_Framework_TestCase::setUp()
*/
public function setUp() {
- SparkPost::setConfig(['key'=>'blah']);
+ SparkPost::setConfig(array('key'=>'blah'));
$this->client = self::getMethod('getHttpClient')->invoke(null); //so we can bootstrap api responses
}
@@ -49,9 +49,9 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests happy path
*/
public function testAllWithGoodResponse() {
- $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))]);
+ $mock = new Mock(array(new Response(200, array(), Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))));
$this->client->getEmitter()->attach($mock);
- $this->assertEquals(["results"=>[['test'=>'This is a test'], ['test'=>'two']]], Transmission::all());
+ $this->assertEquals(array("results"=>array(array('test'=>'This is a test'), array('test'=>'two'))), Transmission::all());
$this->client->getEmitter()->detach($mock);
}
@@ -59,9 +59,9 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests happy path
*/
public function testFindWithGoodResponse() {
- $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}]}'))]);
+ $mock = new Mock(array(new Response(200, array(), Stream::factory('{"results":[{"test":"This is a test"}]}'))));
$this->client->getEmitter()->attach($mock);
- $this->assertEquals(["results"=>[['test'=>'This is a test']]], Transmission::find('someId'));
+ $this->assertEquals(array("results"=>array(array('test'=>'This is a test'))), Transmission::find('someId'));
$this->client->getEmitter()->detach($mock);
}
@@ -69,7 +69,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests 404 bad response
*/
public function testFindWith404Response() {
- $mock = new Mock([new Response(404, [])]);
+ $mock = new Mock(array(new Response(404, array())));
$this->client->getEmitter()->attach($mock);
try {
Transmission::find('someId');
@@ -84,7 +84,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests unknown bad response
*/
public function testFindWithOtherBadResponse() {
- $mock = new Mock([new Response(400, [])]);
+ $mock = new Mock(array(new Response(400, array())));
$this->client->getEmitter()->attach($mock);
try {
Transmission::find('someId');
@@ -99,10 +99,10 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests happy path
*/
public function testSuccessfulSend() {
- $body = ["result"=>["transmission_id"=> "11668787484950529"], "status"=>["message"=> "ok","code"=> "1000"]];
- $mock = new Mock([new Response(200, [], Stream::factory(json_encode($body)))]);
+ $body = array("result"=>array("transmission_id"=>"11668787484950529"), "status"=>array("message"=> "ok","code"=> "1000"));
+ $mock = new Mock(array(new Response(200, array(), Stream::factory(json_encode($body)))));
$this->client->getEmitter()->attach($mock);
- $this->assertEquals($body, Transmission::send(['text'=>'awesome email']));
+ $this->assertEquals($body, Transmission::send(array('text'=>'awesome email')));
$this->client->getEmitter()->detach($mock);
}
@@ -110,11 +110,11 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests bad response
*/
public function testSendForRequestException() {
- $body = ['errors'=>['This is a fake error']];
- $mock = new Mock([new Response(400, [], Stream::factory(json_encode($body)))]);
+ $body = array('errors'=>array('This is a fake error'));
+ $mock = new Mock(array(new Response(400, array(), Stream::factory(json_encode($body)))));
$this->client->getEmitter()->attach($mock);
try {
- Transmission::send(['text'=>'awesome email']);
+ Transmission::send(array('text'=>'awesome email'));
} catch (\Exception $e) {
$this->assertEquals('["This is a fake error"]', $e->getMessage());
} finally {