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

Commit

Permalink
Merge branch 'zend-nav-fragment-change' of https://github.com/padraic…
Browse files Browse the repository at this point in the history
…/zf2 into hotfix/pr-417
  • Loading branch information
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions src/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AbstractPage extends Container
*
* @var string|null
*/
protected $_fragmentIdentifier;
protected $_fragment;

/**
* Page id
Expand Down Expand Up @@ -336,18 +336,18 @@ public function getLabel()
/**
* Sets a fragment identifier
*
* @param string $fragmentIdentifier new fragment identifier
* @param string $fragment new fragment identifier
* @return Zend_Navigation_Page fluent interface, returns self
* @throws Zend_Navigation_Exception if empty/no string is given
*/
public function setFragmentIdentifier($fragmentIdentifier)
public function setFragment($fragment)
{
if (null !== $fragmentIdentifier && !is_string($fragmentIdentifier)) {
if (null !== $fragment && !is_string($fragment)) {
throw new Exception\InvalidArgumentException(
'Invalid argument: $fragmentIdentifier must be a string or null');
'Invalid argument: $fragment must be a string or null');
}

$this->_fragmentIdentifier = $fragmentIdentifier;
$this->_fragment = $fragment;
return $this;
}

Expand All @@ -356,9 +356,9 @@ public function setFragmentIdentifier($fragmentIdentifier)
*
* @return string|null fragment identifier
*/
public function getFragmentIdentifier()
public function getFragment()
{
return $this->_fragmentIdentifier;
return $this->_fragment;
}

/**
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public function toArray()
$this->getCustomProperties(),
array(
'label' => $this->getLabel(),
'fragmentIdentifier' => $this->getFragmentIdentifier(),
'fragment' => $this->getFragment(),
'id' => $this->getId(),
'class' => $this->getClass(),
'title' => $this->getTitle(),
Expand Down
6 changes: 3 additions & 3 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public function getHref()
$this->getEncodeUrl());

// Add the fragment identifier if it is set
$fragmentIdentifier = $this->getFragmentIdentifier();
if (null !== $fragmentIdentifier) {
$url .= '#' . $fragmentIdentifier;
$fragment = $this->getFragment();
if (null !== $fragment) {
$url .= '#' . $fragment;
}

return $this->_hrefCache = $url;
Expand Down
8 changes: 4 additions & 4 deletions src/Page/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public function getHref()
{
$uri = $this->getUri();

$fragmentIdentifier = $this->getFragmentIdentifier();
if (null !== $fragmentIdentifier) {
$fragment = $this->getFragment();
if (null !== $fragment) {
if ('#' == substr($uri, -1)) {
return $uri . $fragmentIdentifier;
return $uri . $fragment;
} else {
return $uri . '#' . $fragmentIdentifier;
return $uri . '#' . $fragment;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/Page/MvcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testGetHrefWithFragmentIdentifier()
{
$page = new Page\Mvc(array(
'label' => 'foo',
'fragmentIdentifier' => 'qux',
'fragment' => 'qux',
'controller' => 'mycontroller',
'action' => 'myaction',
'route' => 'myroute',
Expand Down Expand Up @@ -404,7 +404,7 @@ public function testToArrayMethod()
'action' => 'index',
'controller' => 'index',
'module' => 'test',
'fragmentIdentifier' => 'bar',
'fragment' => 'bar',
'id' => 'my-id',
'class' => 'my-class',
'title' => 'my-title',
Expand Down
2 changes: 1 addition & 1 deletion test/Page/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testGetHrefWithFragmentIdentifier()

$page = new Page\Uri();
$page->setUri($uri);
$page->setFragmentIdentifier('bar');
$page->setFragment('bar');

$this->assertEquals($uri . '#bar', $page->getHref());

Expand Down
16 changes: 8 additions & 8 deletions test/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,23 @@ public function testSetAndGetFragmentIdentifier()
{
$page = AbstractPage::factory(array(
'uri' => '#',
'fragmentIdentifier' => 'foo',
'fragment' => 'foo',
));

$this->assertEquals('foo', $page->getFragmentIdentifier());
$this->assertEquals('foo', $page->getFragment());

$page->setFragmentIdentifier('bar');
$this->assertEquals('bar', $page->getFragmentIdentifier());
$page->setFragment('bar');
$this->assertEquals('bar', $page->getFragment());

$invalids = array(42, (object) null);
foreach ($invalids as $invalid) {
try {
$page->setFragmentIdentifier($invalid);
$page->setFragment($invalid);
$this->fail('An invalid value was set, but a ' .
'Zend_Navigation_Exception was not thrown');
} catch (Navigation\Exception\InvalidArgumentException $e) {
$this->assertContains(
'Invalid argument: $fragmentIdentifier', $e->getMessage()
'Invalid argument: $fragment', $e->getMessage()
);
}
}
Expand Down Expand Up @@ -1137,7 +1137,7 @@ public function testToArrayMethod()
$options = array(
'label' => 'foo',
'uri' => 'http://www.example.com/foo.html',
'fragmentIdentifier' => 'bar',
'fragment' => 'bar',
'id' => 'my-id',
'class' => 'my-class',
'title' => 'my-title',
Expand Down Expand Up @@ -1183,7 +1183,7 @@ public function testToArrayMethod()

// tweak options to what we expect sub page 1 to be
$options['label'] = 'foo.bar';
$options['fragmentIdentifier'] = null;
$options['fragment'] = null;
$options['order'] = null;
$options['id'] = null;
$options['class'] = null;
Expand Down

0 comments on commit 9808633

Please sign in to comment.