Skip to content
Permalink
Browse files

Implementing assettimestamps for themes and plugins. Tests added. Fixes

  • Loading branch information...
markstory committed Jul 1, 2010
1 parent 8b9d9b1 commit dc7252964892f1839c0c4db5bcbffac4d7040803
Showing with 45 additions and 1 deletion.
  1. +16 −1 cake/libs/view/helper.php
  2. +29 −0 cake/tests/cases/libs/view/helper.test.php
@@ -246,7 +246,22 @@ function assetTimestamp($path) {
);
if (strpos($path, '?') === false && $timestampEnabled) {
$filepath = preg_replace('/^' . preg_quote($this->webroot, '/') . '/', '', $path);
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $filepath));
$webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
if (file_exists($webrootPath)) {
return $path . '?' . @filemtime($webrootPath);
}
$segments = explode('/', ltrim($filepath, '/'));
if ($segments[0] === 'theme') {
$theme = $segments[1];
unset($segments[0], $segments[1]);
$themePath = App::themePath($theme) . 'webroot' . DS . implode(DS, $segments);
return $path . '?' . @filemtime($themePath);
} else {
$plugin = $segments[0];
unset($segments[0]);
$pluginPath = App::pluginPath($plugin) . 'webroot' . DS . implode(DS, $segments);
return $path . '?' . @filemtime($pluginPath);
}
}
return $path;
}
@@ -490,6 +490,35 @@ function testAssetTimestamp() {
Configure::write('Asset.timestamp', $_timestamp);
}
/**
* test assetTimestamp with plugins and themes
*
* @return void
*/
function testAssetTimestampPluginsAndThemes() {
$_timestamp = Configure::read('Asset.timestamp');
Configure::write('Asset.timestamp', 'force');
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
));
$result = $this->Helper->assetTimestamp('/test_plugin/css/test_plugin_asset.css');
$this->assertPattern('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin');
$result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css');
$this->assertPattern('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file');
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/theme.js');
$this->assertPattern('#/theme/test_theme/js/theme.js\?[0-9]+$#', $result, 'Missing timestamp theme');
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/non_existant.js');
$this->assertPattern('#/theme/test_theme/js/non_existant.js\?$#', $result, 'No error on missing file');
App::build();
Configure::write('Asset.timestamp', $_timestamp);
}
/**
* testFieldsWithSameName method
*

0 comments on commit dc72529

Please sign in to comment.
You can’t perform that action at this time.