$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);
$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->is(array_keys($menu->getChildren()), array('Temp name', 'Parent 2'), 'The children are still ordered correctly after a rename.');
$pt1->setName("Parent 1");
$t->is($menu->getChild("Parent 1", false), $pt1, "pt1 can be found again under old name");
$t->info('    Trying renaming Parent 1 to Parent 2 (which already is used by sibling), should throw an exception.');
try {
    $pt1->setName("Parent 2");
    $t->fail('Exception not thrown.');
} catch (sfException $e) {
    $t->pass('Exception thrown');
}
$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');