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

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Helper/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function __invoke($name = null, array $params = array(), $options = array

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

if (isset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE])) {
unset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE]);
}

$params = array_merge($routeMatchParams, $params);
Expand Down
47 changes: 47 additions & 0 deletions test/Helper/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace ZendTest\View\Helper;

use Zend\View\Helper\Url as UrlHelper;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\SimpleRouteStack as Router;

Expand Down Expand Up @@ -132,4 +134,49 @@ public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatche
$url = $this->url->__invoke('replace', array('action' => 'bar'), true);
$this->assertEquals('/foo/bar', $url);
}

public function testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters()
{
$router = new \Zend\Mvc\Router\Http\TreeRouteStack;
$router->addRoute('default', array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/:controller/:action',
'defaults' => array(
ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\Mvc\Controller\TestAsset',
'controller' => 'SampleController',
'action' => 'Dash'
)
),
'child_routes' => array(
'wildcard' => array(
'type' => 'Zend\Mvc\Router\Http\Wildcard',
'options' => array(
'param_delimiter' => '=',
'key_value_delimiter' => '%'
)
)
)
));

$routeMatch = new RouteMatch(array(
ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\Mvc\Controller\TestAsset',
'controller' => 'Rainbow'
));
$routeMatch->setMatchedRouteName('default/wildcard');

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

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

$helper = new UrlHelper();
$helper->setRouter($router);
$helper->setRouteMatch($routeMatch);

$url = $helper->__invoke('default/wildcard', array('Twenty' => 'Cooler'), true);
$this->assertEquals('/Rainbow/Dash=Twenty%Cooler', $url);
}
}

0 comments on commit 243c253

Please sign in to comment.