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/4634'
Browse files Browse the repository at this point in the history
Close #4634
  • Loading branch information
weierophinney committed Jun 12, 2013
2 parents 62b22f5 + d243b77 commit 70f5d71
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Navigation/Page/Mvc.php
Expand Up @@ -132,15 +132,15 @@ public function isActive($recursive = false)
}

if (null !== $this->getRoute()) {
$this->active = false;
if (
$this->routeMatch->getMatchedRouteName() === $this->getRoute()
&& (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams))
) {
$this->active = true;
return $this->active;
} else {
return parent::isActive($recursive);
}

return $this->active;
}
}

Expand Down
69 changes: 69 additions & 0 deletions tests/ZendTest/Navigation/Page/MvcTest.php
Expand Up @@ -667,4 +667,73 @@ public function testMistakeDetectIsActiveOnIndexController()

$this->assertFalse($page->isActive());
}

public function testRecursiveDetectIsActiveWhenRouteNameIsKnown()
{
$parentPage = new Page\Mvc(
array(
'label' => 'some Label',
'route' => 'parentPageRoute',
)
);
$childPage = new Page\Mvc(
array(
'label' => 'child',
'route' => 'childPageRoute',
)
);
$parentPage->addPage($childPage);

$router = new TreeRouteStack;
$router->addRoutes(
array(
'parentPageRoute' => array(
'type' => 'literal',
'options' => array(
'route' => '/foo',
'defaults' => array(
'controller' => 'fooController',
'action' => 'fooAction'
)
)
),
'childPageRoute' => array(
'type' => 'literal',
'options' => array(
'route' => '/bar',
'defaults' => array(
'controller' => 'barController',
'action' => 'barAction'
)
)
)
)
);

$routeMatch = new RouteMatch(
array(
ModuleRouteListener::MODULE_NAMESPACE => 'Application\Controller',
'controller' => 'barController',
'action' => 'barAction'
)
);
$routeMatch->setMatchedRouteName('childPageRoute');

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

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

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

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

$this->assertTrue($childPage->isActive(true));
$this->assertTrue($parentPage->isActive(true));

}
}

0 comments on commit 70f5d71

Please sign in to comment.