mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Supporting template/layout in plugins for CakeEmail. Fixes #1743.
This commit is contained in:
parent
282196a7cd
commit
cb88b952f4
4 changed files with 57 additions and 3 deletions
|
@ -1262,6 +1262,14 @@ class CakeEmail {
|
|||
$View->viewVars = $this->_viewVars;
|
||||
$msg = array();
|
||||
|
||||
list($templatePlugin, $template) = pluginSplit($this->_template, true);
|
||||
list($layoutPlugin, $layout) = pluginSplit($this->_layout, true);
|
||||
if (!empty($templatePlugin)) {
|
||||
$View->plugin = rtrim($templatePlugin, '.');
|
||||
} elseif (!empty($layoutPlugin)) {
|
||||
$View->plugin = rtrim($layoutPlugin, '.');
|
||||
}
|
||||
|
||||
$content = implode("\n", $content);
|
||||
|
||||
if ($this->_emailFormat === 'both') {
|
||||
|
@ -1278,7 +1286,7 @@ class CakeEmail {
|
|||
|
||||
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'text';
|
||||
$View->viewVars['content'] = $originalContent;
|
||||
$this->_textMessage = str_replace(array("\r\n", "\r"), "\n", $View->render($this->_template, $this->_layout));
|
||||
$this->_textMessage = str_replace(array("\r\n", "\r"), "\n", $View->render($template, $layout));
|
||||
$content = explode("\n", $this->_textMessage);
|
||||
$msg = array_merge($msg, $content);
|
||||
|
||||
|
@ -1291,7 +1299,7 @@ class CakeEmail {
|
|||
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html';
|
||||
$View->viewVars['content'] = $originalContent;
|
||||
$View->hasRendered = false;
|
||||
$this->_htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->render($this->_template, $this->_layout));
|
||||
$this->_htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->render($template, $layout));
|
||||
$content = explode("\n", $this->_htmlMessage);
|
||||
$msg = array_merge($msg, $content);
|
||||
|
||||
|
@ -1319,7 +1327,7 @@ class CakeEmail {
|
|||
|
||||
$View->viewPath = $View->layoutPath = 'Emails' . DS . $this->_emailFormat;
|
||||
$View->viewVars['content'] = $content;
|
||||
$rendered = $View->render($this->_template, $this->_layout);
|
||||
$rendered = $View->render($template, $layout);
|
||||
$content = explode("\n", $rendered);
|
||||
|
||||
if ($this->_emailFormat === 'html') {
|
||||
|
|
|
@ -616,6 +616,47 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendRenderPlugin method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendRenderPlugin() {
|
||||
App::build(array(
|
||||
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
||||
));
|
||||
CakePlugin::load('TestPlugin');
|
||||
|
||||
$this->CakeEmail->reset();
|
||||
$this->CakeEmail->transport('debug');
|
||||
DebugTransport::$includeAddresses = true;
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
|
||||
$this->CakeEmail->subject('My title');
|
||||
$this->CakeEmail->config(array('empty'));
|
||||
|
||||
$this->CakeEmail->template('TestPlugin.test_plugin_tpl', 'default')->send();
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Into TestPlugin.'));
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the CakePHP Framework'));
|
||||
|
||||
$this->CakeEmail->template('TestPlugin.test_plugin_tpl', 'TestPlugin.plug_default')->send();
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Into TestPlugin.'));
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the TestPlugin.'));
|
||||
|
||||
DebugTransport::$lastEmail = '';
|
||||
$this->CakeEmail->template('TestPlugin.test_plugin_tpl', 'plug_default')->send();
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Into TestPlugin.'));
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the TestPlugin.'));
|
||||
|
||||
$this->CakeEmail->viewVars(array('value' => 12345));
|
||||
$this->CakeEmail->template('custom', 'TestPlugin.plug_default')->send();
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
|
||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the TestPlugin.'));
|
||||
|
||||
$this->expectException();
|
||||
$this->CakeEmail->template('test_plugin_tpl', 'plug_default')->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendMultipleMIME method
|
||||
*
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Into TestPlugin.
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
<?php echo $content_for_layout; ?>
|
||||
|
||||
This email was sent using the TestPlugin.
|
Loading…
Add table
Reference in a new issue