mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Correcting timestamp issues in JavascriptHelper::link(), fixes #4441
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6650 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f51f051bc2
commit
7e68ab152c
2 changed files with 42 additions and 31 deletions
|
@ -251,19 +251,18 @@ class JavascriptHelper extends AppHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
if (strpos($url, '?') === false) {
|
||||
if (strpos($url, '.js') === false) {
|
||||
$url .= '.js';
|
||||
}
|
||||
if ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
|
||||
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($url, '://') === false) {
|
||||
if ($url{0} !== '/') {
|
||||
$url = JS_URL . $url;
|
||||
}
|
||||
if (strpos($url, '?') === false) {
|
||||
if (strpos($url, '.js') === false) {
|
||||
$url .= '.js';
|
||||
}
|
||||
if ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
|
||||
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
|
||||
}
|
||||
}
|
||||
$url = $this->webroot($url);
|
||||
|
||||
if (Configure::read('Asset.filter.js')) {
|
||||
|
|
|
@ -71,28 +71,6 @@ class JavascriptTest extends UnitTestCase {
|
|||
$expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', true);
|
||||
$result = $this->Javascript->link('jquery-1.1.2');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*js\/jquery-1\.1\.2\.js\?"[^<>]*>/', $result);
|
||||
|
||||
$debug = Configure::read('debug');
|
||||
Configure::write('debug', 0);
|
||||
$result = $this->Javascript->link('jquery-1.1.2');
|
||||
$expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', 'force');
|
||||
$result = $this->Javascript->link('jquery-1.1.2');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*js\/jquery-1\.1\.2\.js\?"[^<>]*>/', $result);
|
||||
|
||||
Configure::write('debug', $debug);
|
||||
Configure::write('Asset.timestamp', false);
|
||||
|
||||
Configure::write('Asset.filter.js', 'js.php');
|
||||
$result = $this->Javascript->link('jquery-1.1.2');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*cjs\/jquery-1\.1\.2\.js"[^<>]*>/', $result);
|
||||
Configure::write('Asset.filter.js', false);
|
||||
|
||||
$result = $this->Javascript->link('/plugin/js/jquery-1.1.2');
|
||||
$expected = '<script type="text/javascript" src="/plugin/js/jquery-1.1.2.js"></script>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -110,6 +88,40 @@ class JavascriptTest extends UnitTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testFilteringAndTimestamping() {
|
||||
if (!is_writable(JS)) {
|
||||
echo "<br />JavaScript directory not writable, skipping JS asset timestamp tests<br />";
|
||||
return;
|
||||
}
|
||||
|
||||
cache(str_replace(WWW_ROOT, '', JS) . '__cake_js_test.js', 'alert("test")', '+999 days', 'public');
|
||||
$timestamp = substr(strtotime('now'), 0, 8);
|
||||
|
||||
Configure::write('Asset.timestamp', true);
|
||||
$result = $this->Javascript->link('__cake_js_test');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"[^<>]*>/', $result);
|
||||
|
||||
$debug = Configure::read('debug');
|
||||
Configure::write('debug', 0);
|
||||
$result = $this->Javascript->link('__cake_js_test');
|
||||
$expected = '<script type="text/javascript" src="js/__cake_js_test.js"></script>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', 'force');
|
||||
$result = $this->Javascript->link('__cake_js_test');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"[^<>]*>/', $result);
|
||||
|
||||
Configure::write('debug', $debug);
|
||||
Configure::write('Asset.timestamp', false);
|
||||
|
||||
Configure::write('Asset.filter.js', 'js.php');
|
||||
$result = $this->Javascript->link('__cake_js_test');
|
||||
$this->assertPattern('/^<script[^<>]+src=".*cjs\/__cake_js_test.js"[^<>]*>/', $result);
|
||||
Configure::write('Asset.filter.js', false);
|
||||
|
||||
unlink(JS . '__cake_js_test.js');
|
||||
}
|
||||
|
||||
function testObjectGeneration() {
|
||||
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8));
|
||||
|
||||
|
|
Loading…
Reference in a new issue