Merge remote branch 'origin/1.3' into 1.3

This commit is contained in:
predominant 2010-04-09 21:58:25 +10:00
commit 21f61ee34a
5 changed files with 32 additions and 12 deletions

View file

@ -245,7 +245,8 @@ class Helper extends Overloadable {
Configure::read('Asset.timestamp') === 'force' Configure::read('Asset.timestamp') === 'force'
); );
if (strpos($path, '?') === false && $timestampEnabled) { if (strpos($path, '?') === false && $timestampEnabled) {
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); $filepath = preg_replace('/^' . preg_quote($this->webroot, '/') . '/', '', $path);
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $filepath));
} }
return $path; return $path;
} }

View file

@ -358,7 +358,7 @@ class HtmlHelper extends AppHelper {
$path .= '.css'; $path .= '.css';
} }
} }
$url = $this->webroot($this->assetTimestamp($path)); $url = $this->assetTimestamp($this->webroot($path));
if (Configure::read('Asset.filter.css')) { if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL); $pos = strpos($url, CSS_URL);
@ -434,7 +434,7 @@ class HtmlHelper extends AppHelper {
if (strpos($url, '?') === false && strpos($url, '.js') === false) { if (strpos($url, '?') === false && strpos($url, '.js') === false) {
$url .= '.js'; $url .= '.js';
} }
$url = $this->webroot($this->assetTimestamp($url)); $url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) { if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url); $url = str_replace(JS_URL, 'cjs/', $url);
@ -608,7 +608,7 @@ class HtmlHelper extends AppHelper {
if ($path[0] !== '/') { if ($path[0] !== '/') {
$path = IMAGES_URL . $path; $path = IMAGES_URL . $path;
} }
$path = $this->webroot($this->assetTimestamp($path)); $path = $this->assetTimestamp($this->webroot($path));
} }
if (!isset($options['alt'])) { if (!isset($options['alt'])) {

View file

@ -265,7 +265,7 @@ class JavascriptHelper extends AppHelper {
$url .= '.js'; $url .= '.js';
} }
} }
$url = $this->webroot($this->assetTimestamp($url)); $url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) { if (Configure::read('Asset.filter.js')) {
$pos = strpos($url, JS_URL); $pos = strpos($url, JS_URL);

View file

@ -467,6 +467,10 @@ class HelperTest extends CakeTestCase {
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam'); $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam'); $this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam');
$this->Helper->webroot = '/some/dir/';
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
Configure::write('debug', $_debug); Configure::write('debug', $_debug);
Configure::write('Asset.timestamp', $_timestamp); Configure::write('Asset.timestamp', $_timestamp);
} }

View file

@ -304,14 +304,15 @@ class HtmlHelperTest extends CakeTestCase {
function testImageWithTimestampping() { function testImageWithTimestampping() {
Configure::write('Asset.timestamp', 'force'); Configure::write('Asset.timestamp', 'force');
$this->Html->webroot = '/';
$result = $this->Html->image('cake.icon.png'); $result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.png\?\d+/', 'alt' => ''))); $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
Configure::write('debug', 0); Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force'); Configure::write('Asset.timestamp', 'force');
$result = $this->Html->image('cake.icon.png'); $result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.png\?\d+/', 'alt' => ''))); $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
$webroot = $this->Html->webroot; $webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/longer/'; $this->Html->webroot = '/testing/longer/';
@ -331,30 +332,42 @@ class HtmlHelperTest extends CakeTestCase {
* @link https://trac.cakephp.org/ticket/6490 * @link https://trac.cakephp.org/ticket/6490
*/ */
function testImageTagWithTheme() { function testImageTagWithTheme() {
if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) {
return;
}
App::import('Core', 'File');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
$file =& new File($testfile, true);
App::build(array( App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
)); ));
Configure::write('Asset.timestamp', true); Configure::write('Asset.timestamp', true);
Configure::write('debug', 1); Configure::write('debug', 1);
$this->Html->webroot = '/';
$this->Html->theme = 'test_theme'; $this->Html->theme = 'test_theme';
$result = $this->Html->image('cake.power.gif'); $result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array( $this->assertTags($result, array(
'img' => array( 'img' => array(
'src' => 'preg:/theme\/test_theme\/img\/cake\.power\.gif\?\d+/', 'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => '' 'alt' => ''
))); )));
$webroot = $this->Html->webroot; $webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/'; $this->Html->webroot = '/testing/';
$result = $this->Html->image('cake.power.gif'); $result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array( $this->assertTags($result, array(
'img' => array( 'img' => array(
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/cake\.power\.gif\?\d+/', 'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => '' 'alt' => ''
))); )));
$this->Html->webroot = $webroot; $this->Html->webroot = $webroot;
$dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$dir->delete();
} }
/** /**
@ -364,6 +377,7 @@ class HtmlHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testThemeAssetsInMainWebrootPath() { function testThemeAssetsInMainWebrootPath() {
Configure::write('Asset.timestamp', false);
App::build(array( App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
)); ));
@ -542,6 +556,7 @@ class HtmlHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testScript() { function testScript() {
Configure::write('Asset.timestamp', false);
$result = $this->Html->script('foo'); $result = $this->Html->script('foo');
$expected = array( $expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js') 'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')