Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/navigation-mvc-isactive' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Sep 13, 2012
2 parents d266401 + 121d689 commit 06bdec8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/Zend/Navigation/Page/Mvc.php
Expand Up @@ -13,6 +13,7 @@
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\RouteStackInterface;
use Zend\Navigation\Exception;
use Zend\Mvc\ModuleRouteListener;
use Zend\View\Helper\Url as UrlHelper;

/**
Expand Down Expand Up @@ -110,6 +111,10 @@ public function isActive($recursive = false)
if ($this->routeMatch instanceof RouteMatch) {
$reqParams = $this->routeMatch->getParams();

if (isset($reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
$reqParams['controller'] = $reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
}

$myParams = $this->params;
if (null !== $this->controller) {
$myParams['controller'] = $this->controller;
Expand Down
34 changes: 34 additions & 0 deletions tests/ZendTest/Navigation/Page/MvcTest.php
Expand Up @@ -15,6 +15,8 @@
use Zend\Mvc\Router\Http\Regex as RegexRoute;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Navigation\Page;
use Zend\Navigation;
use ZendTest\Navigation\TestAsset;
Expand Down Expand Up @@ -122,6 +124,38 @@ public function testIsActiveReturnsTrueWhenMatchingRoute()
$this->assertEquals(true, $page->isActive());
}

public function testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener()
{
$page = new Page\Mvc(array(
'label' => 'mpinkstonwashere',
'route' => 'roflcopter',
'controller' => 'index'
));

$route = new LiteralRoute('/roflcopter');

$router = new TreeRouteStack;
$router->addRoute('roflcopter', $route);

$routeMatch = new RouteMatch(array(
ModuleRouteListener::MODULE_NAMESPACE => 'Application\Controller',
'controller' => 'index'
));
$routeMatch->setMatchedRouteName('roflcopter');

$event = new MvcEvent();
$event->setRouter($router)
->setRouteMatch($routeMatch);

$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);

$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());

$this->assertEquals(true, $page->isActive());
}

public function testIsActiveReturnsFalseWhenMatchingRouteButNonMatchingParams()
{
$page = new Page\Mvc(array(
Expand Down

0 comments on commit 06bdec8

Please sign in to comment.