Skip to content
Permalink
Browse files

Adding tests for timestamping

  • Loading branch information...
markstory committed Mar 8, 2009
1 parent 0c77cc9 commit 93a2e8fcadd116dabe58561266917942b79c831e
Showing with 44 additions and 6 deletions.
  1. +44 −6 cake/tests/cases/libs/view/helpers/js.test.php
@@ -25,8 +25,11 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Helper', 'Js');
App::import('Core', array('View', 'ClassRegistry'));
Mock::generate('Helper', 'TestJsEngineHelper', array('methodOne'));
Mock::generate('View', 'JsHelperView');
/**
* JsHelper TestCase.
*
@@ -50,6 +53,7 @@ function startTest() {
* @return void
*/
function endTest() {
ClassRegistry::removeObject('view');
unset($this->Js);
}
/**
@@ -139,7 +143,7 @@ function testAlert() {
$result = $this->Js->alert('Hey there');
$expected = 'alert("Hey there");';
$this->assertEqual($result, $expected);
$result = $this->Js->alert('"Hey"');
$expected = 'alert("\"Hey\"");';
$this->assertEqual($result, $expected);
@@ -155,7 +159,7 @@ function testUses() {
'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')
);
$this->assertTags($result, $expected);
$result = $this->Js->uses('jquery-1.3');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js')
@@ -182,6 +186,13 @@ function testUses() {
'/script',
);
$this->assertTags($result, $expected);
$view = new JsHelperView();
ClassRegistry::addObject('view', $view);
$view->expectOnce('addScript');
$result = $this->Js->uses('test', false);
$this->assertNull($result);
}
/**
* test Min/pack version autofinding
@@ -195,20 +206,47 @@ function testMinPackAutoUse() {
Configure::write('debug', 0);
touch(WWW_ROOT . 'js' . DS. '__cake_js_min_test.min.js');
touch(WWW_ROOT . 'js' . DS. '__cake_js_pack_test.pack.js');
$result = $this->Js->uses('__cake_js_min_test');
$this->assertPattern('/__cake_js_min_test\.min\.js/', $result);
$result = $this->Js->uses('__cake_js_pack_test');
$this->assertPattern('/__cake_js_pack_test\.pack\.js/', $result);
Configure::write('debug', 2);
$result = $this->Js->uses('__cake_js_pack_test');
$this->assertNoPattern('/pack\.js/', $result);
unlink(WWW_ROOT . 'js' . DS. '__cake_js_min_test.min.js');
unlink(WWW_ROOT . 'js' . DS. '__cake_js_pack_test.pack.js');
}
/**
* test timestamp enforcement
*
* @return void
**/
function testAssetTimestamping() {
if ($this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped')) {
return;
}
Configure::write('Asset.timestamp', true);
touch(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
$timestamp = substr(strtotime('now'), 0, 8);
$result = $this->Js->uses('__cake_js_test');
$this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result);
Configure::write('debug', 0);
$result = $this->Js->uses('__cake_js_test');
$this->assertPattern('/__cake_js_test.js"/', $result);
Configure::write('Asset.timestamp', 'force');
$result = $this->Js->uses('__cake_js_test');
$this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result);
unlink(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
}
/**
* test confirm generation
*

0 comments on commit 93a2e8f

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