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/ZF-10465' of https://github.com/padraic/zf2 into…
Browse files Browse the repository at this point in the history
… hotfix/zf-10465
  • Loading branch information
weierophinney committed Sep 9, 2011
2 parents f10c688 + 9846aed commit bdeec54
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Mvc extends AbstractPage
*/
protected $_resetParams = true;

/**
* Whether href should be encoded when assembling URL
*
* @see getHref()
* @var bool
*/
protected $_encodeUrl = true;

/**
* Cached href
*
Expand Down Expand Up @@ -193,7 +201,8 @@ public function getHref()

$url = self::$_urlHelper->__invoke($params,
$this->getRoute(),
$this->getResetParams());
$this->getResetParams(),
$this->getEncodeUrl());

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

/**
* Sets whether href should be encoded when assembling URL
*
* @see getHref()
*
* @param bool $resetParams whether href should be encoded when
* assembling URL
* @return \Zend\Navigation\Page\Mvc fluent interface, returns self
*/
public function setEncodeUrl($encodeUrl)
{
$this->_encodeUrl = (bool) $encodeUrl;
$this->_hrefCache = null;

return $this;
}

/**
* Returns whether herf should be encoded when assembling URL
*
* @see getHref()
*
* @return bool whether herf should be encoded when assembling URL
*/
public function getEncodeUrl()
{
return $this->_encodeUrl;
}

/**
* Sets action helper for assembling URLs
*
Expand Down Expand Up @@ -428,7 +466,8 @@ public function toArray()
'module' => $this->getModule(),
'params' => $this->getParams(),
'route' => $this->getRoute(),
'reset_params' => $this->getResetParams()
'reset_params' => $this->getResetParams(),
'encodeUrl' => $this->getEncodeUrl(),
));
}
}
49 changes: 49 additions & 0 deletions test/Page/MvcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,54 @@ public function testSetAndGetParams()
$this->assertEquals(array(), $page->getParams());
}

/**
* @group ZF-10465
*/
public function testSetAndGetEncodeUrl()
{
$page = new Page\Mvc(array(
'label' => 'foo',
'action' => 'index',
'controller' => 'index',
));

$page->setEncodeUrl(false);
$this->assertEquals(false, $page->getEncodeUrl());
}

/**
* @group ZF-10465
*/
public function testEncodeUrlIsRouteAware()
{
$page = new Page\Mvc(array(
'label' => 'foo',
'route' => 'myroute',
'encodeUrl' => false,
'params' => array(
'contentKey' => 'pagexy/subpage',
)
));

$this->_front->getRouter()->addRoute(
'myroute',
new \Zend\Controller\Router\Route\Regex(
'(.+)\.html',
array(
'module' => 'default',
'controller' => 'foobar',
'action' => 'bazbat',
),
array(
1 => 'contentKey'
),
'%s.html'
)
);

$this->assertEquals('/pagexy/subpage.html', $page->getHref());
}

public function testToArrayMethod()
{
$options = array(
Expand All @@ -364,6 +412,7 @@ public function testToArrayMethod()
'order' => 100,
'active' => true,
'visible' => false,
'encodeUrl' => false,

'foo' => 'bar',
'meaning' => 42
Expand Down

0 comments on commit bdeec54

Please sign in to comment.