// 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); $menu->setCredentials(array(array('c1', 'c2'))); $t->info(' 2.1.2 - Persisting a menu with multi-level credentials is not supported - an exception is thrown.'); $rt = create_root('rt'); try { $rt->persistFromMenuArray($menu->toArray(false)); $t->fail('Exception not thrown'); } catch (sfException $e) { $t->pass('Exception thrown: ' . $e->getMessage()); } $t->info(' 2.1.3 - Persist a valid menu item with several different fields filled in (no refresh).'); $rt = create_root('rt'); $menu->setCredentials(array('c1', 'c2')); $rt->persistFromMenuArray($menu->toArray(false)); basic_root_menu_check($rt, $t); $t->info(' 2.1.4 - Run the same checks after a full refresh on rt. See that the values were actually persisted.'); $rt->refresh(true);
$t->info('4 - Check the credentials and security functions.'); $t->info(' 4.1 - Test ->checkUserAccess() under a variety of conditions.'); $userMenu = new ioMenuItem('user menu'); $user = new sfBasicSecurityUser($configuration->getEventDispatcher(), new sfNoStorage()); $t->is($userMenu->checkUserAccess($user), true, '->checkUserAccess() returns true for a menu with no restrictions.'); $userMenu->requiresAuth(true); $t->is($userMenu->checkUserAccess($user), false, '->checkUserAccess() returns false if the menu requires auth but the user is not authenticated.'); $user->setAuthenticated(true); $t->is($userMenu->checkUserAccess($user), true, '->checkUserAccess() returns true if the menu requires auth and the user is authenticated.'); $userMenu->requiresNoAuth(true); $userMenu->requiresAuth(false); $t->is($userMenu->checkUserAccess($user), false, '->checkUserAccess() returns false if the menu requires NO auth and the user is authenticated.'); $user->setAuthenticated(false); $t->is($userMenu->checkUserAccess($user), true, '->checkUserAccess() returns true if the menu requires NO auth and the user is NOT authenticated.'); $userMenu = new ioMenuItem('user menu'); $userMenu->setCredentials(array('c1', 'c2')); $user->addCredential('c1'); $t->is($userMenu->checkUserAccess($user), false, '->checkUserAccess() returns false when the menu requires a credential the user does not have.'); $user->addCredential('c2'); $t->is($userMenu->checkUserAccess($user), true, '->checkUserAccess() returns true when the menu requires credentials but the user has those credentials.'); $user->removeCredential('c2'); $userMenu->setCredentials(array(array('c1', 'c2'))); $t->is($userMenu->checkUserAccess($user), true, '->checkUserAccess() supports the nesting of credentials to handle OR logic.'); $t->info(' 4.2 - Test actsLikeFirst(), actsLikeLast()'); $user->setAuthenticated(false); $userMenu = new ioMenuItemTest('user menu'); $t->info(' a) Create 3 normal children and as the actsLike methods on them'); $userMenu->addChild('ch1'); $userMenu->addChild('ch2'); $userMenu->addChild('ch3'); $t->is($userMenu['ch1']->actsLikeFirst(), true, '->actsLikeFirst() returns true for the first child.');