From 0fb02cad2c53fecf0cf39d4deef552f1b6b00885 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Fri, 13 Mar 2015 17:04:24 -0500 Subject: [PATCH] Add getPlainTextMessage and getHtmlMessage methods. --- src/Fetch/Message.php | 18 ++++++++++++++++ tests/Fetch/Test/MessageTest.php | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index dbe9497..e16672d 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -373,6 +373,24 @@ class Message return false; } + /** + * This function returns the plain text version of the email or false if not present. + * @return string|bool Returns false if not present + */ + public function getPlainTextMessage() + { + return isset($this->plaintextMessage) ? $this->plaintextMessage : false; + } + + /** + * This function returns the HTML version of the email or false if not present. + * @return string|bool Returns false if not present + */ + public function getHtmlMessage() + { + return isset($this->htmlMessage) ? $this->htmlMessage : false; + } + /** * This function returns either an array of email addresses and names or, optionally, a string that can be used in * mail headers. diff --git a/tests/Fetch/Test/MessageTest.php b/tests/Fetch/Test/MessageTest.php index 970cd30..f795645 100644 --- a/tests/Fetch/Test/MessageTest.php +++ b/tests/Fetch/Test/MessageTest.php @@ -77,6 +77,43 @@ class MessageTest extends \PHPUnit_Framework_TestCase } + public function testGetPlainTextMessage() + { + // easiest way to deal with php encoding issues is simply not to. + $plaintextTest1 = 'f9377a89c9c935463a2b35c92dd61042'; + $plaintextTest2 = '0b8fc9b534a1789f1071f996f238a07a'; + $plaintextTest3 = 'd41d8cd98f00b204e9800998ecf8427e'; + + $message = static::getMessage(3); + $messagePlainText = $message->getPlainTextMessage(); + $this->assertEquals($plaintextTest1, md5($messagePlainText), 'Message returns as plaintext.'); + + $message = static::getMessage(4); + $messagePlainText = $message->getPlainTextMessage(); + $this->assertEquals($plaintextTest2, md5($messagePlainText), 'Message returns as plaintext.'); + + $message = static::getMessage(6); + $messagePlainText = $message->getPlainTextMessage(); + $this->assertEquals($plaintextTest3, md5($messagePlainText), 'Message does not return as plaintext.'); + + } + + public function testGetHtmlMessage() + { + // easiest way to deal with php encoding issues is simply not to. + $HtmlTest1 = 'd41d8cd98f00b204e9800998ecf8427e'; + $HtmlTest2 = '6a366ddecf080199284146d991d52169'; + + $message = static::getMessage(3); + $messageHtml = $message->getHtmlMessage(); + $this->assertEquals($HtmlTest1, md5($messageHtml), 'Message does not return as HTML.'); + + $message = static::getMessage(4); + $messageHtml = $message->getHtmlMessage(); + $this->assertEquals($HtmlTest2, md5($messageHtml), 'Message returns as HTML.'); + + } + public function testGetAddresses() { $message = static::getMessage(3);