Fixing HtmlHelper::css, and JavascriptHelper::link so that files containing the asset extension always get the extension added. Test cases added. Refs #139

This commit is contained in:
mark_story 2009-10-02 12:53:20 -04:00
parent f12cbdba38
commit c47e899ba1
4 changed files with 10 additions and 2 deletions

View file

@ -344,7 +344,7 @@ class HtmlHelper extends AppHelper {
} }
if (strpos($path, '?') === false) { if (strpos($path, '?') === false) {
if (strpos($path, '.css') === false) { if (substr($path, -4) !== '.css') {
$path .= '.css'; $path .= '.css';
} }
} }

View file

@ -249,7 +249,7 @@ class JavascriptHelper extends AppHelper {
$url = JS_URL . $url; $url = JS_URL . $url;
} }
if (strpos($url, '?') === false) { if (strpos($url, '?') === false) {
if (strpos($url, '.js') === false) { if (substr($url, -3) !== '.js') {
$url .= '.js'; $url .= '.js';
} }
} }

View file

@ -362,6 +362,10 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->css('screen.css'); $result = $this->Html->css('screen.css');
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Html->css('my.css.library');
$expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
$this->assertTags($result, $expected);
$result = $this->Html->css('screen.css?1234'); $result = $this->Html->css('screen.css?1234');
$expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/'; $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
$this->assertTags($result, $expected); $this->assertTags($result, $expected);

View file

@ -166,6 +166,10 @@ class JavascriptTest extends CakeTestCase {
$expected = '<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>'; $expected = '<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Javascript->link('some.json.libary');
$expected = '<script type="text/javascript" src="js/some.json.libary.js"></script>';
$this->assertEqual($result, $expected);
$result = $this->Javascript->link('jquery-1.1.2'); $result = $this->Javascript->link('jquery-1.1.2');
$expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>'; $expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);