Permalink
Browse files

Fixing tag generation for Html::script() and Html::css() when using '…

…fullBase' => true.

Changing values on array_diff_key() from empty ('') to null as they have no consequences and offer better readability.
  • Loading branch information...
renan committed Mar 29, 2013
1 parent 3a72876 commit 96c9174ee21a866584de2ed4fb0dc243929bed55
@@ -604,6 +604,22 @@ public function testCssLink() {
$this->assertNull($result);
}
/**
* testCssWithFullBase method
*
* @return void
*/
public function testCssWithFullBase() {
Configure::write('Asset.filter.css', false);
$here = $this->Html->url('/', true);
$result = $this->Html->css('screen', null, array('fullBase' => true));
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $here . 'css/screen.css')
);
$this->assertTags($result, $expected);
}
/**
* testPluginCssLink method
*
@@ -976,6 +992,30 @@ public function testScriptAssetFilter() {
$this->assertTags($result, $expected);
}
/**
* testScriptWithFullBase method
*
* @return void
*/
public function testScriptWithFullBase() {
$here = $this->Html->url('/', true);
$result = $this->Html->script('foo', array('fullBase' => true));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => $here . 'js/foo.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
$expected = array(
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/foobar.js')),
'/script',
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/bar.js')),
'/script',
);
$this->assertTags($result, $expected);
}
/**
* test a script file in the webroot/theme dir.
*
@@ -1421,7 +1421,7 @@ public function checkbox($fieldName, $options = array()) {
}
unset($options['hiddenField']);
return $output . $this->Html->useTag('checkbox', $options['name'], array_diff_key($options, array('name' => '')));
return $output . $this->Html->useTag('checkbox', $options['name'], array_diff_key($options, array('name' => null)));
}
/**
@@ -1527,7 +1527,7 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
}
$allOptions = array_merge($attributes, $optionsHere);
$out[] = $this->Html->useTag('radio', $attributes['name'], $tagName,
array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')),
array_diff_key($allOptions, array('name' => null, 'type' => null, 'id' => null)),
$optTitle
);
}
@@ -1584,7 +1584,7 @@ public function __call($method, $params) {
$options['type'] = $method;
}
$options = $this->_initInputField($params[0], $options);
return $this->Html->useTag('input', $options['name'], array_diff_key($options, array('name' => '')));
return $this->Html->useTag('input', $options['name'], array_diff_key($options, array('name' => null)));
}
/**
@@ -1610,7 +1610,7 @@ public function textarea($fieldName, $options = array()) {
}
unset($options['value']);
}
return $this->Html->useTag('textarea', $options['name'], array_diff_key($options, array('type' => '', 'name' => '')), $value);
return $this->Html->useTag('textarea', $options['name'], array_diff_key($options, array('type' => null, 'name' => null)), $value);
}
/**
@@ -1636,7 +1636,7 @@ public function hidden($fieldName, $options = array()) {
$this->_secure(true, null, '' . $options['value']);
}
return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => '')));
return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => null)));
}
/**
@@ -1659,7 +1659,7 @@ public function file($fieldName, $options = array()) {
$this->_secure($secure, array_merge($field, array($suffix)));
}
$exclude = array('name' => '', 'value' => '');
$exclude = array('name' => null, 'value' => null);
return $this->Html->useTag('file', $options['name'], array_diff_key($options, $exclude));
}
@@ -2020,7 +2020,7 @@ public function select($fieldName, $options = array(), $attributes = array()) {
) {
$this->_secure(true);
}
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => '', 'value' => '')));
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => null, 'value' => null)));
}
$emptyMulti = (
$showEmpty !== null && $showEmpty !== false && !(
@@ -398,6 +398,7 @@ public function link($title, $url = null, $options = array(), $confirmMessage =
* - `block` Set the name of the block link/style tag will be appended to. This overrides the `inline`
* option.
* - `plugin` False value will prevent parsing path as a plugin
* - `fullBase` If true the url will get a full address for the css file.
*
* @param string|array $path The name of a CSS style sheet or an array containing names of
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
@@ -429,6 +430,7 @@ public function css($path, $rel = null, $options = array()) {
$url = $path;
} else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));
$options = array_diff_key($options, array('fullBase' => null));
if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
@@ -488,6 +490,7 @@ public function css($path, $rel = null, $options = array()) {
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
* included once, use false to allow the same script to be included more than once per request.
* - `plugin` False value will prevent parsing path as a plugin
* - `fullBase` If true the url will get a full address for the script file.
*
* @param string|array $url String or array of javascript files to include
* @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
@@ -523,6 +526,7 @@ public function script($url, $options = array()) {
if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js'));
$options = array_diff_key($options, array('fullBase' => null));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
@@ -781,7 +785,7 @@ protected function _prepareCrumbs($startText) {
*/
public function image($path, $options = array()) {
$path = $this->assetUrl($path, $options + array('pathPrefix' => IMAGES_URL));
$options = array_diff_key($options, array('fullBase' => '', 'pathPrefix' => ''));
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
if (!isset($options['alt'])) {
$options['alt'] = '';
@@ -1085,10 +1089,10 @@ public function media($path, $options = array()) {
$text = $options['text'];
$options = array_diff_key($options, array(
'tag' => '',
'fullBase' => '',
'pathPrefix' => '',
'text' => ''
'tag' => null,
'fullBase' => null,
'pathPrefix' => null,
'text' => null
));
return $this->tag($tag, $text, $options);
}

0 comments on commit 96c9174

Please sign in to comment.