* Copyright 2006-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
uses('view'.DS.'helpers'.DS.'app_helper', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'javascript','view'.DS.'view',
'view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form', 'class_registry', 'controller'.DS.'controller');
class TheJsTestController extends Controller {
var $name = 'TheTest';
var $uses = null;
}
/**
* Short description for class.
*
* @package test_suite
* @subpackage test_suite.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/
class JavascriptTest extends UnitTestCase {
function setUp() {
$this->Javascript = new JavascriptHelper();
$this->Javascript->Html = new HtmlHelper();
$this->Javascript->Form = new FormHelper();
$view =& new View(new TheJsTestController());
ClassRegistry::addObject('view', $view);
}
function testLink() {
$result = $this->Javascript->link('script.js');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('script');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('scriptaculous.js?load=effects');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('jquery-1.1.2');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('jquery-1.1.2');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('/plugin/js/jquery-1.1.2');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('/some_other_path/myfile.1.2.2.min.js');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('some_other_path/myfile.1.2.2.min.js');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('some_other_path/myfile.1.2.2.min');
$expected = '';
$this->assertEqual($result, $expected);
}
function testFilteringAndTimestamping() {
if (!is_writable(JS)) {
echo "
JavaScript directory not writable, skipping JS asset timestamp tests
";
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('/^';
$this->assertEqual($result, $expected);
Configure::write('Asset.timestamp', 'force');
$result = $this->Javascript->link('__cake_js_test');
$this->assertPattern('/^", $result);
$this->Javascript->cacheEvents(false, true);
$this->assertFalse($this->Javascript->inBlock);
$result = $this->Javascript->codeBlock();
$this->assertIdentical($result, null);
$this->assertTrue($this->Javascript->inBlock);
echo 'alert("this is a buffered script");';
$result = $this->Javascript->blockEnd();
$this->assertIdentical($result, null);
$this->assertFalse($this->Javascript->inBlock);
$result = $this->Javascript->getCache();
$this->assertEqual('alert("this is a buffered script");', $result);
}
function testOutOfLineScriptWriting() {
echo $this->Javascript->codeBlock('$(document).ready(function() { /* ... */ });', array('inline' => false));
$this->Javascript->codeBlock(null, array('inline' => false));
echo '$(function(){ /* ... */ });';
$this->Javascript->blockEnd();
$view =& ClassRegistry::getObject('view');
}
function testEvent() {
$result = $this->Javascript->event('myId', 'click', 'something();');
$this->assertPattern('/^