diff --git a/test/Page/PageFactoryTest.php b/test/Page/PageFactoryTest.php index fd507e1..ded1e58 100644 --- a/test/Page/PageFactoryTest.php +++ b/test/Page/PageFactoryTest.php @@ -158,4 +158,12 @@ public function testShouldFailIfUnableToDetermineType() $this->fail('An exception has not been thrown for invalid page type'); } + + /** + * @expectedException \Zend\Navigation\Exception\InvalidArgumentException + */ + public function testShouldThrowExceptionOnInvalidMethodArgument() + { + AbstractPage::factory(''); + } } diff --git a/test/Page/PageTest.php b/test/Page/PageTest.php index 1a390d5..adcdb89 100644 --- a/test/Page/PageTest.php +++ b/test/Page/PageTest.php @@ -9,11 +9,12 @@ namespace ZendTest\Navigation\Page; +use Zend\Config; +use Zend\Navigation; +use Zend\Navigation\Exception; use Zend\Navigation\Page\AbstractPage; use Zend\Navigation\Page\Mvc; use Zend\Navigation\Page\Uri; -use Zend\Navigation; -use Zend\Config; /** * Tests the class Zend_Navigation_Page @@ -104,6 +105,46 @@ public function testSetShouldNotMapToSetConfigToPreventRecursion() $this->assertEquals($options, $page->get('config')); } + public function testSetShouldThrowExceptionIfPropertyIsNotString() + { + $page = AbstractPage::factory([ + 'type' => 'uri', + ]); + + $this->setExpectedException(Exception\InvalidArgumentException::class); + $page->set([], true); + } + + public function testSetShouldThrowExceptionIfPropertyIsEmpty() + { + $page = AbstractPage::factory([ + 'type' => 'uri', + ]); + + $this->setExpectedException(Exception\InvalidArgumentException::class); + $page->set('', true); + } + + public function testGetShouldThrowExceptionIfPropertyIsNotString() + { + $page = AbstractPage::factory([ + 'type' => 'uri', + ]); + + $this->setExpectedException(Exception\InvalidArgumentException::class); + $page->get([]); + } + + public function testGetShouldThrowExceptionIfPropertyIsEmpty() + { + $page = AbstractPage::factory([ + 'type' => 'uri', + ]); + + $this->setExpectedException(Exception\InvalidArgumentException::class); + $page->get(''); + } + public function testSetAndGetLabel() { $page = AbstractPage::factory([ @@ -325,6 +366,17 @@ public function testConstructingWithRelationsInConfig() $this->assertEquals($expected, $actual); } + public function testConstructingWithTraversableOptions() + { + $options = ['label' => 'bar']; + + $page = new Uri(new Config\Config($options)); + + $actual = ['label' => $page->getLabel()]; + + $this->assertEquals($options, $actual); + } + public function testGettingSpecificRelations() { $page = AbstractPage::factory([ @@ -509,6 +561,12 @@ public function testIsActiveOnNewlyConstructedPageShouldReturnFalse() $this->assertFalse($page->isActive()); } + public function testIsActiveRecursiveOnNewlyConstructedPageShouldReturnFalse() + { + $page = new Uri(); + $this->assertFalse($page->isActive(true)); + } + public function testGetActiveShouldReturnTrueIfPageIsActive() { $page = new Uri(['active' => true]); @@ -1168,4 +1226,16 @@ public function testSetObjectPermission() $this->assertInstanceOf('stdClass', $page->getPermission()); $this->assertEquals('my_permission', $page->getPermission()->name); } + + public function testSetParentShouldThrowExceptionIfPageItselfIsParent() + { + $page = AbstractPage::factory( + [ + 'type' => 'uri', + ] + ); + + $this->setExpectedException(Exception\InvalidArgumentException::class); + $page->setParent($page); + } }