示例#1
0
        $this->sessionId = rand(1, 9999);
        return true;
    }
}
$dispatcher = new sfEventDispatcher();
$sessionPath = sys_get_temp_dir() . '/sessions_' . rand(11111, 99999);
$storage = new MySessionStorage(array('session_path' => $sessionPath));
$user = new sfBasicSecurityUser($dispatcher, $storage);
// ->initialize()
$t->diag('->initialize()');
$t->todo('->initialize() times out the user if no request made for a long time');
// ->getCredentials()
$t->diag('->getCredentials()');
$user->clearCredentials();
$user->addCredential('user');
$t->is($user->getCredentials(), array('user'), '->getCredentials() returns user credentials as an array');
// ->setAuthenticated() ->isAuthenticated()
$t->diag('->setAuthenticated() ->isAuthenticated()');
$t->is($user->isAuthenticated(), false, '->isAuthenticated() returns false by default');
$user->setAuthenticated(true);
$t->is($user->isAuthenticated(), true, '->isAuthenticated() returns true if the user is authenticated');
$user->setAuthenticated(false);
$t->is($user->isAuthenticated(), false, '->setAuthenticated() accepts a boolean as its first parameter');
// session id regeneration
$user->setAuthenticated(false);
$id = $storage->getSessionId();
$user->setAuthenticated(true);
$t->isnt($id, $id = $storage->getSessionId(), '->setAuthenticated() regenerates the session id if the authentication changes');
$user->setAuthenticated(true);
$t->is($storage->getSessionId(), $id, '->setAuthenticated() does not regenerate the session id if the authentication does not change');
$user->addCredential('foo');