mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Implemented the support to use helpers in CakeEmail. Fixes #1754
This commit is contained in:
parent
b4a780332f
commit
d220ee5578
5 changed files with 96 additions and 0 deletions
|
@ -332,6 +332,7 @@ class EmailComponent extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
$lib->subject($this->subject)->messageID($this->messageId);
|
$lib->subject($this->subject)->messageID($this->messageId);
|
||||||
|
$lib->helpers($this->_controller->helpers);
|
||||||
|
|
||||||
$headers = array('X-Mailer' => $this->xMailer);
|
$headers = array('X-Mailer' => $this->xMailer);
|
||||||
foreach ($this->headers as $key => $value) {
|
foreach ($this->headers as $key => $value) {
|
||||||
|
|
|
@ -181,6 +181,13 @@ class CakeEmail {
|
||||||
*/
|
*/
|
||||||
protected $_viewVars = array();
|
protected $_viewVars = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helpers to be used in the render
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_helpers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text message
|
* Text message
|
||||||
*
|
*
|
||||||
|
@ -715,6 +722,20 @@ class CakeEmail {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helpers to be used in render
|
||||||
|
*
|
||||||
|
* @param array $helpers
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function helpers($helpers = null) {
|
||||||
|
if ($helpers === null) {
|
||||||
|
return $this->_helpers;
|
||||||
|
}
|
||||||
|
$this->_helpers = (array)$helpers;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Email format
|
* Email format
|
||||||
*
|
*
|
||||||
|
@ -1057,6 +1078,7 @@ class CakeEmail {
|
||||||
$this->_template = '';
|
$this->_template = '';
|
||||||
$this->_viewRender = 'View';
|
$this->_viewRender = 'View';
|
||||||
$this->_viewVars = array();
|
$this->_viewVars = array();
|
||||||
|
$this->_helpers = array();
|
||||||
$this->_textMessage = '';
|
$this->_textMessage = '';
|
||||||
$this->_htmlMessage = '';
|
$this->_htmlMessage = '';
|
||||||
$this->_message = '';
|
$this->_message = '';
|
||||||
|
@ -1260,6 +1282,7 @@ class CakeEmail {
|
||||||
|
|
||||||
$View = new $viewClass(null);
|
$View = new $viewClass(null);
|
||||||
$View->viewVars = $this->_viewVars;
|
$View->viewVars = $this->_viewVars;
|
||||||
|
$View->helpers = $this->_helpers;
|
||||||
$msg = array();
|
$msg = array();
|
||||||
|
|
||||||
list($templatePlugin, $template) = pluginSplit($this->_template, true);
|
list($templatePlugin, $template) = pluginSplit($this->_template, true);
|
||||||
|
|
|
@ -501,6 +501,7 @@ TEXTBLOC;
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p>Here is your value: <b>22091985</b></p>
|
<p>Here is your value: <b>22091985</b></p>
|
||||||
|
|
||||||
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -522,6 +523,35 @@ HTMLBLOC;
|
||||||
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testMessageRetrievalWithHelper method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMessageRetrievalWithHelper() {
|
||||||
|
App::build(array(
|
||||||
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
|
||||||
|
));
|
||||||
|
|
||||||
|
$timestamp = time();
|
||||||
|
$this->Controller->set('time', $timestamp);
|
||||||
|
$this->Controller->set('title_for_layout', 'EmailTest');
|
||||||
|
$this->Controller->helpers = array('Time');
|
||||||
|
|
||||||
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||||
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||||
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||||
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||||
|
$this->Controller->EmailTest->layout = 'default';
|
||||||
|
$this->Controller->EmailTest->template = 'custom_helper';
|
||||||
|
$this->Controller->EmailTest->sendAs = 'text';
|
||||||
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||||
|
|
||||||
|
$this->assertTrue($this->Controller->EmailTest->send());
|
||||||
|
$this->assertTrue((bool)strpos($this->Controller->EmailTest->textMessage, 'Right now: ' . date('Y-m-d\TH:i:s\Z', $timestamp)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testContentArray method
|
* testContentArray method
|
||||||
*
|
*
|
||||||
|
|
|
@ -616,6 +616,29 @@ class CakeEmailTest extends CakeTestCase {
|
||||||
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
|
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testSendRenderWithHelpers method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSendRenderWithHelpers() {
|
||||||
|
$this->CakeEmail->reset();
|
||||||
|
$this->CakeEmail->transport('debug');
|
||||||
|
DebugTransport::$includeAddresses = true;
|
||||||
|
|
||||||
|
$timestamp = time();
|
||||||
|
$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('custom_helper', 'default');
|
||||||
|
$this->CakeEmail->viewVars(array('time' => $timestamp));
|
||||||
|
$this->CakeEmail->helpers(array('Time'));
|
||||||
|
$result = $this->CakeEmail->send();
|
||||||
|
|
||||||
|
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Right now: ' . date('Y-m-d\TH:i:s\Z', $timestamp)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSendRenderPlugin method
|
* testSendRenderPlugin method
|
||||||
*
|
*
|
||||||
|
|
19
lib/Cake/Test/test_app/View/Emails/text/custom_helper.ctp
Normal file
19
lib/Cake/Test/test_app/View/Emails/text/custom_helper.ctp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake.libs.view.templates.pages
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
Right now: <?php echo $this->Time->toAtom($time); ?>
|
Loading…
Add table
Reference in a new issue