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

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
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 test/Page/MvcTest.php
Original file line number Diff line number Diff line change
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 cd0ff39

Please sign in to comment.