-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* @package wp-sparkpost | ||
*/ | ||
namespace WPSparkPost; | ||
|
||
class TestTemplates extends \WP_UnitTestCase { | ||
function test_it_should_set_mailer_obj(){ | ||
$mailer = new SparkPostHTTPMailer(); | ||
$templateObj = new SparkPostTemplates($mailer); | ||
|
||
$this->assertTrue($templateObj->mailer instanceof SparkPostHTTPMailer); | ||
} | ||
|
||
function test_preview_returns_template_data() { | ||
$mailer = $this->getMockBuilder('WPSparkPost\SparkPostHTTPMailer') | ||
->setMethods(array('request', 'get_request_headers', 'error', 'debug')) | ||
->getMock(); | ||
|
||
$response = array( | ||
'response' => array( | ||
'code' => 200 | ||
), | ||
'headers' => array(), | ||
'body' => json_encode(array( | ||
'results' => array( | ||
'from' => array( | ||
'from' => 'me@hello.com', | ||
'from_name' => 'me' | ||
), | ||
'subject' => 'test subject', | ||
'headers' => array(), | ||
'html' => '<h1>Hello there<h1>', | ||
'text' => 'hello there', | ||
'reply_to' => 'me@hello.com' | ||
) | ||
)) | ||
); | ||
|
||
$mailer->expects($this->once()) | ||
->method('request') | ||
->will($this->returnValue($response)); | ||
|
||
$templateObj = new SparkPostTemplates($mailer); | ||
$result = $templateObj->preview('abcd', array()); | ||
$this->assertEquals($result->subject, 'test subject'); | ||
$this->assertEquals($result->html, '<h1>Hello there<h1>'); | ||
$this->assertEquals($result->text, 'hello there'); | ||
} | ||
|
||
function test_preview_returns_false_on_error() { | ||
$mailer = $this->getMockBuilder('WPSparkPost\SparkPostHTTPMailer') | ||
->setMethods(array('request', 'get_request_headers', 'error', 'debug')) | ||
->getMock(); | ||
|
||
$response = array( | ||
'response' => array( | ||
'code' => 200 | ||
), | ||
'headers' => array(), | ||
'body' => json_encode(array( | ||
'errors' => array( | ||
'some interesting error' | ||
) | ||
)) | ||
); | ||
|
||
$mailer->expects($this->once()) | ||
->method('request') | ||
->will($this->returnValue($response)); | ||
|
||
$templateObj = new SparkPostTemplates($mailer); | ||
$result = $templateObj->preview('abcd', array()); | ||
$this->assertEquals($result, false); | ||
} | ||
|
||
function test_preview_returns_false_on_unknown_error() { | ||
$mailer = $this->getMockBuilder('WPSparkPost\SparkPostHTTPMailer') | ||
->setMethods(array('request', 'get_request_headers', 'error', 'debug')) | ||
->getMock(); | ||
|
||
$response = array( | ||
'response' => array( | ||
'code' => 200 | ||
), | ||
'headers' => array(), | ||
'body' => json_encode(array('unknown_key' => 'unknown result')) | ||
); | ||
|
||
$mailer->expects($this->once()) | ||
->method('request') | ||
->will($this->returnValue($response)); | ||
|
||
$templateObj = new SparkPostTemplates($mailer); | ||
$result = $templateObj->preview('abcd', array()); | ||
$this->assertEquals($result, false); | ||
} | ||
} |