| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Navigation
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- require_once 'Zend/Navigation.php';
- require_once 'Zend/Config.php';
- /**
- * Tests the class Zend_Navigation_Container
- *
- * @category Zend
- * @package Zend_Navigation
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Navigation
- */
- class Zend_Navigation_ContainerTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Prepares the environment before running a test.
- *
- */
- protected function setUp()
- {
- }
- /**
- * Tear down the environment after running a test
- *
- */
- protected function tearDown()
- {
- }
- public function testConstructWithArray()
- {
- $argument = array(
- array(
- 'label' => 'Page 1',
- 'uri' => 'page1.html'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => 'page2.html'
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => 'page3.html'
- )
- );
- $container = new Zend_Navigation($argument);
- $this->assertEquals(3, $container->count());
- }
- public function testConstructWithConfig()
- {
- $argument = new Zend_Config(array(
- array(
- 'label' => 'Page 1',
- 'uri' => 'page1.html'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => 'page2.html'
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => 'page3.html'
- )
- ));
- $container = new Zend_Navigation($argument);
- $this->assertEquals(3, $container->count());
- }
- public function testConstructorShouldThrowExceptionOnInvalidArgument()
- {
- try {
- $nav = new Zend_Navigation('ok');
- $this->fail('An invalid argument was given to the constructor, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $pages', $e->getMessage());
- }
- try {
- $nav = new Zend_Navigation(1337);
- $this->fail('An invalid argument was given to the constructor, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $pages', $e->getMessage());
- }
- try {
- $nav = new Zend_Navigation(new stdClass());
- $this->fail('An invalid argument was given to the constructor, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $pages', $e->getMessage());
- }
- }
- public function testIterationShouldBeOrderAware()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#',
- 'order' => -1
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 4',
- 'uri' => '#',
- 'order' => 100
- ),
- array(
- 'label' => 'Page 5',
- 'uri' => '#'
- )
- ));
- $expected = array('Page 2', 'Page 1', 'Page 3', 'Page 5', 'Page 4');
- $actual = array();
- foreach ($nav as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testRecursiveIteration()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#',
- 'pages' => array(
- array(
- 'label' => 'Page 1.1',
- 'uri' => '#',
- 'pages' => array(
- array(
- 'label' => 'Page 1.1.1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 1.1.2',
- 'uri' => '#'
- )
- )
- ),
- array(
- 'label' => 'Page 1.2',
- 'uri' => '#'
- )
- )
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#',
- 'pages' => array(
- array(
- 'label' => 'Page 2.1',
- 'uri' => '#'
- )
- )
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => '#'
- )
- ));
- $actual = array();
- $expected = array(
- 'Page 1',
- 'Page 1.1',
- 'Page 1.1.1',
- 'Page 1.1.2',
- 'Page 1.2',
- 'Page 2',
- 'Page 2.1',
- 'Page 3'
- );
- $iterator = new RecursiveIteratorIterator($nav,
- RecursiveIteratorIterator::SELF_FIRST);
- foreach ($iterator as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testSettingPageOrderShouldUpdateContainerOrder()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#'
- )
- ));
- $page3 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ));
- $nav->addPage($page3);
- $expected = array(
- 'before' => array('Page 1', 'Page 2', 'Page 3'),
- 'after' => array('Page 3', 'Page 1', 'Page 2')
- );
- $actual = array(
- 'before' => array(),
- 'after' => array()
- );
- foreach ($nav as $page) {
- $actual['before'][] = $page->getLabel();
- }
- $page3->setOrder(-1);
- foreach ($nav as $page) {
- $actual['after'][] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testAddPageShouldWorkWithArray()
- {
- $pageOptions = array(
- 'label' => 'From array',
- 'uri' => '#array'
- );
- $nav = new Zend_Navigation();
- $nav->addPage($pageOptions);
- $this->assertEquals(1, count($nav));
- }
- public function testAddPageShouldWorkWithConfig()
- {
- $pageOptions = array(
- 'label' => 'From config',
- 'uri' => '#config'
- );
- $pageOptions = new Zend_Config($pageOptions);
- $nav = new Zend_Navigation();
- $nav->addPage($pageOptions);
- $this->assertEquals(1, count($nav));
- }
- public function testAddPageShouldWorkWithPageInstance()
- {
- $pageOptions = array(
- 'label' => 'From array 1',
- 'uri' => '#array'
- );
- $nav = new Zend_Navigation(array($pageOptions));
- $page = Zend_Navigation_Page::factory($pageOptions);
- $nav->addPage($page);
- $this->assertEquals(2, count($nav));
- }
- public function testAddPagesShouldWorkWithArray()
- {
- $nav = new Zend_Navigation();
- $nav->addPages(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'action' => 'index',
- 'controller' => 'index'
- )
- ));
- $this->assertEquals(2, count($nav),
- 'Expected 2 pages, found ' . count($nav));
- }
- public function testAddPagesShouldWorkWithConfig()
- {
- $nav = new Zend_Navigation();
- $nav->addPages(new Zend_Config(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'action' => 'index',
- 'controller' => 'index'
- )
- )));
- $this->assertEquals(2, count($nav),
- 'Expected 2 pages, found ' . count($nav));
- }
- public function testAddPagesShouldWorkWithMixedArray()
- {
- $nav = new Zend_Navigation();
- $nav->addPages(new Zend_Config(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- new Zend_Config(array(
- 'label' => 'Page 2',
- 'action' => 'index',
- 'controller' => 'index'
- )),
- Zend_Navigation_Page::factory(array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ))
- )));
- $this->assertEquals(3, count($nav),
- 'Expected 3 pages, found ' . count($nav));
- }
- public function testAddPagesShouldThrowExceptionWhenGivenString()
- {
- $nav = new Zend_Navigation();
- try {
- $nav->addPages('this is a string');
- $this->fail('An invalid argument was given to addPages(), ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $pages must be', $e->getMessage());
- }
- }
- public function testAddPagesShouldThrowExceptionWhenGivenAnArbitraryObject()
- {
- $nav = new Zend_Navigation();
- try {
- $nav->addPages($pages = new stdClass());
- $this->fail('An invalid argument was given to addPages(), ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $pages must be', $e->getMessage());
- }
- }
- public function testRemovingAllPages()
- {
- $nav = new Zend_Navigation();
- $nav->addPages(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#'
- )
- ));
- $nav->removePages();
- $this->assertEquals(0, count($nav),
- 'Expected 0 pages, found ' . count($nav));
- }
- public function testSettingPages()
- {
- $nav = new Zend_Navigation();
- $nav->addPages(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#'
- )
- ));
- $nav->setPages(array(
- array(
- 'label' => 'Page 3',
- 'uri' => '#'
- )
- ));
- $this->assertEquals(1, count($nav),
- 'Expected 1 page, found ' . count($nav));
- }
- public function testGetPagesShouldReturnAnArrayOfPages()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'uri' => 'Page 1'
- ),
- array(
- 'uri' => 'Page 2'
- )
- ));
- $pages = $nav->getPages();
- $expected = array(
- 'type' => 'array',
- 'count' => 2
- );
- $actual = array(
- 'type' => gettype($pages),
- 'count' => count($pages)
- );
- $this->assertEquals($expected, $actual);
- $this->assertContainsOnly('Zend_Navigation_Page_Uri', $pages, false);
- }
- public function testGetPagesShouldReturnUnorderedPages()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 2',
- 'uri' => '#',
- 'order' => -1
- ),
- array(
- 'label' => 'Page 4',
- 'uri' => '#',
- 'order' => 100
- ),
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 5',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => '#'
- )
- ));
- $expected = array('Page 2', 'Page 4', 'Page 1', 'Page 5', 'Page 3');
- $actual = array();
- foreach ($nav->getPages() as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testRemovingPageByOrder()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#',
- 'order' => 32
- ),
- array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 4',
- 'uri' => '#'
- )
- ));
- $expected = array(
- 'remove0' => true,
- 'remove32' => true,
- 'remove0again' => true,
- 'remove1000' => false,
- 'count' => 1,
- 'current' => 'Page 4'
- );
- $actual = array(
- 'remove0' => $nav->removePage(0),
- 'remove32' => $nav->removePage(32),
- 'remove0again' => $nav->removePage(0),
- 'remove1000' => $nav->removePage(1000),
- 'count' => $nav->count(),
- 'current' => $nav->current()->getLabel()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testRemovingPageByInstance()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#'
- )
- ));
- $page3 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ));
- $nav->addPage($page3);
- $this->assertEquals(true, $nav->removePage($page3));
- }
- public function testRemovingPageByInstanceShouldReturnFalseIfPageIsNotInContainer()
- {
- $nav = new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ),
- array(
- 'label' => 'Page 2',
- 'uri' => '#'
- )
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'Page lol',
- 'uri' => '#'
- ));
- $this->assertEquals(false, $nav->removePage($page));
- }
- public function testHasPage()
- {
- $page0 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 0',
- 'uri' => '#'
- ));
- $page1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ));
- $page1_1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1.1',
- 'uri' => '#'
- ));
- $page1_2 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1.2',
- 'uri' => '#'
- ));
- $page1_2_1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1.2.1',
- 'uri' => '#'
- ));
- $page1_3 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1.3',
- 'uri' => '#'
- ));
- $page2 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 2',
- 'uri' => '#'
- ));
- $page3 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 3',
- 'uri' => '#'
- ));
- $nav = new Zend_Navigation(array($page1, $page2, $page3));
- $page1->addPage($page1_1);
- $page1->addPage($page1_2);
- $page1_2->addPage($page1_2_1);
- $page1->addPage($page1_3);
- $expected = array(
- 'haspage0' => false,
- 'haspage2' => true,
- 'haspage1_1' => false,
- 'haspage1_1recursive' => true
- );
- $actual = array(
- 'haspage0' => $nav->hasPage($page0),
- 'haspage2' => $nav->hasPage($page2),
- 'haspage1_1' => $nav->hasPage($page1_1),
- 'haspage1_1recursive' => $nav->hasPage($page1_1, true)
- );
- $this->assertEquals($expected, $actual);
- }
- public function testHasPages()
- {
- $nav1 = new Zend_Navigation();
- $nav2 = new Zend_Navigation();
- $nav2->addPage(array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ));
- $expected = array(
- 'empty' => false,
- 'notempty' => true
- );
- $actual = array(
- 'empty' => $nav1->hasPages(),
- 'notempty' => $nav2->hasPages()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetParentShouldWorkWithPage()
- {
- $page1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ));
- $page2 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 2',
- 'uri' => '#'
- ));
- $page2->setParent($page1);
- $expected = array(
- 'parent' => 'Page 1',
- 'hasPages' => true
- );
- $actual = array(
- 'parent' => $page2->getParent()->getLabel(),
- 'hasPages' => $page1->hasPages()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetParentShouldWorkWithNull()
- {
- $page1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ));
- $page2 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 2',
- 'uri' => '#'
- ));
- $page2->setParent($page1);
- $page2->setParent(null);
- $this->assertEquals(null, $page2->getParent());
- }
- public function testSetParentShouldRemoveFromOldParentPage()
- {
- $page1 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 1',
- 'uri' => '#'
- ));
- $page2 = Zend_Navigation_Page::factory(array(
- 'label' => 'Page 2',
- 'uri' => '#'
- ));
- $page2->setParent($page1);
- $page2->setParent(null);
- $expected = array(
- 'parent' => null,
- 'haspages' => false
- );
- $actual = array(
- 'parent' => $page2->getParent(),
- 'haspages' => $page2->hasPages()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testFinderMethodsShouldWorkWithCustomProperties()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findOneBy('page2', 'page2');
- $this->assertType('Zend_Navigation_Page', $found);
- $this->assertEquals('Page 2', $found->getLabel());
- }
- public function testFindOneByShouldReturnOnlyOnePage()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findOneBy('id', 'page_2_and_3');
- $this->assertType('Zend_Navigation_Page', $found);
- $this->assertEquals('Page 2', $found->getLabel());
- }
- public function testFindOneByShouldReturnNullIfNotFound()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findOneBy('id', 'non-existant');
- $this->assertNull($found);
- }
- public function testFindAllByShouldReturnAllMatchingPages()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findAllBy('id', 'page_2_and_3');
- $this->assertContainsOnly('Zend_Navigation_Page', $found, false);
- $expected = array('Page 2', 'Page 3');
- $actual = array();
- foreach ($found as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testFindAllByShouldReturnEmptyArrayifNotFound()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findAllBy('id', 'non-existant');
- $expected = array('type' => 'array', 'count' => 0);
- $actual = array('type' => gettype($found), 'count' => count($found));
- $this->assertEquals($expected, $actual);
- }
- public function testFindByShouldDefaultToFindOneBy()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findBy('id', 'page_2_and_3');
- $this->assertType('Zend_Navigation_Page', $found);
- }
- public function testFindOneByMagicMethodNativeProperty()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findOneById('page_2_and_3');
- $this->assertType('Zend_Navigation_Page', $found);
- $this->assertEquals('Page 2', $found->getLabel());
- }
- public function testFindOneByMagicMethodCustomProperty()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findOneBypage2('page2');
- $this->assertType('Zend_Navigation_Page', $found);
- $this->assertEquals('Page 2', $found->getLabel());
- }
- public function testFindAllByWithMagicMethodNativeProperty()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findAllById('page_2_and_3');
- $this->assertContainsOnly('Zend_Navigation_Page', $found, false);
- $expected = array('Page 2', 'Page 3');
- $actual = array();
- foreach ($found as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testFindAllByMagicUcfirstPropDoesNotFindCustomLowercaseProps()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findAllByAction('about');
- $this->assertContainsOnly('Zend_Navigation_Page', $found, false);
- $expected = array('Page 3');
- $actual = array();
- foreach ($found as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testFindAllByMagicLowercaseFindsBothNativeAndCustomProps()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findAllByaction('about');
- $this->assertContainsOnly('Zend_Navigation_Page', $found, false);
- $expected = array('Page 1.3', 'Page 3');
- $actual = array();
- foreach ($found as $page) {
- $actual[] = $page->getLabel();
- }
- $this->assertEquals($expected, $actual);
- }
- public function testFindByMagicMethodIsEquivalentToFindOneBy()
- {
- $nav = $this->_getFindByNavigation();
- $found = $nav->findById('page_2_and_3');
- $this->assertType('Zend_Navigation_Page', $found);
- $this->assertEquals('Page 2', $found->getLabel());
- }
- public function testInvalidMagicFinderMethodShouldThrowException()
- {
- $nav = $this->_getFindByNavigation();
- try {
- $found = $nav->findSomeById('page_2_and_3');
- $this->fail('An invalid magic finder method was used, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Bad method call', $e->getMessage());
- }
- }
- public function testInvalidMagicMethodShouldThrowException()
- {
- $nav = $this->_getFindByNavigation();
- try {
- $found = $nav->getPagez();
- $this->fail('An invalid magic finder method was used, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Bad method call', $e->getMessage());
- }
- }
- protected function _getFindByNavigation()
- {
- // findAllByFoo('bar') // Page 1, Page 1.1
- // findById('page_2_and_3') // Page 2
- // findOneById('page_2_and_3') // Page 2
- // findAllById('page_2_and_3') // Page 2, Page 3
- // findAllByAction('about') // Page 1.3, Page 3
- return new Zend_Navigation(array(
- array(
- 'label' => 'Page 1',
- 'uri' => 'page-1',
- 'foo' => 'bar',
- 'pages' => array(
- array(
- 'label' => 'Page 1.1',
- 'uri' => 'page-1.1',
- 'foo' => 'bar',
- 'title' => 'The given title'
- ),
- array(
- 'label' => 'Page 1.2',
- 'uri' => 'page-1.2',
- 'title' => 'The given title'
- ),
- array(
- 'type' => 'uri',
- 'label' => 'Page 1.3',
- 'uri' => 'page-1.3',
- 'title' => 'The given title',
- 'action' => 'about'
- )
- )
- ),
- array(
- 'id' => 'page_2_and_3',
- 'label' => 'Page 2',
- 'module' => 'page2',
- 'controller' => 'index',
- 'action' => 'page1',
- 'page2' => 'page2'
- ),
- array(
- 'id' => 'page_2_and_3',
- 'label' => 'Page 3',
- 'module' => 'page3',
- 'controller' => 'index',
- 'action' => 'about'
- )
- ));
- }
- public function testCurrent()
- {
- $container = new Zend_Navigation(array(
- array(
- 'label' => 'Page 2',
- 'type' => 'uri'
- ),
- array(
- 'label' => 'Page 1',
- 'type' => 'uri',
- 'order' => -1
- )
- ));
- $page = $container->current();
- $this->assertEquals('Page 1', $page->getLabel());
- }
- public function testCurrentShouldThrowExceptionIfIndexIsInvalid()
- {
- require_once dirname(__FILE__) . '/_files/My/Container.php';
- $container = new My_Container(array(
- array(
- 'label' => 'Page 2',
- 'type' => 'uri'
- ),
- array(
- 'label' => 'Page 1',
- 'type' => 'uri',
- 'order' => -1
- )
- ));
- try {
- $page = $container->current();
- $this->fail('Container index is invalid, ' .
- 'but a Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Corruption detected', $e->getMessage());
- }
- }
- public function testKeyWhenContainerIsEmpty()
- {
- $container = new Zend_Navigation();
- $this->assertEquals(null, $container->key());
- }
- public function testKeyShouldReturnCurrentPageHash()
- {
- $container = new Zend_Navigation();
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri'
- ));
- $container->addPage($page);
- $this->assertEquals($page->hashCode(), $container->key());
- }
- public function testGetChildrenShouldReturnTheCurrentPage()
- {
- $container = new Zend_Navigation();
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri'
- ));
- $container->addPage($page);
- $this->assertEquals($page, $container->getChildren());
- }
- public function testGetChildrenShouldReturnNullWhenContainerIsEmpty()
- {
- $container = new Zend_Navigation();
- $this->assertEquals(null, $container->getChildren());
- }
- }
|