* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* 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
* @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
*/
App::import('Core', array('Controller', 'View', 'ClassRegistry', 'View'));
App::import('Helper', array('Javascript', 'Html', 'Form'));
/**
* TheJsTestController class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TheJsTestController extends Controller {
/**
* name property
*
* @var string 'TheTest'
* @access public
*/
var $name = 'TheTest';
/**
* uses property
*
* @var mixed null
* @access public
*/
var $uses = null;
}
/**
* TheView class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TheView extends View {
/**
* scripts method
*
* @access public
* @return void
*/
function scripts() {
return $this->__scripts;
}
}
/**
* TestJavascriptObject class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TestJavascriptObject {
/**
* property1 property
*
* @var string 'value1'
* @access public
*/
var $property1 = 'value1';
/**
* property2 property
*
* @var int 2
* @access public
*/
var $property2 = 2;
}
/**
* JavascriptTest class
*
* @package test_suite
* @subpackage test_suite.cases.libs
* @since CakePHP Test Suite v 1.0.0.0
*/
class JavascriptTest extends CakeTestCase {
/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$this->Javascript =& new JavascriptHelper();
$this->Javascript->Html =& new HtmlHelper();
$this->Javascript->Form =& new FormHelper();
$this->View =& new TheView(new TheJsTestController());
ClassRegistry::addObject('view', $this->View);
}
/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
unset($this->Javascript->Html);
unset($this->Javascript->Form);
unset($this->Javascript);
ClassRegistry::removeObject('view');
unset($this->View);
}
/**
* testConstruct method
*
* @access public
* @return void
*/
function testConstruct() {
$Javascript =& new JavascriptHelper(array('safe'));
$this->assertTrue($Javascript->safe);
$Javascript =& new JavascriptHelper(array('safe' => false));
$this->assertFalse($Javascript->safe);
}
/**
* testLink method
*
* @access public
* @return void
*/
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);
$result = $this->Javascript->link('http://example.com/jquery.js');
$expected = '';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link(array('prototype.js', 'scriptaculous.js'));
$this->assertPattern('/^\s*';
$this->assertNull($result);
$this->assertEqual(count($resultScripts), 1);
$this->assertEqual(current($resultScripts), $expected);
}
/**
* testFilteringAndTimestamping method
*
* @access public
* @return void
*/
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('/^';
$this->assertEqual($result, $expected);
if ($old === null) {
Configure::delete('Asset.filter.js');
}
$debug = Configure::read('debug');
$webroot = $this->Javascript->webroot;
Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force');
$this->Javascript->webroot = '/testing/';
$result = $this->Javascript->link('__cake_js_test');
$this->assertPattern('/^