From 26d2237df02db6a7b51a12d112cfe82272fd5357 Mon Sep 17 00:00:00 2001 From: mark_story <mark@mark-story.com> Date: Tue, 22 Sep 2009 19:04:40 -0400 Subject: [PATCH] Making conditions easier to read. Adding additional test for image timestamping. Refs #108 --- cake/libs/view/helpers/html.php | 7 +++++-- cake/libs/view/helpers/javascript.php | 6 +++++- cake/tests/cases/libs/view/helpers/html.test.php | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 331b1ad8d..353a78b8b 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -373,9 +373,12 @@ class HtmlHelper extends AppHelper { $path .= '.css'; } } - + $timestampEnabled = ( + (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || + Configure::read('Asset.timestamp') === 'force' + ); $url = $this->webroot($path); - if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { + if (strpos($path, '?') === false && $timestampEnabled) { $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); } diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index b46fc14a4..ef4b0ab79 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -270,8 +270,12 @@ class JavascriptHelper extends AppHelper { $url .= '.js'; } } + $timestampEnabled = ( + (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || + Configure::read('Asset.timestamp') === 'force' + ); - if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { + if (strpos($url, '?') === false && $timestampEnabled) { $url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); } else { $url = $this->webroot($url); diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index 0a5b2f1f2..831cb048b 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -308,6 +308,15 @@ class HtmlHelperTest extends CakeTestCase { $result = $this->Html->image('cake.icon.gif'); $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => ''))); + + $webroot = $this->Html->webroot; + $this->Html->webroot = '/testing/longer/'; + $result = $this->Html->image('cake.icon.gif'); + $expected = array( + 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.gif\?[0-9]+/', 'alt' => '') + ); + $this->assertTags($result, $expected); + $this->Html->webroot = $webroot; } /**