Add more unit tests for the legacy Mail class

This commit is contained in:
Kijin Sung 2016-05-23 21:58:37 +09:00
parent c8c319b988
commit 53169710a7
2 changed files with 17 additions and 1 deletions

View file

@ -115,7 +115,7 @@ class Mail extends Rhymix\Framework\Mail
*/ */
public function getPlainContent() public function getPlainContent()
{ {
return chunk_split(base64_encode(str_replace(array("<", ">", "&"), array("&lt;", "&gt;", "&amp;"), $this->message->getBody()))); return chunk_split(base64_encode(htmlspecialchars($this->message->getBody())));
} }
/** /**

View file

@ -156,5 +156,21 @@ class MailTest extends \Codeception\TestCase\Test
$mail->setBcc('bcc-1@rhymix.org'); $mail->setBcc('bcc-1@rhymix.org');
$mail->setBcc('bcc-2@rhymix.org'); $mail->setBcc('bcc-2@rhymix.org');
$this->assertEquals(array('bcc-2@rhymix.org' => ''), $mail->message->getBcc()); $this->assertEquals(array('bcc-2@rhymix.org' => ''), $mail->message->getBcc());
$content = '<p>Hello world!</p><p>This is a long message to test chunk splitting.</p><p>This feature is only available using the legacy Mail class.</p>';
$mail->setBody($content);
$this->assertEquals(chunk_split(base64_encode($content)), $mail->getHTMLContent());
$this->assertEquals(chunk_split(base64_encode(htmlspecialchars($content))), $mail->getPlainContent());
$mail->addAttachment(\RX_BASEDIR . 'tests/_data/formatter/minify.target.css', 'target.css');
$cid = $mail->addCidAttachment(\RX_BASEDIR . 'tests/_data/formatter/minify.target.css', 'thisismyrandomcid@rhymix.org');
$this->assertEquals('cid:thisismyrandomcid@rhymix.org', $cid);
$attachments = $mail->getAttachments();
$this->assertEquals(2, count($attachments));
$this->assertEquals('attach', $attachments[0]->type);
$this->assertEquals('target.css', $attachments[0]->display_filename);
$this->assertEquals('embed', $attachments[1]->type);
$this->assertEquals('cid:thisismyrandomcid@rhymix.org', $attachments[1]->cid);
} }
} }