Skip to content

Commit

Permalink
Merge d2238f7 into 6599c51
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnuf committed Jun 23, 2014
2 parents 6599c51 + d2238f7 commit 5bba1bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
20 changes: 2 additions & 18 deletions src/SpiffyNavigation/Service/Navigation.php
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
}
20 changes: 19 additions & 1 deletion test/SpiffyNavigationTest/Service/NavigationTest.php
Expand Up @@ -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');
Expand Down Expand Up @@ -320,4 +338,4 @@ public function testIsAllowedRbac()
$page->setOptions(array('role' => 'foo', 'permission' => 'bar', 'assertion' => function() { return false; }));
$this->assertFalse($navigation->isAllowed($page));
}
}
}

0 comments on commit 5bba1bc

Please sign in to comment.