2013-10-14 60 views
0

美好的一天,使用Zend測試用戶身份驗證?

我使用Zend測試用戶身份驗證,但現在我已登錄,然後再次註銷它使我登錄,因此我無法測試以確保它正常工作。

我用:

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

它總是讓我爲具有身份,讓我來查看該資源。

是否有可能清除註銷緩存,會話或餅乾,或去徹底測試,而不取消對線等

感謝的方式

註銷:

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

     $this->_redirect('/'); 
+0

顯示註銷plz的代碼。 –

+0

好吧,我已經更新了 – surfer190

+1

'$ auth-> clearIdentity();'就夠了。但僅僅爲了測試,還包括'Zend_Session :: destroy();'並再次測試。 –

回答

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 
}