Fix content view variable being stomped by send() parameter.

The content of send() should only be used if it is a non-empty value.

Fixes #4129
This commit is contained in:
mark_story 2013-10-08 12:28:26 -04:00
parent 105f032e81
commit f82b00c25e
2 changed files with 28 additions and 1 deletions

View file

@ -1313,6 +1313,9 @@ class CakeEmail {
* @return array Wrapped message
*/
protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) {
if (strlen($message) == 0) {
return array('');
}
$message = str_replace(array("\r\n", "\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
@ -1640,8 +1643,11 @@ class CakeEmail {
$layout = false;
}
foreach ($types as $type) {
if ($View->get('content') == '') {
$View->set('content', $content);
}
foreach ($types as $type) {
$View->hasRendered = false;
$View->viewPath = $View->layoutPath = 'Emails' . DS . $type;

View file

@ -904,6 +904,27 @@ class CakeEmailTest extends CakeTestCase {
$this->assertEquals(45, $result['timeout']);
}
/**
* Calling send() with no parameters should not overwrite the view variables.
*
* @return void
*/
public function testSendWithNoContentDoesNotOverwriteViewVar() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to('you@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->emailFormat('text');
$this->CakeEmail->template('default');
$this->CakeEmail->viewVars(array(
'content' => 'A message to you',
));
$result = $this->CakeEmail->send();
$this->assertContains('A message to you', $result['message']);
}
/**
* testSendWithContent method
*