使用Zend测试用户身份验证?

时间:2013-10-14 13:28:02

标签: php zend-framework

美好的一天,

我正在使用Zend测试用户身份验证,但现在我已登录,然后我再次注销它让我保持登录状态,因此我无法测试以确保它正常工作。

我用:

$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())

总是让我拥有身份并允许我查看资源。

是否可以在注销时清除缓存,会话或cookie,或者在不取消注释行等的情况下彻底进行测试。

由于

注销:

$auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity())
            $auth->clearIdentity();

        $this->_redirect('/');

1 个答案:

答案 0 :(得分:0)

我认为,$ auth-> clearIdentity();已经足够但是为了测试的结果让你的注销行动像这样,

 public function logoutAction() {
    Zend_Auth::getInstance()->clearIdentity();
    $storage = new Zend_Auth_Storage_Session();
    $storage->clear();
    $this->_helper->redirector('Action', 'Controller'); // back to main page
}