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

Commit bdeec54

Browse files
committed
Merge branch 'hotfix/ZF-10465' of https://github.com/padraic/zf2 into hotfix/zf-10465
2 parents f10c688 + 9846aed commit bdeec54

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

src/Page/Mvc.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ class Mvc extends AbstractPage
8585
*/
8686
protected $_resetParams = true;
8787

88+
/**
89+
* Whether href should be encoded when assembling URL
90+
*
91+
* @see getHref()
92+
* @var bool
93+
*/
94+
protected $_encodeUrl = true;
95+
8896
/**
8997
* Cached href
9098
*
@@ -193,7 +201,8 @@ public function getHref()
193201

194202
$url = self::$_urlHelper->__invoke($params,
195203
$this->getRoute(),
196-
$this->getResetParams());
204+
$this->getResetParams(),
205+
$this->getEncodeUrl());
197206

198207
// Add the fragment identifier if it is set
199208
$fragmentIdentifier = $this->getFragmentIdentifier();
@@ -398,6 +407,35 @@ public function getResetParams()
398407
return $this->_resetParams;
399408
}
400409

410+
/**
411+
* Sets whether href should be encoded when assembling URL
412+
*
413+
* @see getHref()
414+
*
415+
* @param bool $resetParams whether href should be encoded when
416+
* assembling URL
417+
* @return \Zend\Navigation\Page\Mvc fluent interface, returns self
418+
*/
419+
public function setEncodeUrl($encodeUrl)
420+
{
421+
$this->_encodeUrl = (bool) $encodeUrl;
422+
$this->_hrefCache = null;
423+
424+
return $this;
425+
}
426+
427+
/**
428+
* Returns whether herf should be encoded when assembling URL
429+
*
430+
* @see getHref()
431+
*
432+
* @return bool whether herf should be encoded when assembling URL
433+
*/
434+
public function getEncodeUrl()
435+
{
436+
return $this->_encodeUrl;
437+
}
438+
401439
/**
402440
* Sets action helper for assembling URLs
403441
*
@@ -428,7 +466,8 @@ public function toArray()
428466
'module' => $this->getModule(),
429467
'params' => $this->getParams(),
430468
'route' => $this->getRoute(),
431-
'reset_params' => $this->getResetParams()
469+
'reset_params' => $this->getResetParams(),
470+
'encodeUrl' => $this->getEncodeUrl(),
432471
));
433472
}
434473
}

test/Page/MvcTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,54 @@ public function testSetAndGetParams()
349349
$this->assertEquals(array(), $page->getParams());
350350
}
351351

352+
/**
353+
* @group ZF-10465
354+
*/
355+
public function testSetAndGetEncodeUrl()
356+
{
357+
$page = new Page\Mvc(array(
358+
'label' => 'foo',
359+
'action' => 'index',
360+
'controller' => 'index',
361+
));
362+
363+
$page->setEncodeUrl(false);
364+
$this->assertEquals(false, $page->getEncodeUrl());
365+
}
366+
367+
/**
368+
* @group ZF-10465
369+
*/
370+
public function testEncodeUrlIsRouteAware()
371+
{
372+
$page = new Page\Mvc(array(
373+
'label' => 'foo',
374+
'route' => 'myroute',
375+
'encodeUrl' => false,
376+
'params' => array(
377+
'contentKey' => 'pagexy/subpage',
378+
)
379+
));
380+
381+
$this->_front->getRouter()->addRoute(
382+
'myroute',
383+
new \Zend\Controller\Router\Route\Regex(
384+
'(.+)\.html',
385+
array(
386+
'module' => 'default',
387+
'controller' => 'foobar',
388+
'action' => 'bazbat',
389+
),
390+
array(
391+
1 => 'contentKey'
392+
),
393+
'%s.html'
394+
)
395+
);
396+
397+
$this->assertEquals('/pagexy/subpage.html', $page->getHref());
398+
}
399+
352400
public function testToArrayMethod()
353401
{
354402
$options = array(
@@ -364,6 +412,7 @@ public function testToArrayMethod()
364412
'order' => 100,
365413
'active' => true,
366414
'visible' => false,
415+
'encodeUrl' => false,
367416

368417
'foo' => 'bar',
369418
'meaning' => 42

0 commit comments

Comments
 (0)