User Login Symfony 1.4 Functional Test


/ Published in: PHP
Save to your folder(s)

This is a basic example from a Symfony 1.4 project on how to simulate a user login. It involves just starting the test with a click() action on the default page.


Copy this code and paste it in your HTML
  1. // First, place this in your functional bootstrap file
  2. // (optional, but helps keep things organized)
  3.  
  4. sfConfig::set('FUNC_ADMIN_USER', 'admin');
  5. sfConfig::set('FUNC_ADMIN_PASS', 'admin');
  6.  
  7. // In the functional test, this line logs in a user using vars from the bootstrap file
  8. // It first logs in a user, then checks that the user has access to the page we are testing
  9.  
  10. $browser->
  11.  
  12. // go to login page
  13. get('/appointments')->
  14.  
  15. // make sure we did not get access
  16. with('response')->begin()->
  17. isStatusCode(401)->
  18. end()->
  19.  
  20. // log in
  21. with('form')->begin()->
  22. click('sign in', array(
  23. 'signin' => array(
  24. 'username' => sfConfig::get('FUNC_ADMIN_USER'),
  25. 'password' => sfConfig::get('FUNC_ADMIN_PASS'))))->
  26. end()->
  27.  
  28. // try again to access the appointment page (should have been block the first time
  29. get('/appointments')->
  30.  
  31. // make sure we have access now
  32. with('response')->begin()->
  33. isStatusCode(200)->
  34. end()
  35. ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.