Kaynağa Gözat

ZF-12048: Fixed inconsistent behavior of HeadScript view helper setFile method

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24878 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 yıl önce
ebeveyn
işleme
ca6422d28c

+ 1 - 1
library/Zend/View/Helper/HeadScript.php

@@ -245,7 +245,7 @@ class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container
                     break;
                 case 'file':
                 default:
-                    if (!$this->_isDuplicate($content)) {
+                    if (!$this->_isDuplicate($content) || $action=='set') {
                         $attrs['src'] = $content;
                         $item = $this->createData($type, $attrs);
                         if ('offsetSet' == $action) {

+ 14 - 0
tests/Zend/View/Helper/HeadScriptTest.php

@@ -451,6 +451,20 @@ document.write(bar.strlen());');
 
         $this->assertEquals($expected, $test);
     }
+    
+    /**
+     * @group ZF-12048
+     */
+    public function testSetFileStillOverwritesExistingFilesWhenItsADuplicate()
+    {
+        $this->helper->appendFile('foo.js');
+        $this->helper->appendFile('bar.js');
+        $this->helper->setFile('foo.js');
+        
+        $expected = '<script type="text/javascript" src="foo.js"></script>';
+        $test = $this->helper->toString();
+        $this->assertEquals($expected, $test);
+    }
 }
 
 // Call Zend_View_Helper_HeadScriptTest::main() if this source file is executed directly.