From 36aa61056daba14efbf0ab9e7480de07d8ef73ed Mon Sep 17 00:00:00 2001 From: nielsj Date: Mon, 23 Jun 2014 23:25:07 +0200 Subject: [PATCH 1/2] add failing test --- .../Service/NavigationTest.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/SpiffyNavigationTest/Service/NavigationTest.php b/test/SpiffyNavigationTest/Service/NavigationTest.php index db09409..31e20b8 100644 --- a/test/SpiffyNavigationTest/Service/NavigationTest.php +++ b/test/SpiffyNavigationTest/Service/NavigationTest.php @@ -139,6 +139,24 @@ public function testIsActive() $this->assertTrue($navigation->isActive($page)); } + public function testIsActiveWithDefaultParam() + { + $routeMatch = new RouteMatch(array()); + $routeMatch->setMatchedRouteName('test'); + $routeMatch->setParam('page', 1); + + $router = new TreeRouteStack(); + $router->addRoute('test', new Literal('/foo-bar', array('page' => 1))); + + $page = new Page(); + $page->setOptions(array('route' => 'test')); + + $navigation = new Navigation(); + $navigation->setRouteMatch($routeMatch); + + $this->assertTrue($navigation->isActive($page)); + } + public function testGetContainerWithInvalidNameThrowsException() { $this->setExpectedException('InvalidArgumentException'); @@ -320,4 +338,4 @@ public function testIsAllowedRbac() $page->setOptions(array('role' => 'foo', 'permission' => 'bar', 'assertion' => function() { return false; })); $this->assertFalse($navigation->isAllowed($page)); } -} \ No newline at end of file +} From d2238f7c514c761c4ddf1b74b31da68ad07178bf Mon Sep 17 00:00:00 2001 From: nielsj Date: Mon, 23 Jun 2014 23:41:21 +0200 Subject: [PATCH 2/2] use same check as `Zend/Navigation/Page/Mvc` --- src/SpiffyNavigation/Service/Navigation.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/SpiffyNavigation/Service/Navigation.php b/src/SpiffyNavigation/Service/Navigation.php index c6acecd..87e9357 100644 --- a/src/SpiffyNavigation/Service/Navigation.php +++ b/src/SpiffyNavigation/Service/Navigation.php @@ -143,7 +143,7 @@ public function isActive(Page $page) $page->getOption('query_params') ? $page->getOption('query_params') : array() ); - $active = $this->paramsAreEqual($pageParams, $reqParams); + $active = count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams); } elseif ($this->getIsActiveRecursion()) { $iterator = new RecursiveIteratorIterator($page, RecursiveIteratorIterator::CHILD_FIRST); @@ -340,20 +340,4 @@ public function getIsActiveRecursion() { return $this->isActiveRecursion; } - - /** - * @param $pageParams - * @param $requiredParams - * @return bool - */ - protected function paramsAreEqual($pageParams, $requiredParams) - { - foreach (array('__CONTROLLER__', '__NAMESPACE__', 'controller', 'action') as $unsetKey) { - if (isset($requiredParams[$unsetKey])) { - unset($requiredParams[$unsetKey]); - } - } - $diff = array_diff($requiredParams, $pageParams); - return empty($diff); - } -} \ No newline at end of file +}