Permalink
Browse files

Adding tests for $once parameter

  • Loading branch information...
1 parent efbef5f commit 100fdc1876916b01db6aaeb8cb8a810a15fe8cd7 @markstory markstory committed Mar 9, 2009
Showing with 31 additions and 25 deletions.
  1. +25 −25 cake/libs/view/helpers/js.php
  2. +6 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -21,7 +21,7 @@
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
+ **/
/**
* Javascript Generator helper class for easy use of JavaScript.
*
@@ -30,55 +30,55 @@
*
* @package cake
* @subpackage cake.cake.libs.view.helpers
- */
+ **/
class JsHelper extends AppHelper {
/**
* Base URL
*
* @var string
- */
+ **/
var $base = null;
/**
* Webroot path
*
* @var string
- */
+ **/
var $webroot = null;
/**
* Theme name
*
* @var string
- */
+ **/
var $themeWeb = null;
/**
* URL to current action.
*
* @var string
- */
+ **/
var $here = null;
/**
* Parameter array.
*
* @var array
- */
+ **/
var $params = array();
/**
* Current action.
*
* @var string
- */
+ **/
var $action = null;
/**
* Plugin path
*
* @var string
- */
+ **/
var $plugin = null;
/**
* POST data for models
*
* @var array
- */
+ **/
var $data = null;
/**
* helpers
@@ -91,7 +91,7 @@ class JsHelper extends AppHelper {
*
* @var array
* @access public
- */
+ **/
var $tags = array(
'javascriptblock' => '<script type="text/javascript">%s</script>',
'javascriptstart' => '<script type="text/javascript">',
@@ -116,21 +116,21 @@ class JsHelper extends AppHelper {
* __objects
*
* @var array
- */
+ **/
var $__objects = array();
/**
* output
*
* @var string
- */
+ **/
var $output = false;
/**
* Constructor - determines engine helper
*
* @param array $settings Settings array contains name of engine helper.
* @access public
* @return void
- */
+ **/
function __construct($settings = array()) {
$className = 'jquery';
if (is_array($settings) && isset($settings[0])) {
@@ -154,7 +154,7 @@ function __construct($settings = array()) {
* @param array $params Parameters for the method being called.
* @access public
* @return void
- */
+ **/
function call__($method, $params) {
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
return $this->{$this->__engineName}->dispatchMethod($method, $params);
@@ -245,7 +245,7 @@ function uses($url, $inline = true, $once = true) {
* @param string $url
* @param array $options
* @return string
- */
+ **/
function load_($url = null, $options = array()) {
if (isset($options['update'])) {
if (!is_array($options['update'])) {
@@ -313,14 +313,14 @@ function __object($name, $var) {
* Abstract Base Class for All JsEngines to extend. Provides generic methods.
*
* @package cake.view.helpers
- */
+ **/
class JsBaseEngineHelper extends AppHelper {
/**
* Determines whether native JSON extension is used for encoding. Set by object constructor.
*
* @var boolean
* @access public
- */
+ **/
var $useNative = false;
/**
* Constructor.
@@ -336,7 +336,7 @@ function __construct() {
* @param string $message Message you want to alter.
* @access public
* @return void
- */
+ **/
function alert($message) {
return 'alert("' . $this->escape($message) . '");';
}
@@ -346,7 +346,7 @@ function alert($message) {
* @param mixed $url
* @param array $options
* @return string
- */
+ **/
function redirect($url = null) {
return 'window.location = "' . Router::url($url) . '";';
}
@@ -356,7 +356,7 @@ function redirect($url = null) {
* @param string $message Message you want confirmed.
* @access public
* @return void
- */
+ **/
function confirm($message) {
return 'confirm("' . $this->escape($message) . '");';
}
@@ -367,7 +367,7 @@ function confirm($message) {
* @param string $default Default message
* @access public
* @return void
- */
+ **/
function prompt($message, $default = '') {
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
}
@@ -387,7 +387,7 @@ function prompt($message, $default = '') {
* @param array $options Set of options, see above.
* @return string A JSON code block
* @access public
- */
+ **/
function object($data = array(), $options = array()) {
$defaultOptions = array(
'block' => false, 'prefix' => '', 'postfix' => '',
@@ -450,7 +450,7 @@ function object($data = array(), $options = array()) {
* @param boolean $quoteStrings If false, leaves string values unquoted
* @return string a JavaScript-safe/JSON representation of $val
* @access public
- */
+ **/
function value($val, $quoteStrings = true) {
switch (true) {
case (is_array($val) || is_object($val)):
@@ -490,7 +490,7 @@ function value($val, $quoteStrings = true) {
* @param string $script String that needs to get escaped.
* @return string Escaped string.
* @access public
- */
+ **/
function escape($string) {
$escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
return str_replace(array_keys($escape), array_values($escape), $string);
@@ -202,6 +202,12 @@ function testUniqueScriptInsertion() {
$result = $this->Js->uses('foo');
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
+
+ $result = $this->Js->uses(array('foo', 'bar', 'baz'));
+ $this->assertNoPattern('/foo.js/', $result);
+
+ $result = $this->Js->uses('foo', true, false);
+ $this->assertNotNull($result);
}
}

0 comments on commit 100fdc1

Please sign in to comment.