diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index be21205ad2c..74c9e0a0fad 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1441,6 +1441,12 @@ protected function _renderTemplates($content) { $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); diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 6d429aff126..ee4e8f64064 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1028,6 +1028,38 @@ public function testSendRenderWithHelpers() { $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 * diff --git a/lib/Cake/Test/test_app/View/Emails/html/image.ctp b/lib/Cake/Test/test_app/View/Emails/html/image.ctp new file mode 100644 index 00000000000..073d58ab6f9 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Emails/html/image.ctp @@ -0,0 +1,23 @@ +Html->image('image.gif', array( + 'alt' => 'cool image', + 'width' => 100, + 'height' => 100, + 'fullBase' => true, + )); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index d925ee8d37c..0061eac3f38 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -313,6 +313,9 @@ public function assetUrl($path, $options = array()) { $path = h($this->assetTimestamp($this->webroot($path))); if (!empty($options['fullBase'])) { + if ($path[0] == '/') { + $path = substr($path, 1); + } $path = $this->url('/', true) . $path; } }