Index: tests/Zend/Navigation/PageTest.php =================================================================== --- tests/Zend/Navigation/PageTest.php (revision 24362) +++ tests/Zend/Navigation/PageTest.php (working copy) @@ -161,6 +161,35 @@ } } } + + /** + * @group ZF-8922 + */ + public function testSetAndGetFragmentIdentifier() + { + $page = Zend_Navigation_Page::factory(array( + 'uri' => '#', + 'fragmentIdentifier' => 'foo', + )); + + $this->assertEquals('foo', $page->getFragmentIdentifier()); + + $page->setFragmentIdentifier('bar'); + $this->assertEquals('bar', $page->getFragmentIdentifier()); + + $invalids = array(42, (object) null); + foreach ($invalids as $invalid) { + try { + $page->setFragmentIdentifier($invalid); + $this->fail('An invalid value was set, but a ' . + 'Zend_Navigation_Exception was not thrown'); + } catch (Zend_Navigation_Exception $e) { + $this->assertContains( + 'Invalid argument: $fragmentIdentifier', $e->getMessage() + ); + } + } + } public function testSetAndGetId() { @@ -1093,32 +1122,33 @@ public function testToArrayMethod() { $options = array( - 'label' => 'foo', - 'uri' => '#', - 'id' => 'my-id', - 'class' => 'my-class', - 'title' => 'my-title', - 'target' => 'my-target', - 'rel' => array(), - 'rev' => array(), - 'order' => 100, - 'active' => true, - 'visible' => false, + 'label' => 'foo', + 'uri' => 'http://www.example.com/foo.html', + 'fragmentIdentifier' => 'bar', + 'id' => 'my-id', + 'class' => 'my-class', + 'title' => 'my-title', + 'target' => 'my-target', + 'rel' => array(), + 'rev' => array(), + 'order' => 100, + 'active' => true, + 'visible' => false, - 'resource' => 'joker', - 'privilege' => null, + 'resource' => 'joker', + 'privilege' => null, - 'foo' => 'bar', - 'meaning' => 42, + 'foo' => 'bar', + 'meaning' => 42, - 'pages' => array( + 'pages' => array( array( 'label' => 'foo.bar', - 'uri' => '#' + 'uri' => 'http://www.example.com/foo.html' ), array( 'label' => 'foo.baz', - 'uri' => '#' + 'uri' => 'http://www.example.com/foo.html' ) ) ); @@ -1139,15 +1169,16 @@ $this->assertEquals(2, count($toArray['pages'])); // tweak options to what we expect sub page 1 to be - $options['label'] = 'foo.bar'; - $options['order'] = null; - $options['id'] = null; - $options['class'] = null; - $options['title'] = null; - $options['target'] = null; - $options['resource'] = null; - $options['active'] = false; - $options['visible'] = true; + $options['label'] = 'foo.bar'; + $options['fragmentIdentifier'] = null; + $options['order'] = null; + $options['id'] = null; + $options['class'] = null; + $options['title'] = null; + $options['target'] = null; + $options['resource'] = null; + $options['active'] = false; + $options['visible'] = true; unset($options['foo']); unset($options['meaning']); Index: tests/Zend/Navigation/Page/UriTest.php =================================================================== --- tests/Zend/Navigation/Page/UriTest.php (revision 24362) +++ tests/Zend/Navigation/Page/UriTest.php (working copy) @@ -100,4 +100,22 @@ $this->assertEquals($uri, $page->getHref()); } + + /** + * @group ZF-8922 + */ + public function testGetHrefWithFragmentIdentifier() + { + $uri = 'http://www.example.com/foo.html'; + + $page = new Zend_Navigation_Page_Uri(); + $page->setUri($uri); + $page->setFragmentIdentifier('bar'); + + $this->assertEquals($uri . '#bar', $page->getHref()); + + $page->setUri('#'); + + $this->assertEquals('#bar', $page->getHref()); + } } Index: tests/Zend/Navigation/Page/MvcTest.php =================================================================== --- tests/Zend/Navigation/Page/MvcTest.php (revision 24362) +++ tests/Zend/Navigation/Page/MvcTest.php (working copy) @@ -102,7 +102,39 @@ $this->assertEquals('/lolcat/myaction/1337', $page->getHref()); } + + /** + * @group ZF-8922 + */ + public function testGetHrefWithFragmentIdentifier() + { + $page = new Zend_Navigation_Page_Mvc(array( + 'label' => 'foo', + 'fragmentIdentifier' => 'qux', + 'controller' => 'mycontroller', + 'action' => 'myaction', + 'route' => 'myroute', + 'params' => array( + 'page' => 1337 + ) + )); + + $this->_front->getRouter()->addRoute( + 'myroute', + new Zend_Controller_Router_Route( + 'lolcat/:action/:page', + array( + 'module' => 'default', + 'controller' => 'foobar', + 'action' => 'bazbat', + 'page' => 1 + ) + ) + ); + $this->assertEquals('/lolcat/myaction/1337#qux', $page->getHref()); + } + public function testIsActiveReturnsTrueOnIdenticalModuleControllerAction() { $page = new Zend_Navigation_Page_Mvc(array( @@ -349,20 +381,21 @@ public function testToArrayMethod() { $options = array( - 'label' => 'foo', - 'action' => 'index', - 'controller' => 'index', - 'module' => 'test', - 'id' => 'my-id', - 'class' => 'my-class', - 'title' => 'my-title', - 'target' => 'my-target', - 'order' => 100, - 'active' => true, - 'visible' => false, + 'label' => 'foo', + 'action' => 'index', + 'controller' => 'index', + 'module' => 'test', + 'fragmentIdentifier' => 'bar', + 'id' => 'my-id', + 'class' => 'my-class', + 'title' => 'my-title', + 'target' => 'my-target', + 'order' => 100, + 'active' => true, + 'visible' => false, - 'foo' => 'bar', - 'meaning' => 42 + 'foo' => 'bar', + 'meaning' => 42 ); $page = new Zend_Navigation_Page_Mvc($options);