Fixes in render. Tests added.

This commit is contained in:
Juan Basso 2011-03-04 08:29:38 -03:00
parent d0f1843dd5
commit 6e15945e73
2 changed files with 57 additions and 4 deletions

View file

@ -143,6 +143,13 @@ class CakeEmail {
*/ */
protected $_template = ''; protected $_template = '';
/**
* View for render
*
* @var string
*/
protected $_viewRender = 'View';
/** /**
* Text message * Text message
* *
@ -651,6 +658,16 @@ class CakeEmail {
} }
} }
/**
* Set view class for render
*
* @param string $viewClass
* @return void
*/
public function setViewRender($viewClass) {
$this->_viewRender = $viewClass;
}
/** /**
* Set the email format * Set the email format
* *
@ -823,6 +840,7 @@ class CakeEmail {
$this->_headers = array(); $this->_headers = array();
$this->_layout = 'default'; $this->_layout = 'default';
$this->_template = ''; $this->_template = '';
$this->_viewRender = 'View';
$this->_textMessage = ''; $this->_textMessage = '';
$this->_htmlMessage = ''; $this->_htmlMessage = '';
$this->_message = ''; $this->_message = '';
@ -1008,16 +1026,16 @@ class CakeEmail {
* @access private * @access private
*/ */
function _render($content) { function _render($content) {
$viewClass = $this->Controller->view; $viewClass = $this->_viewRender;
if ($viewClass !== 'View') { if ($viewClass !== 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass); list($plugin, $viewClass) = pluginSplit($viewClass);
$viewClass = $viewClass . 'View'; $viewClass = $viewClass . 'View';
App::import('View', $this->Controller->view); App::import('View', $this->_viewRender);
} }
$View = new $viewClass($this->Controller); $View = new $viewClass(null);
$View->layout = $this->layout; $View->layout = $this->_layout;
$msg = array(); $msg = array();
$content = implode("\n", $content); $content = implode("\n", $content);

View file

@ -102,6 +102,20 @@ class CakeEmailTest extends CakeTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->CakeEmail = new TestCakeEmail(); $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();
} }
/** /**
@ -381,6 +395,27 @@ class CakeEmailTest extends CakeTestCase {
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: ')); $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 * testReset method
* *