mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Refactored Helper::assetUrl() a bit and added test cases.
This commit is contained in:
parent
c0690a3eff
commit
b6f99bc0b9
2 changed files with 36 additions and 5 deletions
|
@ -589,6 +589,38 @@ class HelperTest extends CakeTestCase {
|
||||||
Configure::write('Asset.timestamp', $_timestamp);
|
Configure::write('Asset.timestamp', $_timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test assetUrl application
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAssetUrl() {
|
||||||
|
$this->Helper->webroot = '';
|
||||||
|
$_timestamp = Configure::read('Asset.timestamp');
|
||||||
|
|
||||||
|
$result = $this->Helper->assetUrl(array(
|
||||||
|
'controller' => 'js',
|
||||||
|
'action' => 'post',
|
||||||
|
'ext' => 'js'
|
||||||
|
),
|
||||||
|
array('fullBase' => true)
|
||||||
|
);
|
||||||
|
$this->assertEquals('http://localhost/js/post.js', $result);
|
||||||
|
|
||||||
|
$result = $this->Helper->assetUrl('foo.jpg', array('pathPrefix' => 'img/'));
|
||||||
|
$this->assertEquals('img/foo.jpg', $result);
|
||||||
|
|
||||||
|
$result = $this->Helper->assetUrl('foo.jpg', array('fullBase' => true));
|
||||||
|
$this->assertEquals('http://localhost/foo.jpg', $result);
|
||||||
|
|
||||||
|
Configure::write('Asset.timestamp', 'force');
|
||||||
|
|
||||||
|
$result = $this->Helper->assetUrl('cake.generic.css', array('pathPrefix' => CSS_URL));
|
||||||
|
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
|
||||||
|
|
||||||
|
Configure::write('Asset.timestamp', $_timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test assetTimestamp with plugins and themes
|
* test assetTimestamp with plugins and themes
|
||||||
*
|
*
|
||||||
|
|
|
@ -271,17 +271,16 @@ class Helper extends Object {
|
||||||
*/
|
*/
|
||||||
public function assetUrl($path, array $options) {
|
public function assetUrl($path, array $options) {
|
||||||
if (is_array($path)) {
|
if (is_array($path)) {
|
||||||
$path = $this->url($path);
|
$path = $this->url($path, !empty($options['fullBase']));
|
||||||
} elseif (strpos($path, '://') === false) {
|
} elseif (strpos($path, '://') === false) {
|
||||||
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
|
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
|
||||||
$path = $options['pathPrefix'] . $path;
|
$path = $options['pathPrefix'] . $path;
|
||||||
}
|
}
|
||||||
$path = $this->assetTimestamp($this->webroot($path));
|
$path = $this->assetTimestamp($this->webroot($path));
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($options['fullBase'])) {
|
if (!empty($options['fullBase'])) {
|
||||||
$path = $this->url('/', true) . $path;
|
$path = $this->url('/', true) . $path;
|
||||||
unset($options['fullBase']);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
|
|
Loading…
Add table
Reference in a new issue