Skip to content

Commit

Permalink
Fixed pathPrefix for css and script methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Aug 3, 2013
1 parent c0212a0 commit 316c658
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -408,6 +408,12 @@ public function testImageTag() {

$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' => '')));
}

/**
Expand Down Expand Up @@ -593,6 +599,14 @@ public function testCssLink() {
$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/';
Expand Down Expand Up @@ -926,6 +940,18 @@ public function testScript() {
);
$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');

Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -445,7 +445,7 @@ public function css($path, $options = array()) {
$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'));
Expand Down Expand Up @@ -546,7 +546,7 @@ public function script($url, $options = array()) {

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);
Expand Down

0 comments on commit 316c658

Please sign in to comment.