| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396 |
- <?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-2015 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-2015 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',
- 'fragment' => null,
- 'id' => null,
- 'class' => null,
- 'title' => null,
- 'target' => null,
- 'accesskey' => null,
- 'rel' => array(),
- 'rev' => array(),
- 'customHtmlAttribs' => array(),
- 'order' => null,
- 'resource' => null,
- 'privilege' => null,
- 'active' => false,
- 'visible' => true,
- 'type' => 'Zend_Navigation_Page_Uri',
- 'pages' => array (),
- ),
- array(
- 'label' => 'foo.baz',
- 'uri' => 'http://www.example.com/foo.html',
- 'fragment' => null,
- 'id' => null,
- 'class' => null,
- 'title' => null,
- 'target' => null,
- 'accesskey' => null,
- 'rel' => array(),
- 'rev' => array(),
- 'customHtmlAttribs' => array (),
- 'order' => null,
- 'resource' => null,
- 'privilege' => null,
- 'active' => false,
- 'visible' => true,
- 'type' => 'Zend_Navigation_Page_Uri',
- 'pages' => array (),
- )
- ),
- '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';
- // should be same
- $this->assertEquals($options, $toArray);
- // $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;
- $options['customHtmlAttribs'] = array();
- $options['pages'] = array();
- unset($options['foo']);
- unset($options['meaning']);
- // assert that there is no diff from what we expect
- $this->assertEquals($options, $toArray['pages'][0]);
- // 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
- $this->assertEquals($options, $toArray['pages'][1]);
- }
-
- /**
- * @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()
- );
- }
- }
- }
|