2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2009-03-06 19:51:13 -05:00
|
|
|
* JsHelper Test Case
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-06 19:51:13 -05:00
|
|
|
* TestCase for the JsHelper
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @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
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-03-06 19:51:13 -05:00
|
|
|
App::import('Helper', 'Js');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-03-07 02:26:19 -05:00
|
|
|
Mock::generate('Helper', 'TestJsEngineHelper', array('methodOne'));
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-06 19:51:13 -05:00
|
|
|
* JsHelper TestCase.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-03-06 19:51:13 -05:00
|
|
|
class JsHelperTestCase extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-03-06 19:51:13 -05:00
|
|
|
function startTest() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Js = new JsHelper();
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-03-06 19:51:13 -05:00
|
|
|
function endTest() {
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($this->Js);
|
|
|
|
}
|
2009-03-07 02:26:19 -05:00
|
|
|
/**
|
|
|
|
* test object construction
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testConstruction() {
|
|
|
|
$js = new JsHelper();
|
|
|
|
$this->assertEqual($js->helpers, array('jqueryEngine'));
|
|
|
|
|
|
|
|
$js = new JsHelper(array('mootools'));
|
|
|
|
$this->assertEqual($js->helpers, array('mootoolsEngine'));
|
|
|
|
|
|
|
|
$js = new JsHelper('prototype');
|
|
|
|
$this->assertEqual($js->helpers, array('prototypeEngine'));
|
|
|
|
|
|
|
|
$js = new JsHelper('MyPlugin.Dojo');
|
|
|
|
$this->assertEqual($js->helpers, array('MyPlugin.DojoEngine'));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test that methods dispatch internally and to the engine class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testMethodDispatching() {
|
|
|
|
$js = new JsHelper(array('TestJs'));
|
|
|
|
$js->TestJsEngine = new TestJsEngineHelper();
|
|
|
|
$js->TestJsEngine->expectOnce('dispatchMethod', array('methodOne', array()));
|
|
|
|
|
|
|
|
$js->methodOne();
|
|
|
|
}
|
2009-03-06 19:51:13 -05:00
|
|
|
/**
|
|
|
|
* test escape string skills
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testEscaping() {
|
|
|
|
$result = $this->Js->escape('');
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->escape('CakePHP' . "\n" . 'Rapid Development Framework');
|
|
|
|
$expected = 'CakePHP\\nRapid Development Framework';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->escape('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP');
|
|
|
|
$expected = 'CakePHP\\nRapid Development Framework\\nFor PHP';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->escape('CakePHP: "Rapid Development Framework"');
|
|
|
|
$expected = 'CakePHP: \\"Rapid Development Framework\\"';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->escape('CakePHP: \'Rapid Development Framework\'');
|
|
|
|
$expected = 'CakePHP: \\\'Rapid Development Framework\\\'';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->escape('my \\"string\\"');
|
|
|
|
$expected = 'my \\\"string\\\"';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-03-06 19:56:28 -05:00
|
|
|
/**
|
|
|
|
* test prompt() creation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testPrompt() {
|
|
|
|
$result = $this->Js->prompt('Hey, hey you', 'hi!');
|
|
|
|
$expected = 'prompt("Hey, hey you", "hi!");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->prompt('"Hey"', '"hi"');
|
|
|
|
$expected = 'prompt("\"Hey\"", "\"hi\"");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test alert generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test confirm generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testConfirm() {
|
|
|
|
$result = $this->Js->confirm('Are you sure?');
|
|
|
|
$expected = 'confirm("Are you sure?");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Js->confirm('"Are you sure?"');
|
|
|
|
$expected = 'confirm("\"Are you sure?\"");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-03-07 02:26:19 -05:00
|
|
|
/**
|
|
|
|
* test Redirect
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testRedirect() {
|
|
|
|
$result = $this->Js->redirect(array('controller' => 'posts', 'action' => 'view', 1));
|
|
|
|
$expected = 'window.location = "/posts/view/1";';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|