views:

37

answers:

1

I am writing a functional test for a page that requires user authentication. I am using the sfDoctrineGuard plugin.

How do I authenticate a user in my test?

Do I have to enter every test through the sign in screen?

Here is my incorrect code:

$b->post('/sfGuardAuth/signin',
       array('signin[password]' => 'password',
             'signin[username]' => 'user',
             'signin[_csrf_token]' => '7bd809388ed8bf763fc5fccc255d042e'))->
       with('response')->begin()->
         checkElement('h2', 'Welcome Humans')->
       end()

Thank you

+1  A: 

Yes, you do have to sign in to carry out tests. Fortunately, this is much simpler than the method you illustrate above. See the "better and simpler way" on this blog post.

You could make the signin method part of any TestFunctional class according to how you've structured your tests.

lonesomeday