Przeglądaj źródła

ZF-11550: handle route defaults with null values

- Added test for this case
- Applied patch from Moshe van der Sterre

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24234 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 14 lat temu
rodzic
commit
1fb222a191

+ 6 - 0
library/Zend/Navigation/Page/Mvc.php

@@ -163,6 +163,12 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
                 $myParams['action'] = $front->getDefaultAction();
             }
 
+            foreach($myParams as $key => $value) {
+                if($value == null) {
+                    unset($myParams[$key]);
+                }
+            }
+
             if (count(array_intersect_assoc($reqParams, $myParams)) ==
                 count($myParams)) {
                 $this->_active = true;

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

@@ -397,4 +397,47 @@ class Zend_Navigation_Page_MvcTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals($expected, $actual);
     }
+
+    /**
+     * @group ZF-11550
+     */
+    public function testNullValuesInMatchedRouteWillStillReturnMatchedPage()
+    {
+        $page = new Zend_Navigation_Page_Mvc(array(
+            'route'      => 'default',
+            'module'     => 'default',
+            'controller' => 'index',
+            'action'     => 'index',
+            'label'      => 'Home',
+            'title'      => 'Home',
+        ));
+
+        $this->_front->getRouter()->addRoute(
+            'default',
+            new Zend_Controller_Router_Route(
+                ':locale/:module/:controller/:action/*',
+                array(
+                    'locale'     => null,
+                    'module'     => 'default',
+                    'controller' => 'index',
+                    'action'     => 'index',
+                ),
+                array(
+                    'locale'     => '.*',
+                    'module'     => '.*',
+                    'controller' => '.*',
+                    'action'     => '.*',
+                )
+            )
+        );
+
+        $this->_front->getRequest()->setParams(array(
+            'locale'     => 'en_US',
+            'module'     => 'default',
+            'controller' => 'index',
+            'action'     => 'index',
+        ));
+
+        $this->assertEquals(true, $page->isActive());
+    }
 }