User Tools

Site Tools


php:testguard

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

php:testguard [2013/03/16 17:40] (current)
Line 1: Line 1:
 +==== Functional test behind sfGuardDoctrinePlugin ====
 +03.02.2010
 +
 +
 +If you implemented sfGuardDoctrinePlugin in your application,​ it's likely you'd get this when you try to run functional tests:
 +
 +<​code>​
 +not ok 3 - status code is 200
 +#     ​Failed test (./​lib/​vendor/​symfony/​lib/​test/​sfTesterResponse.class.php at line 398)
 +#            got: 401
 +#       ​expected:​ 200
 +</​code>​
 +
 +That's because in functional test you have 
 +
 +<code php>​$browser = new sfTestFunctional(new sfBrowser());</​code>​
 +
 +**Solution: create an extended class to sfTestFunctional.**
 +
 +<code php | /​lib/​sfGuardTestFunctional.php>​
 +<?​php ​
 +// lib/​sfGuardTestFunctional.php
 +class sfGuardTestFunctional extends sfTestFunctional {  ​
 +    public function signin($username = '​admin',​ $password = '​admin',​ $click = 'sign in', $signin_url = '/​login',​ $nameFormat = '​signin'​) {
 +        return $this->​get($signin_url)
 +            ->​click($click,​ array($nameFormat => array('​username'​ => $username,'​password'​ => $password)));​
 +    }
 +}
 +</​code>​
 +
 +and modify the test:
 +
 +<code php>
 +$browser = new sfGuardTestFunctional(new sfBrowser());​
 +
 +$browser
 +    ->​get('/​foo/​bar'​)
 +    ->​signin($username,​ $password)
 +    ->​get('/​foo/​bar'​)
 +    ->​with('​request'​)->​begin()->​
 +        isParameter('​module',​ '​foo'​)->​
 +        isParameter('​action',​ '​bar'​)->​
 +    end()
 +    ​
 +</​code>​
  
php/testguard.txt ยท Last modified: 2013/03/16 17:40 (external edit)