/ Published in: PHP
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// First, place this in your functional bootstrap file // (optional, but helps keep things organized) sfConfig::set('FUNC_ADMIN_USER', 'admin'); sfConfig::set('FUNC_ADMIN_PASS', 'admin'); // In the functional test, this line logs in a user using vars from the bootstrap file // It first logs in a user, then checks that the user has access to the page we are testing $browser-> // go to login page get('/appointments')-> // make sure we did not get access with('response')->begin()-> isStatusCode(401)-> // log in with('form')->begin()-> 'username' => sfConfig::get('FUNC_ADMIN_USER'), 'password' => sfConfig::get('FUNC_ADMIN_PASS'))))-> // try again to access the appointment page (should have been block the first time get('/appointments')-> // make sure we have access now with('response')->begin()-> isStatusCode(200)-> ;