Permalink
Browse files

Fixed asset.timestamp inconsistency for css files.

Added tests to confirm css linking.
Closes #5990. Fixes #5991

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7990 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent 2879689 commit de1d1ae3bdb40113d16169e07b4e7af393963645 TommyO committed Jan 14, 2009
Showing with 53 additions and 24 deletions.
  1. +7 −9 cake/libs/view/helpers/html.php
  2. +46 −15 cake/tests/cases/libs/view/helpers/html.test.php
View
16 cake/libs/view/helpers/html.php
@@ -348,16 +348,16 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
}
}
- if (Configure::read('Asset.filter.css')) {
- $path = str_replace(CSS_URL, 'ccss/', $path);
- }
-
$path = $this->webroot($path);
- $url = $path;
+ $url = $path;
if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
}
+
+ if (Configure::read('Asset.filter.css')) {
+ $url = str_replace(CSS_URL, 'ccss/', $url);
+ }
}
if ($rel == 'import') {
@@ -432,11 +432,9 @@ function getCrumbs($separator = '»', $startText = false) {
function image($path, $options = array()) {
if (is_array($path)) {
$path = $this->url($path);
- } elseif ($path{0} === '/') {
+ } elseif ($path[0] === '/') {
$path = $this->webroot($path);
- } elseif (strpos($path, '://') !== false) {
- $path = $path;
- } else {
+ } elseif (strpos($path, '://') === false) {
if (Configure::read('Asset.timestamp') == true && Configure::read() > 0) {
$path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . IMAGES_URL . $path));
}
View
61 cake/tests/cases/libs/view/helpers/html.test.php
@@ -149,6 +149,8 @@ function testLink() {
);
$this->assertTags($result, $expected);
+ Configure::write('Asset.timestamp', false);
+
$result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
$expected = array(
'a' => array('href' => '#'),
@@ -164,6 +166,24 @@ function testLink() {
'/a'
);
$this->assertTags($result, $expected);
+
+ Configure::write('Asset.timestamp', true);
+
+ $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
+ $expected = array(
+ 'a' => array('href' => '#'),
+ 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
+ '/a'
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Html->image('test.gif', array('url' => '#'));
+ $expected = array(
+ 'a' => array('href' => '#'),
+ 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
+ '/a'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testImageTag method
@@ -172,6 +192,8 @@ function testLink() {
* @return void
*/
function testImageTag() {
+ Configure::write('Asset.timestamp', false);
+
$result = $this->Html->image('test.gif');
$this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
@@ -185,9 +207,9 @@ function testImageTag() {
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
Configure::write('Asset.timestamp', true);
+
$result = $this->Html->image('logo.gif');
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/logo\.gif\?\d*/', 'alt' => '')));
- Configure::write('Asset.timestamp', false);
}
/**
* testStyle method
@@ -212,6 +234,9 @@ function testStyle() {
* @return void
*/
function testCssLink() {
+ Configure::write('Asset.timestamp', false);
+ Configure::write('Asset.filter.css', false);
+
$result = $this->Html->css('screen');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
@@ -229,7 +254,27 @@ function testCssLink() {
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
$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/';
+ $this->assertTags($result, $expected);
+ Configure::write('Asset.filter.css', false);
+
+ $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
+ $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
+ $this->assertTags($result[0], $expected);
+ $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
+ $this->assertTags($result[1], $expected);
+ $this->assertEqual(count($result), 2);
+
Configure::write('Asset.timestamp', true);
+
+ Configure::write('Asset.filter.css', 'css.php');
+ $result = $this->Html->css('cake.generic');
+ $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css\?[0-9]+/';
+ $this->assertTags($result, $expected);
+ Configure::write('Asset.filter.css', false);
+
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
@@ -261,21 +306,7 @@ function testCssLink() {
$this->assertTags($result, $expected);
$this->Html->webroot = $webroot;
- Configure::write('Asset.timestamp', false);
Configure::write('debug', $debug);
-
- Configure::write('Asset.filter.css', 'css.php');
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
- $this->assertTags($result, $expected);
- Configure::write('Asset.filter.css', false);
-
- $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
- $this->assertTags($result[0], $expected);
- $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
- $this->assertTags($result[1], $expected);
- $this->assertEqual(count($result), 2);
}
/**
* testCharsetTag method

0 comments on commit de1d1ae

Please sign in to comment.