Преглед изворни кода

Fix ZF-10458. Patch by Frank Brückner.

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@24987 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob пре 13 година
родитељ
комит
7761e93109

+ 8 - 0
library/Zend/View/Helper/Navigation.php

@@ -157,9 +157,17 @@ class Zend_View_Helper_Navigation
         }
 
         if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) {
+            // Add navigation helper path at the beginning
+            $paths = $this->view->getHelperPaths();
+            $this->view->setHelperPath(null);
+            
             $this->view->addHelperPath(
                     str_replace('_', '/', self::NS),
                     self::NS);
+            
+            foreach ($paths as $ns => $path) {
+                $this->view->addHelperPath($path, $ns);
+            }
         }
 
         if ($strict) {

+ 51 - 0
tests/Zend/View/Helper/Navigation/NavigationTest.php

@@ -379,6 +379,57 @@ class Zend_View_Helper_Navigation_NavigationTest
 
         $this->assertEquals($expected, $actual);
     }
+    
+    /**
+     * @group ZF-10458
+     */
+    public function testFindCustomHelper()
+    {
+        $this->_helper->view->addHelperPath(
+            $this->_files . '/helpers',
+            'My_View_Helper_Navigation'
+        );                
+        
+        $this->assertTrue(
+            $this->_helper->findHelper('menu') instanceof
+                My_View_Helper_Navigation_Menu
+        );
+    }
+    
+    /**
+     * @group ZF-10458
+     */
+    public function testAddHelperPath()
+    {
+        $this->_helper->view->addHelperPath(
+            $this->_files . '/helpers',
+            'My_View_Helper_Navigation'
+        );
+        
+        $expected = array(
+            'Zend_View_Helper_' => array(
+                'Zend/View/Helper/',
+            ),
+            'My_View_Helper_Navigation_' => array(
+                $this->_files . '/helpers/',
+            ),
+        );
+        
+        $this->assertSame($expected, $this->_helper->view->getHelperPaths());
+    }
+    
+    /**
+     * @group ZF-10458
+     */
+    public function testRenderCustomHelper()
+    {
+        $this->_helper->view->addHelperPath(
+            $this->_files . '/helpers',
+            'My_View_Helper_Navigation'
+        );
+        
+        $this->assertSame('<menu/>', (string) $this->_helper->menu());
+    }
 
     /**
      * @group ZF-6854

+ 39 - 0
tests/Zend/View/Helper/Navigation/_files/helpers/Menu.php

@@ -0,0 +1,39 @@
+<?php
+
+class My_View_Helper_Navigation_Menu
+    extends Zend_View_Helper_Navigation_HelperAbstract
+{
+    /**
+     * View helper entry point:
+     * Retrieves helper and optionally sets container to operate on
+     *
+     * @param  Zend_Navigation_Container $container  [optional] container to
+     *                                               operate on
+     * @return My_View_Helper_Navigation_Menu        fluent interface,
+     *                                               returns self
+     */
+    public function menu(Zend_Navigation_Container $container = null)
+    {
+        if (null !== $container) {
+            $this->setContainer($container);
+        }
+
+        return $this;
+    }
+    
+    /**
+     * Renders menu
+     *
+     * Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
+     *
+     * @param  Zend_Navigation_Container $container  [optional] container to
+     *                                               render. Default is to
+     *                                               render the container
+     *                                               registered in the helper.
+     * @return string                                helper output
+     */
+    public function render(Zend_Navigation_Container $container = null)
+    {
+        return '<menu/>';
+    }
+}