Fix email rendering when using 2 different plugins.

When an email template and layout are in different plugins the incorrect
plugin would be used for the layout.

Fixes #3062
This commit is contained in:
mark_story 2014-04-04 21:45:04 -04:00
parent b8e21c99ee
commit 4ec81542db
2 changed files with 16 additions and 8 deletions

View file

@ -1638,21 +1638,21 @@ class CakeEmail {
$View->plugin = $layoutPlugin;
}
// Convert null to false, as View needs false to disable
// the layout.
if ($layout === null) {
$layout = false;
}
if ($View->get('content') === null) {
$View->set('content', $content);
}
// Convert null to false, as View needs false to disable
// the layout.
if ($this->_layout === null) {
$this->_layout = false;
}
foreach ($types as $type) {
$View->hasRendered = false;
$View->viewPath = $View->layoutPath = 'Emails' . DS . $type;
$render = $View->render($template, $layout);
$render = $View->render($this->_template, $this->_layout);
$render = str_replace(array("\r\n", "\r"), "\n", $render);
$rendered[$type] = $this->_encodeString($render, $this->charset);
}

View file

@ -1472,7 +1472,7 @@ class CakeEmailTest extends CakeTestCase {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
@ -1493,6 +1493,14 @@ class CakeEmailTest extends CakeTestCase {
$this->assertContains('Into TestPlugin.', $result['message']);
$this->assertContains('This email was sent using the TestPlugin.', $result['message']);
$this->CakeEmail->template(
'TestPlugin.test_plugin_tpl',
'TestPluginTwo.default'
);
$result = $this->CakeEmail->send();
$this->assertContains('Into TestPlugin.', $result['message']);
$this->assertContains('This email was sent using TestPluginTwo.', $result['message']);
// test plugin template overridden by theme
$this->CakeEmail->theme('TestTheme');
$result = $this->CakeEmail->send();