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

Commit

Permalink
Closes #3794
Browse files Browse the repository at this point in the history
Merge branch 'DASPRiD-feature/query-fragment-assembling'
  • Loading branch information
Ralph Schindler committed Feb 19, 2013
2 parents 4aab037 + 5643524 commit 3cee776
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/Zend/Mvc/Router/Http/Query.php
Expand Up @@ -19,6 +19,7 @@
* Query route.
*
* @see http://guides.rubyonrails.org/routing.html
* @deprecated
*/
class Query implements RouteInterface
{
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Mvc/Router/Http/TreeRouteStack.php
Expand Up @@ -217,6 +217,14 @@ public function assemble(array $params = array(), array $options = array())

$path = $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);

if (isset($options['query'])) {
$uri->setQuery($options['query']);
}

if (isset($options['fragment'])) {
$uri->setFragment($options['fragment']);
}

if ((isset($options['force_canonical']) && $options['force_canonical']) || $uri->getHost() !== null) {
if ($uri->getScheme() === null) {
if ($this->requestUri === null) {
Expand Down
32 changes: 32 additions & 0 deletions tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php
Expand Up @@ -212,6 +212,38 @@ public function testAssembleWithQueryRoute()
$this->assertEquals('/?bar=baz', $stack->assemble(array('bar' => 'baz'), array('name' => 'index/query')));
}

public function testAssembleWithQueryParams()
{
$stack = new TreeRouteStack();
$stack->addRoute(
'index',
array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
)
);

$this->assertEquals('/?foo=bar', $stack->assemble(array(), array('name' => 'index', 'query' => array('foo' => 'bar'))));
}

public function testAssembleWithFragment()
{
$stack = new TreeRouteStack();
$stack->addRoute(
'index',
array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
)
);

$this->assertEquals('/#foobar', $stack->assemble(array(), array('name' => 'index', 'fragment' => 'foobar')));
}

public function testAssembleWithoutNameOption()
{
$this->setExpectedException('Zend\Mvc\Router\Exception\InvalidArgumentException', 'Missing "name" option');
Expand Down

0 comments on commit 3cee776

Please sign in to comment.