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

Commit

Permalink
Merge branch 'feature/5138' into develop
Browse files Browse the repository at this point in the history
Close #5138
  • Loading branch information
weierophinney committed Oct 23, 2013
2 parents 667cbb1 + 14127c8 commit 65407bd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
34 changes: 31 additions & 3 deletions library/Zend/Navigation/Page/Mvc.php
Expand Up @@ -97,7 +97,14 @@ class Mvc extends AbstractPage
*
* @var RouteStackInterface
*/
protected static $defaultRouter= null;
protected static $defaultRouter = null;

/**
* Default route name
*
* @var string
*/
protected static $defaultRoute = null;

// Accessors:

Expand Down Expand Up @@ -228,8 +235,8 @@ public function getHref()
}

switch (true) {
case ($this->getRoute() !== null):
$name = $this->getRoute();
case ($this->getRoute() !== null || static::getDefaultRoute() !== null):
$name = ($this->getRoute() !== null) ? $this->getRoute() : static::getDefaultRoute();
break;
case ($this->getRouteMatch() !== null):
$name = $this->getRouteMatch()->getMatchedRouteName();
Expand Down Expand Up @@ -502,6 +509,27 @@ public static function getDefaultRouter()
return static::$defaultRouter;
}

/**
* Set default route name
*
* @param string $route
* @return void
*/
public static function setDefaultRoute($route)
{
static::$defaultRoute = $route;
}

/**
* Get default route name
*
* @return string
*/
public static function getDefaultRoute()
{
return static::$defaultRoute;
}

// Public methods:

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/ZendTest/Navigation/Page/MvcTest.php
Expand Up @@ -49,6 +49,21 @@ protected function tearDown()
{
}

public function testHrefGeneratedByRouterWithDefaultRoute()
{
$page = new Page\Mvc(array(
'label' => 'foo',
'action' => 'index',
'controller' => 'index'
));
Page\Mvc::setDefaultRoute('default');
$page->setRouter($this->router);
$page->setAction('view');
$page->setController('news');

$this->assertEquals('/news/view', $page->getHref());
}

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

0 comments on commit 65407bd

Please sign in to comment.