Skip to content

Commit

Permalink
Implementing assettimestamps for themes and plugins. Tests added. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 1, 2010
1 parent 8b9d9b1 commit dc72529
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cake/libs/view/helper.php
Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -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
*
Expand Down

0 comments on commit dc72529

Please sign in to comment.