Merge pull request #1207 from renansaddam/supportFullBaseOnScriptAndCss

Fix missing support for fullBase in script() & css()

HtmlHelper::script(), HtmlHelper::css() did not have support for fullBase
added when it was added to image(). Fix that omission.
This commit is contained in:
Mark Story 2013-03-29 18:04:47 -07:00
commit c7a378716b
3 changed files with 56 additions and 12 deletions

View file

@ -604,6 +604,22 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertNull($result); $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 * testPluginCssLink method
* *
@ -976,6 +992,30 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $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. * test a script file in the webroot/theme dir.
* *

View file

@ -1421,7 +1421,7 @@ class FormHelper extends AppHelper {
} }
unset($options['hiddenField']); 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 @@ class FormHelper extends AppHelper {
} }
$allOptions = array_merge($attributes, $optionsHere); $allOptions = array_merge($attributes, $optionsHere);
$out[] = $this->Html->useTag('radio', $attributes['name'], $tagName, $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 $optTitle
); );
} }
@ -1584,7 +1584,7 @@ class FormHelper extends AppHelper {
$options['type'] = $method; $options['type'] = $method;
} }
$options = $this->_initInputField($params[0], $options); $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 @@ class FormHelper extends AppHelper {
} }
unset($options['value']); 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 @@ class FormHelper extends AppHelper {
$this->_secure(true, null, '' . $options['value']); $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 @@ class FormHelper extends AppHelper {
$this->_secure($secure, array_merge($field, array($suffix))); $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)); return $this->Html->useTag('file', $options['name'], array_diff_key($options, $exclude));
} }
@ -2020,7 +2020,7 @@ class FormHelper extends AppHelper {
) { ) {
$this->_secure(true); $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 = ( $emptyMulti = (
$showEmpty !== null && $showEmpty !== false && !( $showEmpty !== null && $showEmpty !== false && !(

View file

@ -398,6 +398,7 @@ class HtmlHelper extends AppHelper {
* - `block` Set the name of the block link/style tag will be appended to. This overrides the `inline` * - `block` Set the name of the block link/style tag will be appended to. This overrides the `inline`
* option. * option.
* - `plugin` False value will prevent parsing path as a plugin * - `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 * @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 * CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
@ -429,6 +430,7 @@ class HtmlHelper extends AppHelper {
$url = $path; $url = $path;
} else { } else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css')); $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')) { if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL); $pos = strpos($url, CSS_URL);
@ -488,6 +490,7 @@ class HtmlHelper extends AppHelper {
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be * - `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. * 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 * - `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 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 * @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
@ -523,6 +526,7 @@ class HtmlHelper extends AppHelper {
if (strpos($url, '//') === false) { if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js')); $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')) { if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url); $url = str_replace(JS_URL, 'cjs/', $url);
@ -781,7 +785,7 @@ class HtmlHelper extends AppHelper {
*/ */
public function image($path, $options = array()) { public function image($path, $options = array()) {
$path = $this->assetUrl($path, $options + array('pathPrefix' => IMAGES_URL)); $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'])) { if (!isset($options['alt'])) {
$options['alt'] = ''; $options['alt'] = '';
@ -1085,10 +1089,10 @@ class HtmlHelper extends AppHelper {
$text = $options['text']; $text = $options['text'];
$options = array_diff_key($options, array( $options = array_diff_key($options, array(
'tag' => '', 'tag' => null,
'fullBase' => '', 'fullBase' => null,
'pathPrefix' => '', 'pathPrefix' => null,
'text' => '' 'text' => null
)); ));
return $this->tag($tag, $text, $options); return $this->tag($tag, $text, $options);
} }