| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367 |
- <?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-2012 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/Page.php';
- require_once 'Zend/Config.php';
- /**
- * Tests the class Zend_Navigation_Page
- *
- * @author Robin Skoglund
- * @category Zend
- * @package Zend_Navigation
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 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_PageTest 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()
- {
- // setConfig, setOptions
- }
- public function testSetShouldMapToNativeProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'mvc'
- ));
- $page->set('action', 'foo');
- $this->assertEquals('foo', $page->getAction());
- $page->set('Action', 'bar');
- $this->assertEquals('bar', $page->getAction());
- }
- public function testGetShouldMapToNativeProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'mvc'
- ));
- $page->setAction('foo');
- $this->assertEquals('foo', $page->get('action'));
- $page->setAction('bar');
- $this->assertEquals('bar', $page->get('Action'));
- }
- public function testSetShouldNormalizePropertyName()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'mvc'
- ));
- $page->setResetParams(false);
- $page->set('reset_params', true);
- $this->assertTrue($page->getResetParams());
- }
- public function testGetShouldNormalizePropertyName()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'mvc'
- ));
- $page->setResetParams(false);
- $this->assertFalse($page->get('reset_params'));
- }
- public function testShouldSetAndGetShouldMapToProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri'
- ));
- $page->set('action', 'Laughing Out Loud');
- $this->assertEquals('Laughing Out Loud', $page->get('action'));
- }
- public function testSetShouldNotMapToSetOptionsToPreventRecursion()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'foo'
- ));
- $options = array('label' => 'bar');
- $page->set('options', $options);
- $this->assertEquals('foo', $page->getLabel());
- $this->assertEquals($options, $page->get('options'));
- }
- public function testSetShouldNotMapToSetConfigToPreventRecursion()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'foo'
- ));
- $options = array('label' => 'bar');
- $page->set('config', $options);
- $this->assertEquals('foo', $page->getLabel());
- $this->assertEquals($options, $page->get('config'));
- }
- public function testSetAndGetLabel()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals('foo', $page->getLabel());
- $page->setLabel('bar');
- $this->assertEquals('bar', $page->getLabel());
- $invalids = array(42, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setLabel($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: $label', $e->getMessage());
- }
- }
- }
- /**
- * @group ZF-8922
- */
- public function testSetAndGetFragmentIdentifier()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'uri' => '#',
- 'fragment' => 'foo',
- ));
-
- $this->assertEquals('foo', $page->getFragment());
-
- $page->setFragment('bar');
- $this->assertEquals('bar', $page->getFragment());
-
- $invalids = array(42, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setFragment($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: $fragment', $e->getMessage()
- );
- }
- }
- }
- public function testSetAndGetId()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals(null, $page->getId());
- $page->setId('bar');
- $this->assertEquals('bar', $page->getId());
- $invalids = array(true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setId($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: $id', $e->getMessage());
- }
- }
- }
- public function testIdCouldBeAnInteger()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#',
- 'id' => 10
- ));
- $this->assertEquals(10, $page->getId());
- }
- public function testSetAndGetClass()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals(null, $page->getClass());
- $page->setClass('bar');
- $this->assertEquals('bar', $page->getClass());
- $invalids = array(42, true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setClass($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: $class', $e->getMessage());
- }
- }
- }
- public function testSetAndGetTitle()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals(null, $page->getTitle());
- $page->setTitle('bar');
- $this->assertEquals('bar', $page->getTitle());
- $invalids = array(42, true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setTitle($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: $title', $e->getMessage());
- }
- }
- }
- public function testSetAndGetTarget()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals(null, $page->getTarget());
- $page->setTarget('bar');
- $this->assertEquals('bar', $page->getTarget());
- $invalids = array(42, true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setTarget($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: $target', $e->getMessage());
- }
- }
- }
- /**
- * @group ZF-9746
- */
- public function testSetAndGetAccesskey()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#',
- ));
-
- $this->assertEquals(null, $page->getAccesskey());
- $page->setAccesskey('b');
- $this->assertEquals('b', $page->getAccesskey());
-
- $invalids = array('bar', 42, true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setAccesskey($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: $character',
- $e->getMessage()
- );
- }
- }
- }
- public function testConstructingWithRelationsInArray()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'bar',
- 'uri' => '#',
- 'rel' => array(
- 'prev' => 'foo',
- 'next' => 'baz'
- ),
- 'rev' => array(
- 'alternate' => 'bat'
- )
- ));
- $expected = array(
- 'rel' => array(
- 'prev' => 'foo',
- 'next' => 'baz'
- ),
- 'rev' => array(
- 'alternate' => 'bat'
- )
- );
- $actual = array(
- 'rel' => $page->getRel(),
- 'rev' => $page->getRev()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testConstructingWithRelationsInConfig()
- {
- $page = Zend_Navigation_Page::factory(new Zend_Config(array(
- 'label' => 'bar',
- 'uri' => '#',
- 'rel' => array(
- 'prev' => 'foo',
- 'next' => 'baz'
- ),
- 'rev' => array(
- 'alternate' => 'bat'
- )
- )));
- $expected = array(
- 'rel' => array(
- 'prev' => 'foo',
- 'next' => 'baz'
- ),
- 'rev' => array(
- 'alternate' => 'bat'
- )
- );
- $actual = array(
- 'rel' => $page->getRel(),
- 'rev' => $page->getRev()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testGettingSpecificRelations()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'bar',
- 'uri' => '#',
- 'rel' => array(
- 'prev' => 'foo',
- 'next' => 'baz'
- ),
- 'rev' => array(
- 'next' => 'foo'
- )
- ));
- $expected = array(
- 'foo', 'foo'
- );
- $actual = array(
- $page->getRel('prev'),
- $page->getRev('next')
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetAndGetOrder()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals(null, $page->getOrder());
- $page->setOrder('1');
- $this->assertEquals(1, $page->getOrder());
- $page->setOrder(1337);
- $this->assertEquals(1337, $page->getOrder());
- $page->setOrder('-25');
- $this->assertEquals(-25, $page->getOrder());
- $invalids = array(3.14, 'e', "\n", '0,4', true, (object) null);
- foreach ($invalids as $invalid) {
- try {
- $page->setOrder($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: $order', $e->getMessage());
- }
- }
- }
- public function testSetResourceString()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello'
- ));
- $page->setResource('foo');
- $this->assertEquals('foo', $page->getResource());
- }
- public function testSetResourceNoParam()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello',
- 'resource' => 'foo'
- ));
- $page->setResource();
- $this->assertEquals(null, $page->getResource());
- }
- public function testSetResourceNull()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello',
- 'resource' => 'foo'
- ));
- $page->setResource(null);
- $this->assertEquals(null, $page->getResource());
- }
- public function testSetResourceInterface()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello'
- ));
- require_once 'Zend/Acl/Resource.php';
- $resource = new Zend_Acl_Resource('bar');
- $page->setResource($resource);
- $this->assertEquals($resource, $page->getResource());
- }
- public function testSetResourceShouldThrowExceptionWhenGivenInteger()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello'
- ));
- try {
- $page->setResource(0);
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $resource', $e->getMessage());
- }
- }
- public function testSetResourceShouldThrowExceptionWhenGivenObject()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello'
- ));
- try {
- $page->setResource(new stdClass());
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $resource', $e->getMessage());
- }
- }
- public function testSetPrivilegeNoParams()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello',
- 'privilege' => 'foo'
- ));
- $page->setPrivilege();
- $this->assertEquals(null, $page->getPrivilege());
- }
- public function testSetPrivilegeNull()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello',
- 'privilege' => 'foo'
- ));
- $page->setPrivilege(null);
- $this->assertEquals(null, $page->getPrivilege());
- }
- public function testSetPrivilegeString()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'hello',
- 'privilege' => 'foo'
- ));
- $page->setPrivilege('bar');
- $this->assertEquals('bar', $page->getPrivilege());
- }
- public function testGetActiveOnNewlyConstructedPageShouldReturnFalse()
- {
- $page = new Zend_Navigation_Page_Uri();
- $this->assertFalse($page->getActive());
- }
- public function testIsActiveOnNewlyConstructedPageShouldReturnFalse()
- {
- $page = new Zend_Navigation_Page_Uri();
- $this->assertFalse($page->isActive());
- }
- public function testGetActiveShouldReturnTrueIfPageIsActive()
- {
- $page = new Zend_Navigation_Page_Uri(array('active' => true));
- $this->assertTrue($page->getActive());
- }
- public function testIsActiveShouldReturnTrueIfPageIsActive()
- {
- $page = new Zend_Navigation_Page_Uri(array('active' => true));
- $this->assertTrue($page->isActive());
- }
- public function testIsActiveWithRecursiveTrueShouldReturnTrueIfChildActive()
- {
- $page = new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1',
- 'active' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'active' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'active' => true
- ))
- )
- ))
- )
- ));
- $this->assertFalse($page->isActive(false));
- $this->assertTrue($page->isActive(true));
- }
- public function testGetActiveWithRecursiveTrueShouldReturnTrueIfChildActive()
- {
- $page = new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1',
- 'active' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'active' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'active' => true
- ))
- )
- ))
- )
- ));
- $this->assertFalse($page->getActive(false));
- $this->assertTrue($page->getActive(true));
- }
- public function testSetActiveWithNoParamShouldSetFalse()
- {
- $page = new Zend_Navigation_Page_Uri();
- $page->setActive();
- $this->assertTrue($page->getActive());
- }
- public function testSetActiveShouldJuggleValue()
- {
- $page = new Zend_Navigation_Page_Uri();
- $page->setActive(1);
- $this->assertTrue($page->getActive());
- $page->setActive('true');
- $this->assertTrue($page->getActive());
- $page->setActive(0);
- $this->assertFalse($page->getActive());
- $page->setActive(array());
- $this->assertFalse($page->getActive());
- }
- public function testIsVisibleOnNewlyConstructedPageShouldReturnTrue()
- {
- $page = new Zend_Navigation_Page_Uri();
- $this->assertTrue($page->isVisible());
- }
- public function testGetVisibleOnNewlyConstructedPageShouldReturnTrue()
- {
- $page = new Zend_Navigation_Page_Uri();
- $this->assertTrue($page->getVisible());
- }
- public function testIsVisibleShouldReturnFalseIfPageIsNotVisible()
- {
- $page = new Zend_Navigation_Page_Uri(array('visible' => false));
- $this->assertFalse($page->isVisible());
- }
- public function testGetVisibleShouldReturnFalseIfPageIsNotVisible()
- {
- $page = new Zend_Navigation_Page_Uri(array('visible' => false));
- $this->assertFalse($page->getVisible());
- }
- public function testIsVisibleRecursiveTrueShouldReturnFalseIfParentInivisble()
- {
- $page = new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1',
- 'visible' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1'
- ))
- )
- ))
- )
- ));
- $childPage = $page->findOneByLabel('Page 1.1');
- $this->assertTrue($childPage->isVisible(false));
- $this->assertFalse($childPage->isVisible(true));
- }
- public function testGetVisibleRecursiveTrueShouldReturnFalseIfParentInivisble()
- {
- $page = new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1',
- 'visible' => false,
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1',
- 'pages' => array(
- new Zend_Navigation_Page_Uri(array(
- 'label' => 'Page 1.1'
- ))
- )
- ))
- )
- ));
- $childPage = $page->findOneByLabel('Page 1.1');
- $this->assertTrue($childPage->getVisible(false));
- $this->assertFalse($childPage->getVisible(true));
- }
- public function testSetVisibleWithNoParamShouldSetVisble()
- {
- $page = new Zend_Navigation_Page_Uri(array('visible' => false));
- $page->setVisible();
- $this->assertTrue($page->isVisible());
- }
- public function testSetVisibleShouldJuggleValue()
- {
- $page = new Zend_Navigation_Page_Uri();
- $page->setVisible(1);
- $this->assertTrue($page->isVisible());
- $page->setVisible('true');
- $this->assertTrue($page->isVisible());
- $page->setVisible(0);
- $this->assertFalse($page->isVisible());
- /**
- * ZF-10146
- *
- * @link http://framework.zend.com/issues/browse/ZF-10146
- */
- $page->setVisible('False');
- $this->assertFalse($page->isVisible());
- $page->setVisible(array());
- $this->assertFalse($page->isVisible());
- }
- public function testMagicOverLoadsShouldSetAndGetNativeProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => 'foo'
- ));
- $this->assertSame('foo', $page->getUri());
- $this->assertSame('foo', $page->uri);
- $page->uri = 'bar';
- $this->assertSame('bar', $page->getUri());
- $this->assertSame('bar', $page->uri);
- }
- public function testMagicOverLoadsShouldCheckNativeProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => 'foo'
- ));
- $this->assertTrue(isset($page->uri));
- try {
- unset($page->uri);
- $this->fail('Should not be possible to unset native properties');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Unsetting native property', $e->getMessage());
- }
- }
- public function testMagicOverLoadsShouldHandleCustomProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => 'foo'
- ));
- $this->assertFalse(isset($page->category));
- $page->category = 'music';
- $this->assertTrue(isset($page->category));
- $this->assertSame('music', $page->category);
- unset($page->category);
- $this->assertFalse(isset($page->category));
- }
- public function testMagicToStringMethodShouldReturnLabel()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $this->assertEquals('foo', (string) $page);
- }
- public function testSetOptionsShouldTranslateToAccessor()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'action' => 'index',
- 'controller' => 'index'
- ));
- $options = array(
- 'label' => 'bar',
- 'action' => 'baz',
- 'controller' => 'bat',
- 'module' => 'test',
- 'reset_params' => false,
- 'id' => 'foo-test'
- );
- $page->setOptions($options);
- $expected = array(
- 'label' => 'bar',
- 'action' => 'baz',
- 'controller' => 'bat',
- 'module' => 'test',
- 'resetParams' => false,
- 'id' => 'foo-test'
- );
- $actual = array(
- 'label' => $page->getLabel(),
- 'action' => $page->getAction(),
- 'controller' => $page->getController(),
- 'module' => $page->getModule(),
- 'resetParams' => $page->getResetParams(),
- 'id' => $page->getId()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetConfig()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'action' => 'index',
- 'controller' => 'index'
- ));
- $options = array(
- 'label' => 'bar',
- 'action' => 'baz',
- 'controller' => 'bat',
- 'module' => 'test',
- 'reset_params' => false,
- 'id' => 'foo-test'
- );
- $page->setConfig(new Zend_Config($options));
- $expected = array(
- 'label' => 'bar',
- 'action' => 'baz',
- 'controller' => 'bat',
- 'module' => 'test',
- 'resetParams' => false,
- 'id' => 'foo-test'
- );
- $actual = array(
- 'label' => $page->getLabel(),
- 'action' => $page->getAction(),
- 'controller' => $page->getController(),
- 'module' => $page->getModule(),
- 'resetParams' => $page->getResetParams(),
- 'id' => $page->getId()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetOptionsShouldSetCustomProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#'
- ));
- $options = array(
- 'test' => 'test',
- 'meaning' => 42
- );
- $page->setOptions($options);
- $actual = array(
- 'test' => $page->test,
- 'meaning' => $page->meaning
- );
- $this->assertEquals($options, $actual);
- }
- public function testAddingRelations()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'page',
- 'uri' => '#'
- ));
- $page->addRel('alternate', 'foo');
- $page->addRev('alternate', 'bar');
- $expected = array(
- 'rel' => array('alternate' => 'foo'),
- 'rev' => array('alternate' => 'bar')
- );
- $actual = array(
- 'rel' => $page->getRel(),
- 'rev' => $page->getRev()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testRemovingRelations()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'page',
- 'uri' => '#'
- ));
- $page->addRel('alternate', 'foo');
- $page->addRev('alternate', 'bar');
- $page->removeRel('alternate');
- $page->removeRev('alternate');
- $expected = array(
- 'rel' => array(),
- 'rev' => array()
- );
- $actual = array(
- 'rel' => $page->getRel(),
- 'rev' => $page->getRev()
- );
- $this->assertEquals($expected, $actual);
- }
- public function testSetRelShouldWorkWithArray()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rel' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array('alternate' => 'format/xml');
- $page->setRel($value);
- $this->assertEquals($value, $page->getRel());
- }
- public function testSetRelShouldWorkWithConfig()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rel' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array('alternate' => 'format/xml');
- $page->setRel(new Zend_Config($value));
- $this->assertEquals($value, $page->getRel());
- }
- public function testSetRelShouldWithNoParamsShouldResetRelations()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rel' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array();
- $page->setRel();
- $this->assertEquals($value, $page->getRel());
- }
- public function testSetRelShouldThrowExceptionWhenNotNullOrArrayOrConfig()
- {
- $page = Zend_Navigation_Page::factory(array('type' => 'uri'));
- try {
- $page->setRel('alternate');
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $relations', $e->getMessage());
- }
- }
- public function testSetRevShouldWorkWithArray()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rev' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array('alternate' => 'format/xml');
- $page->setRev($value);
- $this->assertEquals($value, $page->getRev());
- }
- public function testSetRevShouldWorkWithConfig()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rev' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array('alternate' => 'format/xml');
- $page->setRev(new Zend_Config($value));
- $this->assertEquals($value, $page->getRev());
- }
- public function testSetRevShouldWithNoParamsShouldResetRelations()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rev' => array(
- 'foo' => 'bar',
- 'baz' => 'bat'
- )
- ));
- $value = array();
- $page->setRev();
- $this->assertEquals($value, $page->getRev());
- }
- public function testSetRevShouldThrowExceptionWhenNotNullOrArrayOrConfig()
- {
- $page = Zend_Navigation_Page::factory(array('type' => 'uri'));
- try {
- $page->setRev('alternate');
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertContains('Invalid argument: $relations', $e->getMessage());
- }
- }
- public function testGetRelWithArgumentShouldRetrieveSpecificRelation()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rel' => array(
- 'foo' => 'bar'
- )
- ));
- $this->assertEquals('bar', $page->getRel('foo'));
- }
- public function testGetRevWithArgumentShouldRetrieveSpecificRelation()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rev' => array(
- 'foo' => 'bar'
- )
- ));
- $this->assertEquals('bar', $page->getRev('foo'));
- }
- public function testGetDefinedRel()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rel' => array(
- 'alternate' => 'foo',
- 'foo' => 'bar'
- )
- ));
- $expected = array('alternate', 'foo');
- $this->assertEquals($expected, $page->getDefinedRel());
- }
- public function testGetDefinedRev()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'rev' => array(
- 'alternate' => 'foo',
- 'foo' => 'bar'
- )
- ));
- $expected = array('alternate', 'foo');
- $this->assertEquals($expected, $page->getDefinedRev());
- }
- public function testGetCustomProperties()
- {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'foo',
- 'uri' => '#',
- 'baz' => 'bat'
- ));
- $options = array(
- 'test' => 'test',
- 'meaning' => 42
- );
- $page->setOptions($options);
- $expected = array(
- 'baz' => 'bat',
- 'test' => 'test',
- 'meaning' => 42
- );
- $this->assertEquals($expected, $page->getCustomProperties());
- }
- /**
- * @group ZF-11876
- */
- public function testSetCustomHtmlAttrib()
- {
- $page = Zend_Navigation_Page::factory(
- array(
- 'type' => 'uri',
- )
- );
- $page->setCustomHtmlAttrib('rel', 'nofollow');
- $this->assertEquals('nofollow', $page->getCustomHtmlAttrib('rel'));
- }
- /**
- * @group ZF-11876
- */
- public function testSetCustomHtmlAttribWithNull()
- {
- $page = Zend_Navigation_Page::factory(
- array(
- 'type' => 'uri',
- )
- );
- $page->setCustomHtmlAttrib('rel', 'nofollow');
- $page->setCustomHtmlAttrib('rel', null);
- $this->assertNull($page->getCustomHtmlAttrib('rel'));
- }
- /**
- * @group ZF-11876
- */
- public function testSetCustomHtmlAttribs()
- {
- $page = Zend_Navigation_Page::factory(
- array(
- 'type' => 'uri',
- )
- );
- $attribs = array(
- 'rel' => 'nofollow',
- 'style' => 'font-weight: bold;',
- );
- $page->setCustomHtmlAttribs($attribs);
- $this->assertEquals($attribs, $page->getCustomHtmlAttribs());
- }
- /**
- * @group ZF-11876
- */
- public function testRemoveCustomHtmlAttrib()
- {
- $page = Zend_Navigation_Page::factory(
- array(
- 'type' => 'uri',
- )
- );
- $page->setCustomHtmlAttrib('rel', 'nofollow');
- $page->removeCustomHtmlAttrib('rel');
- $this->assertEquals(array(), $page->getCustomHtmlAttribs());
- }
- /**
- * @group ZF-11876
- */
- public function testClearCustomHtmlAttribs()
- {
- $page = Zend_Navigation_Page::factory(
- array(
- 'type' => 'uri',
- )
- );
- $page->setCustomHtmlAttribs(
- array(
- 'rel' => 'nofollow',
- 'style' => 'font-weight: bold;',
- )
- );
- $page->clearCustomHtmlAttribs();
- $this->assertEquals(array(), $page->getCustomHtmlAttribs());
- }
- public function testToArrayMethod()
- {
- $options = array(
- 'label' => 'foo',
- 'uri' => 'http://www.example.com/foo.html',
- 'fragment' => 'bar',
- 'id' => 'my-id',
- 'class' => 'my-class',
- 'title' => 'my-title',
- 'target' => 'my-target',
- 'accesskey' => 'f',
- 'rel' => array(),
- 'rev' => array(),
- 'order' => 100,
- 'active' => true,
- 'visible' => false,
- 'resource' => 'joker',
- 'privilege' => null,
- 'foo' => 'bar',
- 'meaning' => 42,
- 'pages' => array(
- array(
- 'label' => 'foo.bar',
- 'uri' => 'http://www.example.com/foo.html'
- ),
- array(
- 'label' => 'foo.baz',
- 'uri' => 'http://www.example.com/foo.html'
- )
- ),
- 'customHtmlAttribs' => array(
- 'rel' => 'nofollow',
- 'style' => 'font-weight: bold;',
- ),
- );
- $page = Zend_Navigation_Page::factory($options);
- $toArray = $page->toArray();
- // tweak options to what we expect toArray() to contain
- $options['type'] = 'Zend_Navigation_Page_Uri';
- // calculate diff between toArray() and $options
- $diff = array_diff_assoc($options, $toArray);
- // should be no diff
- $this->assertEquals(array(), $diff);
- // $toArray should have 2 sub pages
- $this->assertEquals(2, count($toArray['pages']));
- // tweak options to what we expect sub page 1 to be
- $options['label'] = 'foo.bar';
- $options['fragment'] = null;
- $options['order'] = null;
- $options['id'] = null;
- $options['class'] = null;
- $options['title'] = null;
- $options['target'] = null;
- $options['accesskey'] = null;
- $options['resource'] = null;
- $options['active'] = false;
- $options['visible'] = true;
- unset($options['foo']);
- unset($options['meaning']);
- // assert that there is no diff from what we expect
- $subPageOneDiff = array_diff_assoc($toArray['pages'][0], $options);
- $this->assertEquals(array(), $subPageOneDiff);
- // tweak options to what we expect sub page 2 to be
- $options['label'] = 'foo.baz';
- // assert that there is no diff from what we expect
- $subPageTwoDiff = array_diff_assoc($toArray['pages'][1], $options);
- $this->assertEquals(array(), $subPageTwoDiff);
- }
-
- /**
- * @group ZF-11805
- */
- public function testFactoryExceptionWhenNoPageTypeDetected()
- {
- // Without label
- try {
- $page = Zend_Navigation_Page::factory(array());
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertSame(
- 'Invalid argument: Unable to determine class to instantiate',
- $e->getMessage()
- );
- }
-
- // With label
- try {
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'Foo',
- ));
- $this->fail('An invalid value was set, but a ' .
- 'Zend_Navigation_Exception was not thrown');
- } catch (Zend_Navigation_Exception $e) {
- $this->assertSame(
- 'Invalid argument: Unable to determine class to instantiate'
- . ' (Page label: Foo)',
- $e->getMessage()
- );
- }
- }
- }
|