diff --git a/lib/Cake/Network/CakeEmail.php b/lib/Cake/Network/CakeEmail.php index 8f985e4b3..f08f6e633 100644 --- a/lib/Cake/Network/CakeEmail.php +++ b/lib/Cake/Network/CakeEmail.php @@ -143,6 +143,13 @@ class CakeEmail { */ protected $_template = ''; +/** + * View for render + * + * @var string + */ + protected $_viewRender = 'View'; + /** * 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 * @@ -823,6 +840,7 @@ class CakeEmail { $this->_headers = array(); $this->_layout = 'default'; $this->_template = ''; + $this->_viewRender = 'View'; $this->_textMessage = ''; $this->_htmlMessage = ''; $this->_message = ''; @@ -1008,16 +1026,16 @@ class CakeEmail { * @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); diff --git a/lib/Cake/tests/Case/Network/CakeEmailTest.php b/lib/Cake/tests/Case/Network/CakeEmailTest.php index 1964d8287..df938da40 100644 --- a/lib/Cake/tests/Case/Network/CakeEmailTest.php +++ b/lib/Cake/tests/Case/Network/CakeEmailTest.php @@ -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(); } /** @@ -381,6 +395,27 @@ class CakeEmailTest extends CakeTestCase { $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 *