簡體   English   中英

Symfony 1.4 : 認證和未認證用戶的功能測試

[英]Symfony 1.4 : functional test for authenticated and unauthenticated users

我正在使用 Propel ORM 為 symfony 1.4.19 網站編寫一些功能測試。 我的一些頁面顯示不同,這取決於用戶是否登錄(經過身份驗證)。

我一直在看在線文檔,看看如何實現:

  1. 根據用戶是否登錄(經過身份驗證)或未登錄(視情況而定)運行的測試
  2. 作為功​​能測試的一部分,如何登錄或注銷用戶。

但是,我似乎找不到任何顯示如何執行此操作的內容。

登錄:

$username = 'root';
$password = 'root';

$browser->
  post('/login', array('signin' => array('username' => $username, 'password' => $password)))->
  with('request')->begin()->
    isParameter('module', 'sfGuardAuth')->
    isParameter('action', 'signin')->
  end()->
  with('response')->begin()->
    isStatusCode(302)->
    isRedirected()->
  end()->
  followRedirect()
;

登出:

$browser->
  get('/logout')->
  with('request')->begin()->
    isParameter('module', 'sfGuardAuth')->
    isParameter('action', 'signout')->
  end()->
  with('response')->begin()->
    isStatusCode(302)->
    isRedirected()->
  end()->
  followRedirect()
;

// this will reset session
$browser->restart();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM