Skip to content

Commit

Permalink
Fixes in render. Tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent d0f1843 commit 6e15945
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -143,6 +143,13 @@ class CakeEmail {
*/
protected $_template = '';

/**
* View for render
*
* @var string
*/
protected $_viewRender = 'View';

/**
* Text message
*
Expand Down Expand Up @@ -651,6 +658,16 @@ public function setLayout($layout, $template = null) {
}
}

/**
* Set view class for render
*
* @param string $viewClass
* @return void
*/
public function setViewRender($viewClass) {
$this->_viewRender = $viewClass;
}

/**
* Set the email format
*
Expand Down Expand Up @@ -823,6 +840,7 @@ public function reset() {
$this->_headers = array();
$this->_layout = 'default';
$this->_template = '';
$this->_viewRender = 'View';
$this->_textMessage = '';
$this->_htmlMessage = '';
$this->_message = '';
Expand Down Expand Up @@ -1008,16 +1026,16 @@ function _formatMessage($message) {
* @access private
*/
function _render($content) {
$viewClass = $this->Controller->view;
$viewClass = $this->_viewRender;

if ($viewClass !== 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass);
$viewClass = $viewClass . 'View';
App::import('View', $this->Controller->view);
App::import('View', $this->_viewRender);
}

$View = new $viewClass($this->Controller);
$View->layout = $this->layout;
$View = new $viewClass(null);
$View->layout = $this->_layout;
$msg = array();

$content = implode("\n", $content);
Expand Down
35 changes: 35 additions & 0 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -102,6 +102,20 @@ class CakeEmailTest extends CakeTestCase {
public function setUp() {
parent::setUp();
$this->CakeEmail = new TestCakeEmail();

App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
}

/**
* tearDown method
*
* @return void
*/
function tearDown() {
parent::tearDown();
App::build();
}

/**
Expand Down Expand Up @@ -381,6 +395,27 @@ public function testSendWithContent() {
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: '));
}

/**
* testSendRender method
*
* @return void
*/
public function testSendRender() {
$this->CakeEmail->reset();
$this->CakeEmail->setTransport('debug');
DebugTransport::$includeAddresses = true;

$this->CakeEmail->setFrom('cake@cakephp.org');
$this->CakeEmail->setTo(array('you@cakephp.org' => 'You'));
$this->CakeEmail->setSubject('My title');
$this->CakeEmail->setLayout('default', 'default');
$result = $this->CakeEmail->send();

$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the CakePHP Framework'));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'Message-ID: '));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: '));
}

/**
* testReset method
*
Expand Down

0 comments on commit 6e15945

Please sign in to comment.