-
Notifications
You must be signed in to change notification settings - Fork 28
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
1 changed file
with
89 additions
and
89 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,38 +11,38 @@ | |
|
||
class MailPostmarkTransportTest extends TestCase { | ||
|
||
public function testSend() { | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Is alive!'); | ||
$message->addTo('[email protected]', 'A. Friend'); | ||
$message->addTo('[email protected]'); | ||
$message->addCc('[email protected]'); | ||
$message->addCc('[email protected]', 'Extra 2'); | ||
$message->addBcc('[email protected]'); | ||
$message->addBcc('[email protected]', 'Extra 4'); | ||
$message->addPart('<q>Help me Rhonda</q>', 'text/html'); | ||
$message->addPart('Doo-wah-ditty.', 'text/plain'); | ||
|
||
$attachment = new Swift_Attachment('This is the plain text attachment.', 'hello.txt', 'text/plain'); | ||
$attachment2 = new Swift_Attachment('This is the plain text attachment.', 'hello.txt', 'text/plain'); | ||
$attachment2->setDisposition('inline'); | ||
|
||
$message->attach($attachment); | ||
$message->attach($attachment2); | ||
$message->setPriority(1); | ||
|
||
$headers = $message->getHeaders(); | ||
$headers->addTextHeader('X-PM-Tag', 'movie-quotes'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)]); | ||
|
||
$recipientCount = $transport->send($message); | ||
|
||
$this->assertEquals(6, $recipientCount); | ||
$transaction = $transport->getHistory()[0]; | ||
$this->assertExpectedMessageRequest($message, $transaction['request']); | ||
} | ||
public function testSend() { | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Is alive!'); | ||
$message->addTo('[email protected]', 'A. Friend'); | ||
$message->addTo('[email protected]'); | ||
$message->addCc('[email protected]'); | ||
$message->addCc('[email protected]', 'Extra 2'); | ||
$message->addBcc('[email protected]'); | ||
$message->addBcc('[email protected]', 'Extra 4'); | ||
$message->addPart('<q>Help me Rhonda</q>', 'text/html'); | ||
$message->addPart('Doo-wah-ditty.', 'text/plain'); | ||
|
||
$attachment = new Swift_Attachment('This is the plain text attachment.', 'hello.txt', 'text/plain'); | ||
$attachment2 = new Swift_Attachment('This is the plain text attachment.', 'hello.txt', 'text/plain'); | ||
$attachment2->setDisposition('inline'); | ||
|
||
$message->attach($attachment); | ||
$message->attach($attachment2); | ||
$message->setPriority(1); | ||
|
||
$headers = $message->getHeaders(); | ||
$headers->addTextHeader('X-PM-Tag', 'movie-quotes'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)]); | ||
|
||
$recipientCount = $transport->send($message); | ||
|
||
$this->assertEquals(6, $recipientCount); | ||
$transaction = $transport->getHistory()[0]; | ||
$this->assertExpectedMessageRequest($message, $transaction['request']); | ||
} | ||
|
||
protected function assertExpectedMessageRequest($message, $request) | ||
{ | ||
|
@@ -80,9 +80,9 @@ protected function assertExpectedMessageRequest($message, $request) | |
], | ||
] | ||
], json_decode($request->getBody()->getContents(), true)); | ||
} | ||
} | ||
|
||
public function testCanSendEmailsWithCCs() | ||
public function testCanSendEmailsWithCCs() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
|
@@ -161,66 +161,66 @@ public function testFailedResponse() | |
$transport->send($message); | ||
} | ||
|
||
public function testMessageStreamViaDefaultHeaders() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Message-Stream' => 'your-custom-stream']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertCount(4, $body['Headers']); | ||
$this->assertEquals(['Name' => 'X-PM-Message-Stream', 'Value' => 'your-custom-stream'], $body['Headers'][3]); | ||
} | ||
|
||
public function testMessageStreamViaHeaderOverwritesDefaultHeaders() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
$message->getHeaders()->addTextHeader('X-PM-Message-Stream', 'message-custom-stream'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Message-Stream' => 'my-custom-stream']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertCount(4, $body['Headers']); | ||
$this->assertEquals(['Name' => 'X-PM-Message-Stream', 'Value' => 'message-custom-stream'], $body['Headers'][3]); | ||
} | ||
|
||
public function testPmTagDeaultHeader() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Tag' => 'my-tag']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertEquals('my-tag', $body['Tag']); | ||
} | ||
public function testMessageStreamViaDefaultHeaders() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Message-Stream' => 'your-custom-stream']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertCount(4, $body['Headers']); | ||
$this->assertEquals(['Name' => 'X-PM-Message-Stream', 'Value' => 'your-custom-stream'], $body['Headers'][3]); | ||
} | ||
|
||
public function testMessageStreamViaHeaderOverwritesDefaultHeaders() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
$message->getHeaders()->addTextHeader('X-PM-Message-Stream', 'message-custom-stream'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Message-Stream' => 'my-custom-stream']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertCount(4, $body['Headers']); | ||
$this->assertEquals(['Name' => 'X-PM-Message-Stream', 'Value' => 'message-custom-stream'], $body['Headers'][3]); | ||
} | ||
|
||
public function testPmTagDeaultHeader() | ||
{ | ||
$message = new Swift_Message(); | ||
$message->setFrom('[email protected]', 'Johnny #5'); | ||
$message->setSubject('Some Subject'); | ||
$message->addBcc('[email protected]', 'A. Friend'); | ||
$message->addBcc('[email protected]', 'B. Friend'); | ||
|
||
$transport = new PostmarkTransportStub([new Response(200)], ['X-PM-Tag' => 'my-tag']); | ||
$transport->send($message); | ||
|
||
$request = $transport->getHistory()[0]['request']; | ||
$body = json_decode($request->getBody()->getContents(), true); | ||
|
||
$this->assertEquals('my-tag', $body['Tag']); | ||
} | ||
} | ||
|
||
|
||
class PostmarkTransportStub extends Postmark\Transport { | ||
protected $client; | ||
protected $client; | ||
|
||
public function __construct(array $responses = [], array $defaultHeaders = []) | ||
public function __construct(array $responses = [], array $defaultHeaders = []) | ||
{ | ||
parent::__construct('TESTING_SERVER', $defaultHeaders); | ||
|
||
|