diff --git a/src/Container.php b/src/Container.php index a287159..c86df97 100644 --- a/src/Container.php +++ b/src/Container.php @@ -150,10 +150,12 @@ 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) { @@ -161,10 +163,16 @@ public function addPages($pages) $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) { diff --git a/src/Page/Uri.php b/src/Page/Uri.php index 7eb5d7c..1a35249 100644 --- a/src/Page/Uri.php +++ b/src/Page/Uri.php @@ -45,12 +45,13 @@ 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 */ @@ -58,10 +59,11 @@ 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; } @@ -72,12 +74,12 @@ 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 @@ -85,16 +87,16 @@ public function getUri() 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; } @@ -110,7 +112,8 @@ public function toArray() return array_merge( parent::toArray(), array( - 'uri' => $this->getUri() - )); + 'uri' => $this->getUri() + ) + ); } } diff --git a/test/ContainerTest.php b/test/ContainerTest.php index 9edde8e..0c1a398 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -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();