Skip to content

Commit

Permalink
Added support to return the html and text message.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 17, 2011
1 parent 33ca64f commit ff5365d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -792,9 +806,16 @@ public function addAttachments($attachments) {
/**
* 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;
}

Expand Down
29 changes: 29 additions & 0 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -539,6 +539,35 @@ public function testSendRenderWithVars() {
$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
*
Expand Down

0 comments on commit ff5365d

Please sign in to comment.