Sfoglia il codice sorgente

ZF-11811: Prevent duplicate attributes on <link> tag when using Zend_View_Helper_HeadLink

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24814 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 anni fa
parent
commit
0a9d35a45e

+ 20 - 2
library/Zend/View/Helper/HeadLink.php

@@ -379,7 +379,7 @@ class Zend_View_Helper_HeadLink extends Zend_View_Helper_Placeholder_Container_S
         }
 
         $attributes = compact('rel', 'type', 'href', 'media', 'conditionalStylesheet', 'extras');
-        return $this->createData($attributes);
+        return $this->createData($this->_applyExtras($attributes));
     }
 
     /**
@@ -432,6 +432,24 @@ class Zend_View_Helper_HeadLink extends Zend_View_Helper_Placeholder_Container_S
         $title = (string) $title;
 
         $attributes = compact('rel', 'href', 'type', 'title', 'extras');
-        return $this->createData($attributes);
+        return $this->createData($this->_applyExtras($attributes));
+    }
+
+    /**
+     * Apply any overrides specified in the 'extras' array
+     * @param array $attributes
+     * @return array
+     */
+    protected function _applyExtras($attributes)
+    {
+        if (isset($attributes['extras'])) {
+            foreach ($attributes['extras'] as $eKey=>$eVal) {
+                if (isset($attributes[$eKey])) {
+                    $attributes[$eKey] = $eVal;
+                    unset($attributes['extras'][$eKey]);
+                }
+            }
+        }
+        return $attributes;
     }
 }

+ 10 - 0
tests/Zend/View/Helper/HeadLinkTest.php

@@ -467,6 +467,16 @@ class Zend_View_Helper_HeadLinkTest extends PHPUnit_Framework_TestCase
         $this->helper->appendStylesheet(array('href' => '/bar/baz', 'id' => 'foo'));
         $this->assertContains('id="foo"', $this->helper->toString());
     }
+
+    /**
+     * @group ZF-11811
+     */
+    public function testHeadLinkAllowsOverrideOfRelAttribute()
+    {
+        $this->helper->appendStylesheet('/css/auth.less', 'all', null, array('rel' => 'stylesheet/less'));
+        $this->assertEquals(1, substr_count($this->helper->toString(), "rel=\""));
+        $this->assertContains('rel="stylesheet/less"', $this->helper->toString());
+    }
 }
 
 // Call Zend_View_Helper_HeadLinkTest::main() if this source file is executed directly.