Fixed pathPrefix for css and script methods

This commit is contained in:
Juan Basso 2013-05-27 22:48:59 -04:00
parent c0212a0454
commit 316c6582ea
2 changed files with 28 additions and 2 deletions

View file

@ -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');

View file

@ -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);