Skip to content

Commit 26d2237

Browse files
committed
Making conditions easier to read.
Adding additional test for image timestamping. Refs #108
1 parent de47373 commit 26d2237

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

cake/libs/view/helpers/html.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,12 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
373373
$path .= '.css';
374374
}
375375
}
376-
376+
$timestampEnabled = (
377+
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
378+
Configure::read('Asset.timestamp') === 'force'
379+
);
377380
$url = $this->webroot($path);
378-
if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
381+
if (strpos($path, '?') === false && $timestampEnabled) {
379382
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
380383
}
381384

cake/libs/view/helpers/javascript.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,12 @@ function link($url, $inline = true) {
270270
$url .= '.js';
271271
}
272272
}
273+
$timestampEnabled = (
274+
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
275+
Configure::read('Asset.timestamp') === 'force'
276+
);
273277

274-
if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
278+
if (strpos($url, '?') === false && $timestampEnabled) {
275279
$url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
276280
} else {
277281
$url = $this->webroot($url);

cake/tests/cases/libs/view/helpers/html.test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ function testImageTag() {
308308

309309
$result = $this->Html->image('cake.icon.gif');
310310
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => '')));
311+
312+
$webroot = $this->Html->webroot;
313+
$this->Html->webroot = '/testing/longer/';
314+
$result = $this->Html->image('cake.icon.gif');
315+
$expected = array(
316+
'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.gif\?[0-9]+/', 'alt' => '')
317+
);
318+
$this->assertTags($result, $expected);
319+
$this->Html->webroot = $webroot;
311320
}
312321

313322
/**

0 commit comments

Comments
 (0)