mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Merge pull request #1305 from jrbasso/2.4-fix-asset-full-url
Fixed full urls on asset methods
This commit is contained in:
commit
faa4262969
3 changed files with 59 additions and 2 deletions
|
@ -400,6 +400,9 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$result = $this->Html->image('http://google.com/logo.gif');
|
||||
$this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
|
||||
|
||||
$result = $this->Html->image('//google.com/logo.gif');
|
||||
$this->assertTags($result, array('img' => array('src' => '//google.com/logo.gif', 'alt' => '')));
|
||||
|
||||
$result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
|
||||
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
|
||||
|
||||
|
@ -408,6 +411,21 @@ 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' => '')));
|
||||
|
||||
$result = $this->Html->image('test.gif', array('pathPrefix' => '//cakephp.org/assets/img/'));
|
||||
$this->assertTags($result, array('img' => array('src' => '//cakephp.org/assets/img/test.gif', 'alt' => '')));
|
||||
|
||||
$previousConfig = Configure::read('App.imageBaseUrl');
|
||||
Configure::write('App.imageBaseUrl', '//cdn.cakephp.org/img/');
|
||||
$result = $this->Html->image('test.gif');
|
||||
$this->assertTags($result, array('img' => array('src' => '//cdn.cakephp.org/img/test.gif', 'alt' => '')));
|
||||
Configure::write('App.imageBaseUrl', $previousConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -593,6 +611,21 @@ 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);
|
||||
|
||||
$previousConfig = Configure::read('App.cssBaseUrl');
|
||||
Configure::write('App.cssBaseUrl', '//cdn.cakephp.org/css/');
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$expected['link']['href'] = '//cdn.cakephp.org/css/cake.generic.css';
|
||||
$this->assertTags($result, $expected);
|
||||
Configure::write('App.cssBaseUrl', $previousConfig);
|
||||
|
||||
Configure::write('Asset.filter.css', 'css.php');
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
|
||||
|
@ -926,6 +959,27 @@ 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);
|
||||
|
||||
$previousConfig = Configure::read('App.jsBaseUrl');
|
||||
Configure::write('App.jsBaseUrl', '//cdn.cakephp.org/js/');
|
||||
$result = $this->Html->script('foo4');
|
||||
$expected = array(
|
||||
'script' => array('type' => 'text/javascript', 'src' => '//cdn.cakephp.org/js/foo4.js')
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
Configure::write('App.jsBaseUrl', $previousConfig);
|
||||
|
||||
$result = $this->Html->script('foo');
|
||||
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
|
||||
|
||||
|
|
|
@ -324,6 +324,9 @@ class Helper extends Object {
|
|||
) {
|
||||
$path .= $options['ext'];
|
||||
}
|
||||
if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
|
||||
return $path;
|
||||
}
|
||||
if (isset($plugin)) {
|
||||
$path = Inflector::underscore($plugin) . '/' . $path;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue