Symfony sfGuardAuth Functional Testing

sfGuardTestFunctional class under /lib

class sfGuardTestFunctional extends sfTestFunctional
{
public function signin($username, $password)
{
return $this->
info(
sprintf('Signin user using username "%s" and password "%s"', $username, $password))->
click(
'Signin', array('signin' => array('username' => $username, 'password'=>$password)))
//with('form')->debug()->
;
}
}

the test file is

<?php

include(dirname(__FILE__).'/http://www.cnblogs.com/bootstrap/functional.php');

$browser = new sfGuardTestFunctional(new sfBrowser());

$username = 'xming';
$password = 'xming';

$browser->
get(
'/login')->
info(
'Culture :'.$browser->getUser()->getCulture())->
with(
'request')->begin()->
isParameter(
'module', 'sfGuardAuth')->
isParameter(
'action', 'signin')->
end()->

get(
'/login')->
with(
'response')->begin()->
isStatusCode(
401)->
end()->
signin(
$username, $password)->
with(
'response')->begin()->
checkElement(
'ul.error_list', false)->
isStatusCode(
302)->
isRedirected()
->
info(
"status code :".$browser->getResponse()->getStatusCode())->
end()->

get(
'/login')->
with(
'response')->begin()->
isStatusCode(
302)->
end()
;

posted @ 2011-08-26 18:14  Lux.Y  阅读(420)  评论(0)    收藏  举报