Added support to return the html and text message.

This commit is contained in:
Juan Basso 2011-04-17 17:53:51 -04:00
parent 33ca64f505
commit ff5365d6ab
2 changed files with 52 additions and 2 deletions

View file

@ -52,6 +52,20 @@ class CakeEmail {
*/
const LINE_LENGTH_MUST = 998;
/**
* Type of message - HTML
*
* @constant MESSAGE_HTML
*/
const MESSAGE_HTML = 'html';
/**
* Type of message - TEXT
*
* @constant MESSAGE_TEXT
*/
const MESSAGE_TEXT = 'text';
/**
* Recipient of the email
*
@ -792,9 +806,16 @@ class CakeEmail {
/**
* Get generated message (used by transport classes)
*
* @return array
* @param mixed $type Use MESSAGE_* constants or null to return the full message as array
* @return mixed String if have type, array if type is null
*/
public function message() {
public function message($type = null) {
switch ($type) {
case self::MESSAGE_HTML:
return $this->_htmlMessage;
case self::MESSAGE_TEXT:
return $this->_textMessage;
}
return $this->_message;
}

View file

@ -539,6 +539,35 @@ class CakeEmailTest extends CakeTestCase {
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
}
/**
* testMessage method
*
* @return void
*/
public function testMessage() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->layout('default', 'default');
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();
$expected = '<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>';
$this->assertTrue((bool)strpos($this->CakeEmail->message(CakeEmail::MESSAGE_HTML), $expected));
$expected = 'This email was sent using the CakePHP Framework, http://cakephp.org.';
$this->assertTrue((bool)strpos($this->CakeEmail->message(CakeEmail::MESSAGE_TEXT), $expected));
$message = $this->CakeEmail->message();
$this->assertTrue(in_array('Content-Type: text/plain; charset=UTF-8', $message));
$this->assertTrue(in_array('Content-Type: text/html; charset=UTF-8', $message));
}
/**
* testReset method
*