Browse Source

Fixes a problem where either the script or css file is not included if they use the same name (e.g. default.css and default.js)

Walther Lalk 11 years ago
parent
commit
2e3e33aa7b
2 changed files with 27 additions and 5 deletions
  1. 8 5
      src/View/Helper/HtmlHelper.php
  2. 19 0
      tests/TestCase/View/Helper/HtmlHelperTest.php

+ 8 - 5
src/View/Helper/HtmlHelper.php

@@ -91,7 +91,10 @@ class HtmlHelper extends Helper {
  *
  * @var array
  */
-	protected $_includedAssets = array();
+	protected $_includedAssets = array(
+		'css' => array(),
+		'script' => array()
+	);
 
 /**
  * Options for the currently opened script block buffer if any.
@@ -405,11 +408,11 @@ class HtmlHelper extends Helper {
 			return;
 		}
 
-		if ($options['once'] && isset($this->_includedAssets[$path])) {
+		if ($options['once'] && isset($this->_includedAssets['css'][$path])) {
 			return '';
 		}
 		unset($options['once']);
-		$this->_includedAssets[$path] = true;
+		$this->_includedAssets['css'][$path] = true;
 
 		if (strpos($path, '//') !== false) {
 			$url = $path;
@@ -489,10 +492,10 @@ class HtmlHelper extends Helper {
 			}
 			return null;
 		}
-		if ($options['once'] && isset($this->_includedAssets[$url])) {
+		if ($options['once'] && isset($this->_includedAssets['script'][$url])) {
 			return null;
 		}
-		$this->_includedAssets[$url] = true;
+		$this->_includedAssets['script'][$url] = true;
 
 		if (strpos($url, '//') === false) {
 			$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));

+ 19 - 0
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -1979,4 +1979,23 @@ class HtmlHelperTest extends TestCase {
 		);
 	}
 
+/**
+ * Tests that CSS and Javascript files of the same name don't conflict with the 'once' test
+ *
+ * @return void
+ */
+	public function testCssAndScriptWithSameName() {
+		$result = $this->Html->css('foo');
+		$expected = array(
+			'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*css\/foo\.css/')
+		);
+		$this->assertTags($result, $expected);
+
+		$result = $this->Html->script('foo');
+		$expected = array(
+			'script' => array('src' => 'js/foo.js')
+		);
+		$this->assertTags($result, $expected);
+	}
+
 }