Ver Fonte

ZF-11359 making Zend_Navigation_Page_Mvc::isActive route aware

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24118 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak há 14 anos atrás
pai
commit
e8eec5cccc

+ 10 - 3
library/Zend/Navigation/Page/Mvc.php

@@ -138,21 +138,28 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
 
             $myParams = $this->_params;
 
+            if ($this->_route) {
+                $route = $front->getRouter()->getRoute($this->_route);
+                if(method_exists($route, 'getDefaults')) {
+                    $myParams = array_merge($route->getDefaults(), $myParams);
+                }
+            }
+
             if (null !== $this->_module) {
                 $myParams['module'] = $this->_module;
-            } else {
+            } elseif(!array_key_exists('module', $myParams)) {
                 $myParams['module'] = $front->getDefaultModule();
             }
 
             if (null !== $this->_controller) {
                 $myParams['controller'] = $this->_controller;
-            } else {
+            } elseif(!array_key_exists('controller', $myParams)) {
                 $myParams['controller'] = $front->getDefaultControllerName();
             }
 
             if (null !== $this->_action) {
                 $myParams['action'] = $this->_action;
-            } else {
+            } elseif(!array_key_exists('action', $myParams)) {
                 $myParams['action'] = $front->getDefaultAction();
             }
 

+ 34 - 0
tests/Zend/Navigation/Page/MvcTest.php

@@ -200,6 +200,40 @@ class Zend_Navigation_Page_MvcTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(false, $page->isActive());
     }
 
+    public function testIsActiveIsRouteAware()
+    {
+        $page = new Zend_Navigation_Page_Mvc(array(
+            'label' => 'foo',
+            'action' => 'myaction',
+            'route' => 'myroute',
+            'params' => array(
+                'page' => 1337
+            )
+        ));
+
+        $this->_front->getRouter()->addRoute(
+            'myroute',
+            new Zend_Controller_Router_Route(
+                'lolcat/:action/:page',
+                array(
+                    'module'     => 'default',
+                    'controller' => 'foobar',
+                    'action'     => 'bazbat',
+                    'page'       => 1
+                )
+            )
+        );
+
+        $this->_front->getRequest()->setParams(array(
+            'module' => 'default',
+            'controller' => 'foobar',
+            'action' => 'myaction',
+            'page' => 1337
+        ));
+
+        $this->assertEquals(true, $page->isActive());
+    }
+
     public function testActionAndControllerAccessors()
     {
         $page = new Zend_Navigation_Page_Mvc(array(