CakeEmail: create request object before rendering

Closes #2931
This commit is contained in:
Rachman Chavik 2012-06-03 15:52:21 +07:00
parent d1819dcabb
commit 9bafc5a3bb
4 changed files with 64 additions and 0 deletions

View file

@ -1441,6 +1441,12 @@ class CakeEmail {
$View = new $viewClass(null);
$View->viewVars = $this->_viewVars;
$View->helpers = $this->_helpers;
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest('/', false);
$request->base = '';
$request->here = $request->webroot = '/';
}
$View->request = $request;
list($templatePlugin, $template) = pluginSplit($this->_template);
list($layoutPlugin, $layout) = pluginSplit($this->_layout);

View file

@ -1028,6 +1028,38 @@ class CakeEmailTest extends CakeTestCase {
$this->assertEquals(array('Time'), $result);
}
/**
* testSendRenderWithImage method
*
* @return void
*/
public function testSendRenderWithImage() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
$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('image');
$this->CakeEmail->emailFormat('html');
$View = new View();
$View->request = new CakeRequest('/', true);
$View->request->base = '';
$View->request->webroot = '/';
$View->request->here = '/';
$View->Helpers->load('Html');
$expected = $View->Html->image('image.gif', array(
'fullBase' => true, 'alt' => 'cool image',
'width' => 100, 'height' => 100,
));
$result = $this->CakeEmail->send();
$this->assertContains($expected, $result['message']);
}
/**
* testSendRenderPlugin method
*

View file

@ -0,0 +1,23 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @since CakePHP(tm) v 2.1
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
echo $this->Html->image('image.gif', array(
'alt' => 'cool image',
'width' => 100,
'height' => 100,
'fullBase' => true,
));

View file

@ -313,6 +313,9 @@ class Helper extends Object {
$path = h($this->assetTimestamp($this->webroot($path)));
if (!empty($options['fullBase'])) {
if ($path[0] == '/') {
$path = substr($path, 1);
}
$path = $this->url('/', true) . $path;
}
}