$t->info('1 - Test getChildrenIndexedByName().'); extract(create_doctrine_test_tree($t)); // create the tree and make its vars accessible print_test_tree($t); $children = $rt->getChildrenIndexedByName(); $t->is(count($children), 2, '->getChildrenIndexedByName() returns 2 for rt'); $t->is(array_keys($children), array('Parent 1', 'Parent 2'), '->getChildrenIndexedByName() has the correct indexes'); $t->is($children['Parent 1']->name, 'Parent 1', '->getChildrenIndexedByName() returns the correct items.'); $t->is(count($pt1->getChildrenIndexedByName()), 3, '->getChildrenIndexedByName() returns 3 item for pt1.'); $t->is(count($pt2->getChildrenIndexedByName()), 1, '->getChildrenIndexedByName() returns 1 item for pt2.'); $t->info('2 - Test persistFromMenuArray() in a varierty of situations.'); $menu = new ioMenuItem('Root li'); $t->info(' 2.1 - First try it without any children - should just update root values.'); $t->info(' 2.1.1 - Persist a menu with mostly blank fields.'); $rt = create_root('rt'); $menu->setAttributes(array()); // clear the default "root" class attribute $rt->persistFromMenuArray($menu->toArray(false)); $t->is($rt->getName(), 'Root li', '->getName() returns "Root li".'); $t->is($rt->getLabel(), null, '->getLabel() returns null.'); $t->is($rt->getRoute(), null, '->getRoute() returns null.'); $t->is($rt->getAttributes(), '', '->getAttributes() returns an empty string.'); $t->is($rt->getRequiresAuth(), false, '->getRequiresAuth() returns false.'); $t->is($rt->getRequiresNoAuth(), false, '->getRequiresNoAuth() returns false.'); $t->is(count($rt->Permissions), 0, '->Permissions matches 0 items'); // setup some interesting values to persist $menu->setLabel('sympal'); $menu->setRoute('http://www.sympalphp.org'); $menu->setAttributes(array('class' => 'root', 'id' => 'sympal_menu')); $menu->requiresAuth(true); $menu->requiresNoAuth(false);
$this->_userAccess = null; } } $t->info('1 - Test basic getters, setters and constructor'); $menu = new ioMenuItem('test menu', '@homepage', array('title' => 'my menu')); $t->is($menu->getName(), 'test menu', '->getName() returns the given name.'); $menu->setName('new menu name'); $t->is($menu->getName(), 'new menu name', '->setName() sets the name correctly.'); $t->is($menu->getLabel(), 'new menu name', '->getLabel() returns the name if the label does not exist.'); $menu->setLabel('menu label'); $t->is($menu->getLabel(), 'menu label', 'Once set, ->getLabel() returns the actual label.'); $t->is($menu->getRoute(), '@homepage', '->getRoute() returns the given route.'); $menu->setRoute('http://www.sympalphp.org'); $t->is($menu->getRoute(), 'http://www.sympalphp.org', '->setRoute() sets the route correctly.'); $t->is($menu->getAttributes(), array('title' => 'my menu'), '->getAttributes() returns the attributes array.'); $menu->setAttributes(array('id' => 'unit_test')); $t->is($menu->getAttributes(), array('id' => 'unit_test'), '->setAttributes() sets the attributes array.'); $t->is($menu->getAttribute('id', 'default'), 'unit_test', '->getAttribute() returns an existing attribute correctly.'); $t->is($menu->getAttribute('fake', 'default'), 'default', '->getAttribute() returns the default for a non-existent attribute.'); $menu->setAttribute('class', 'testing classes'); $t->is($menu->getAttribute('class'), 'testing classes', '->setAttribute() correctly sets an attribute.'); $t->is($menu->requiresAuth(), false, 'By default ->requiresAuth() returns false.'); $menu->requiresAuth(true); $t->is($menu->requiresAuth(), true, 'Calling ->requiresAuth() with an argument sets the property.'); $t->is($menu->requiresNoAuth(), false, 'By default ->requiresNoAuth() returns false.'); $menu->requiresNoAuth(true); $t->is($menu->requiresNoAuth(), true, 'Calling ->requiresNoAuth() with an argument sets the property.'); $menu->setCredentials(array('c1', 'c2')); $t->is($menu->getCredentials(), array('c1', 'c2'), '->setCredentials() with an array sets all of the given credentials.'); $t->is($menu->showChildren(), true, '->showChildren() return true by default.'); $menu->showChildren(false);