Skip to content

Commit

Permalink
debugtransport now also returns in correct format as stated in RFC 28…
Browse files Browse the repository at this point in the history
…22 2.3, updated tests
  • Loading branch information
ceeram committed Aug 29, 2011
1 parent 2efa3b0 commit 3be9a8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Network/Email/DebugTransport.php
Expand Up @@ -34,7 +34,7 @@ class DebugTransport extends AbstractTransport {
public function send(CakeEmail $email) {
$headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'));
$headers = $this->_headersToString($headers);
$message = implode("\n", (array)$email->message());
$message = implode("\r\n", (array)$email->message());
return array('headers' => $headers, 'message' => $message);
}

Expand Down
16 changes: 6 additions & 10 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -542,15 +542,15 @@ public function testSendWithContent() {
$result = $this->CakeEmail->send("Here is my body, with multi lines.\nThis is the second line.\r\n\r\nAnd the last.");
$expected = array('headers', 'message');
$this->assertEquals($expected, array_keys($result));
$expected = "Here is my body, with multi lines.\nThis is the second line.\n\nAnd the last.\n\n";
$expected = "Here is my body, with multi lines.\r\nThis is the second line.\r\n\r\nAnd the last.\r\n\r\n";

$this->assertEquals($expected, $result['message']);
$this->assertTrue((bool)strpos($result['headers'], 'Date: '));
$this->assertTrue((bool)strpos($result['headers'], 'Message-ID: '));
$this->assertTrue((bool)strpos($result['headers'], 'To: '));

$result = $this->CakeEmail->send("Other body");
$expected = "Other body\n\n";
$expected = "Other body\r\n\r\n";
$this->assertIdentical($result['message'], $expected);
$this->assertTrue((bool)strpos($result['headers'], 'Message-ID: '));
$this->assertTrue((bool)strpos($result['headers'], 'To: '));
Expand Down Expand Up @@ -710,11 +710,7 @@ public function testSendAttachment() {
$this->CakeEmail->config(array());
$this->CakeEmail->attachments(array(CAKE . 'basics.php'));
$result = $this->CakeEmail->send('body');

$wrap = $this->CakeEmail->wrap($result['message']);
$this->assertTrue(in_array("Content-Type: application/octet-stream", $wrap));
$this->assertTrue(in_array("Content-Transfer-Encoding: base64", $wrap));
$this->assertTrue(in_array("Content-Disposition: attachment; filename=\"basics.php\"", $wrap));
$this->assertTrue((bool)strpos($result['message'], "Content-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"basics.php\""));

$this->CakeEmail->attachments(array('my.file.txt' => CAKE . 'basics.php'));
$result = $this->CakeEmail->send('body');
Expand All @@ -724,9 +720,9 @@ public function testSendAttachment() {
$result = $this->CakeEmail->send('body');
$this->assertTrue((bool)strpos($result['message'], "Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"file.txt\""));

$this->CakeEmail->attachments(array('file.txt' => array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain', 'contentId' => 'a1b1c1')));
$this->CakeEmail->send('body');
$this->assertTrue((bool)strpos($result['message'], "Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\nContent-ID: <a1b1c1>\r\nContent-Disposition: inline; filename=\"file.txt\""));
$this->CakeEmail->attachments(array('file2.txt' => array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain', 'contentId' => 'a1b1c1')));
$result = $this->CakeEmail->send('body');
$this->assertTrue((bool)strpos($result['message'], "Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\nContent-ID: <a1b1c1>\r\nContent-Disposition: inline; filename=\"file2.txt\""));
}

/**
Expand Down

0 comments on commit 3be9a8a

Please sign in to comment.