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

Commit

Permalink
Merge branch 'hotfix/4282'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
33 changes: 32 additions & 1 deletion src/Page/Mvc.php
Expand Up @@ -75,6 +75,13 @@ class Mvc extends AbstractPage
*/
protected $routeMatch;

/**
* If true and set routeMatch than getHref will use routeMatch params
* to assemble uri
* @var bool
*/
protected $useRouteMatch = false;

/**
* Router for assembling URLs
*
Expand Down Expand Up @@ -190,7 +197,7 @@ public function getHref()
);
}

if ($this->getRouteMatch() !== null) {
if ($this->useRouteMatch()) {
$rmParams = $this->getRouteMatch()->getParams();

if (isset($rmParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
Expand Down Expand Up @@ -427,6 +434,30 @@ public function setRouteMatch(RouteMatch $matches)
return $this;
}

/**
* Get the useRouteMatch flag
*
* @return bool
*/
public function useRouteMatch()
{
return $this->useRouteMatch;
}

/**
* Set whether the page should use route match params for assembling link uri
*
* @see getHref()
* @param bool $useRouteMatch [optional]
* @return Mvc
*/
public function setUseRouteMatch($useRouteMatch = true)
{
$this->useRouteMatch = (bool) $useRouteMatch;
$this->hrefCache = null;
return $this;
}

/**
* Get the router.
*
Expand Down
34 changes: 30 additions & 4 deletions test/Page/MvcTest.php
Expand Up @@ -538,14 +538,34 @@ public function testNoExceptionForGetHrefIfDefaultRouterIsSet()
$page->setDefaultRouter(null);
}

public function testBoolSetAndGetUseRouteMatch()
{
$page = new Page\Mvc(array(
'useRouteMatch' => 2,
));
$this->assertSame(true, $page->useRouteMatch());

$page->setUseRouteMatch(null);
$this->assertSame(false, $page->useRouteMatch());

$page->setUseRouteMatch(false);
$this->assertSame(false, $page->useRouteMatch());

$page->setUseRouteMatch(true);
$this->assertSame(true, $page->useRouteMatch());

$page->setUseRouteMatch();
$this->assertSame(true, $page->useRouteMatch());
}

public function testMvcPageParamsInheritRouteMatchParams()
{
$page = new Page\Mvc(array(
'label' => 'lollerblades',
'route' => 'lollerblades'
'route' => 'lollerblades',
));

$route = new SegmentRoute('/lollerblades/view/:serialNumber');
$route = new SegmentRoute('/lollerblades/view[/:serialNumber]');

$router = new TreeRouteStack;
$router->addRoute('lollerblades', $route);
Expand All @@ -558,17 +578,20 @@ public function testMvcPageParamsInheritRouteMatchParams()
$page->setRouter($router);
$page->setRouteMatch($routeMatch);

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

$page->setUseRouteMatch(true);
$this->assertEquals('/lollerblades/view/23', $page->getHref());
}

public function testInheritedRouteMatchParamsWorkWithModuleRouteListener()
{
$page = new Page\Mvc(array(
'label' => 'mpinkstonwashere',
'route' => 'lmaoplane'
'route' => 'lmaoplane',
));

$route = new SegmentRoute('/lmaoplane/:controller');
$route = new SegmentRoute('/lmaoplane[/:controller]');

$router = new TreeRouteStack;
$router->addRoute('lmaoplane', $route);
Expand All @@ -589,6 +612,9 @@ public function testInheritedRouteMatchParamsWorkWithModuleRouteListener()
$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());

$this->assertEquals('/lmaoplane', $page->getHref());

$page->setUseRouteMatch(true);
$this->assertEquals('/lmaoplane/index', $page->getHref());
}
}

0 comments on commit 50b28a7

Please sign in to comment.