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

Commit

Permalink
Merge remote-tracking branch 'froschdesign/master'; commit 'ddbd7fb' …
Browse files Browse the repository at this point in the history
…into hotfix/zf-9815
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
20 changes: 14 additions & 6 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,29 @@ public function addPage($page)
/**
* Adds several pages at once
*
* @param array|\Zend\Config\Config $pages pages to add
* @return \Zend\Navigation\Container fluent interface, returns self
* @throws \Zend\Navigation\InvalidArgumentException if $pages is not array
* or \Zend\Config\Config
* @param array|\Zend\Config\Config|\Zend\Navigation\Container $pages pages
* to add
* @return \Zend\Navigation\Container fluent interface, returns self
* @throws \Zend\Navigation\InvalidArgumentException if $pages is not array,
* \Zend\Config\Config or
* \Zend\Navigation\Container
*/
public function addPages($pages)
{
if ($pages instanceof Config\Config) {
$pages = $pages->toArray();
}

if ($pages instanceof Container) {
$pages = iterator_to_array($pages);
}

if (!is_array($pages)) {
throw new Exception\InvalidArgumentException(
'Invalid argument: $pages must be an array or an ' .
'instance of Zend_Config');
'Invalid argument: $pages must be an array, an '
. 'instance of \Zend\Config\Config or an instance of '
. '\Zend\Navigation\Container'
);
}

foreach ($pages as $page) {
Expand Down
25 changes: 14 additions & 11 deletions src/Page/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,25 @@ class Uri extends AbstractPage
*
* @var string|null
*/
protected $_uri = null;
protected $uri = null;

/**
* Sets page URI
*
* @param string $uri page URI, must a string or null
*
* @return \Zend\Navigation\Page\Uri fluent interface, returns self
* @throws \Zend\Navigation\InvalidArgumentException if $uri is invalid
*/
public function setUri($uri)
{
if (null !== $uri && !is_string($uri)) {
throw new InvalidArgumentException(
'Invalid argument: $uri must be a string or null');
'Invalid argument: $uri must be a string or null'
);
}

$this->_uri = $uri;
$this->uri = $uri;
return $this;
}

Expand All @@ -72,29 +74,29 @@ public function setUri($uri)
*/
public function getUri()
{
return $this->_uri;
return $this->uri;
}

/**
* Returns href for this page
*
*
* Includes the fragment identifier if it is set.
*
* @return string
*/
public function getHref()
{
$uri = $this->getUri();
$fragment = $this->getFragment();

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

return $uri;
}

Expand All @@ -110,7 +112,8 @@ public function toArray()
return array_merge(
parent::toArray(),
array(
'uri' => $this->getUri()
));
'uri' => $this->getUri()
)
);
}
}
18 changes: 18 additions & 0 deletions test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,24 @@ public function testAddPagesShouldWorkWithMixedArray()
'Expected 3 pages, found ' . count($nav));
}

/**
* @group ZF-9815
*/
public function testAddPagesShouldWorkWithNavigationContainer()
{
$nav = new Navigation\Navigation();
$nav->addPages($this->_getFindByNavigation());

$this->assertEquals(
3, count($nav), 'Expected 3 pages, found ' . count($nav)
);

$this->assertEquals(
$nav->toArray(),
$this->_getFindByNavigation()->toArray()
);
}

public function testAddPagesShouldThrowExceptionWhenGivenString()
{
$nav = new Navigation\Navigation();
Expand Down

0 comments on commit f4e1da0

Please sign in to comment.