From 316c6582ea5e0f6a45f9fc70b1cf72d0dcde5256 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Mon, 27 May 2013 22:48:59 -0400 Subject: [PATCH] Fixed pathPrefix for css and script methods --- .../Test/Case/View/Helper/HtmlHelperTest.php | 26 +++++++++++++++++++ lib/Cake/View/Helper/HtmlHelper.php | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index 054b09641..490c55d1c 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -408,6 +408,12 @@ class HtmlHelperTest extends CakeTestCase { $result = $this->Html->image('test.gif?one=two&three=four'); $this->assertTags($result, array('img' => array('src' => 'img/test.gif?one=two&three=four', 'alt' => ''))); + + $result = $this->Html->image('test.gif', array('pathPrefix' => '/my/custom/path/')); + $this->assertTags($result, array('img' => array('src' => '/my/custom/path/test.gif', 'alt' => ''))); + + $result = $this->Html->image('test.gif', array('pathPrefix' => 'http://cakephp.org/assets/img/')); + $this->assertTags($result, array('img' => array('src' => 'http://cakephp.org/assets/img/test.gif', 'alt' => ''))); } /** @@ -593,6 +599,14 @@ class HtmlHelperTest extends CakeTestCase { $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/'; $this->assertTags($result, $expected); + $result = $this->Html->css('cake.generic', array('pathPrefix' => '/my/custom/path/')); + $expected['link']['href'] = '/my/custom/path/cake.generic.css'; + $this->assertTags($result, $expected); + + $result = $this->Html->css('cake.generic', array('pathPrefix' => 'http://cakephp.org/assets/css/')); + $expected['link']['href'] = 'http://cakephp.org/assets/css/cake.generic.css'; + $this->assertTags($result, $expected); + Configure::write('Asset.filter.css', 'css.php'); $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/'; @@ -926,6 +940,18 @@ class HtmlHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Html->script('foo2', array('pathPrefix' => '/my/custom/path/')); + $expected = array( + 'script' => array('type' => 'text/javascript', 'src' => '/my/custom/path/foo2.js') + ); + $this->assertTags($result, $expected); + + $result = $this->Html->script('foo3', array('pathPrefix' => 'http://cakephp.org/assets/js/')); + $expected = array( + 'script' => array('type' => 'text/javascript', 'src' => 'http://cakephp.org/assets/js/foo3.js') + ); + $this->assertTags($result, $expected); + $result = $this->Html->script('foo'); $this->assertNull($result, 'Script returned upon duplicate inclusion %s'); diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 247cd6020..edc6728d6 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -445,7 +445,7 @@ class HtmlHelper extends AppHelper { $url = $path; } else { $url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssBaseUrl'), 'ext' => '.css')); - $options = array_diff_key($options, array('fullBase' => null)); + $options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null)); if (Configure::read('Asset.filter.css')) { $pos = strpos($url, Configure::read('App.cssBaseUrl')); @@ -546,7 +546,7 @@ class HtmlHelper extends AppHelper { if (strpos($url, '//') === false) { $url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js')); - $options = array_diff_key($options, array('fullBase' => null)); + $options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null)); if (Configure::read('Asset.filter.js')) { $url = str_replace(Configure::read('App.jsBaseUrl'), 'cjs/', $url);