Sorry, but looks hard to debug your app from here.

Did you check your log files log/<your_app>_test.log ?

On 30 jan, 14:19, dantleech <[email protected]> wrote:
> using the following:
>
>   public function loginOk()
>   {
>     $this
>       -> post('customer/login', array('email' => '[email protected]',
> 'password' => 'wibble', 'test' => 'emCpOverview', 'redirect_action' =>
> 'index'));
>       -> isRedirected()
>       -> followRedirect();
>
>     return $this;
>   }
>
> I get the following :
>
>  http://www.dantleech.com/data/functionaltestfail.png
>
> Note the red block and the missing assertion, the login actions
> redirect throws an sfStopException which prevents further code
> execution
>
> If I surround the [->post] with try and catch:
>
>     try
>     {
>       $this -> post('/customer/login', array('email' =>
> '[email protected]', 'password' => 'wibble'));
>     }
>     catch (sfStopException $e)
>     {
>     }
>
> I am 'redirected' but everything seems very odd, and I am not logged
> in for my next request:
>
>  http://www.dantleech.com/data/functionaltestfail2.png
>
> I am authenticated in BEFORE I send the [->get] but not during or
> after.. I also have to wrap the [->get] in try and catch for further
> tests to run ..
>
> Any help much appreciated :) I have been trying to get this to work
> for a while now ...
>
> On 29 Jan, 13:51, Jérôme TEXIER <[email protected]> wrote:
>
> > On symfony 1.0 & 1.1, redirection can be followed this way :
> > $browser->
> > ...
> > isRedirected()->
> > followRedirect()->
> > ...
>
> > Also, more info on functional tests refactoring here 
> > :http://www.symfony-project.org/blog/2008/09/19/call-the-expert-a-refa...
>
> > Jérôme
>
> > On 28 jan, 12:58, dantleech <[email protected]> wrote:
>
> > > thanks Jerome
>
> > > I am doing something similar, though our project started life off with
> > > sf1.0 so the login page doesnt use the form framework.
>
> > > ------ test browser
> > > class emTestBrowser extends sfTestFunctional
> > > {
> > >   public function loadData()
> > >   {
> > >     // load fixtures..
> > >   }
> > >   public function loginOk()
> > >   {
> > >     $this -> post('/customer/login', array('email' =>
> > > '[email protected]', 'password' => 'wibble');
> > >     $this -> isRedirected();
>
> > >     return $this;
> > >   }
>
> > > }
>
> > > -------- test
> > > $browser = new emTestBrowser(new sfBrowser());
> > > $browser -> initialize();
> > > $browser -> loadData();
> > > $browser -> loginOk();
>
> > > $browser->
> > >   get('/someModule/index')->
> > >   isStatusCode(200)->
> > >   isRequestParameter('module', 'someModule')->
> > >   isRequestParameter('action', 'index')->
> > >   isRequestParameter('mailbox_id', 1)->
> > >   checkResponseElement('body', 'Something')->
> > >   end();
>
> > > ----------------
>
> > > The problem is that we do not get as far as the first assertion in
> > > emTestBrowser::loginOk. The login code calls [->redirect] and that
> > > throws an sfStopException which, err, stops everything. If I remove
> > > the redirect from the login code then the tests proceed as expected. I
> > > know I must be missing something here otherwise assertions such as [-
>
> > > >isRedirected] would be pretty pointless :)
>
> > > On 28 Jan, 09:34, Jérôme TEXIER <[email protected]> wrote:
>
> > > > Did you try to use the specific sfTesterUser to check the state of the
> > > > your user :
>
> > > > with('user')->begin()->
> > > >  isAuthenticated()->
> > > > end()
>
> > > > One good point dealing with signin/signout operations on functional
> > > > test is to write a reusable class for those kind of test, something
> > > > like :
>
> > > > class sfGuardTestFunctional extends sfTestFunctional {
> > > >   public function signinOk($user_data)
> > > >   {
> > > >     return $this->
> > > >       info(sprintf('Connexion with login : "%s" and password "%s"
> > > > should be ok OK.', $user_data['username'], $user_data['password']))->
> > > >       get('/login')->
> > > >       click('login',array('signin'=>$user_data))->
>
> > > >       with('form')->begin()->
> > > >         hasErrors(false)->
> > > >       end()->
>
> > > >       with('user')->begin()->
> > > >         isCulture('en')->
> > > >         isAuthenticated(true)->
> > > >       end()->
>
> > > >       with('request')->begin()->
> > > >         isParameter('module', 'sfGuardAuth')->
> > > >         isParameter('action', 'signin')->
> > > >       end()->
>
> > > >       isRedirected();
> > > >   }
> > > >   //could add signout, signinError methods here
> > > > ?>
>
> > > > So on your fonctional test, you can use the signin test :
>
> > > > $browser = new sfGuardTestFunctional(new sfBrowser()); //rather than
> > > > $browser = new sfTestFunctional(new sfBrowser())
> > > > $browser->signinOk(array('username'=>'foo','password'=>'bar'));
>
> > > > Regards.
>
> > > > Jérôme
>
> > > > On 27 jan, 15:00, dantleech <[email protected]> wrote:
>
> > > > > cheers alecs
>
> > > > > though im not sure that your examples addresses my problem of
> > > > > authenticating the user before function testing a page ... what I
> > > > > meant by sfContext::getUser() was
>
> > > > > <?php
> > > > >   $user = sfContext::getInstance() -> getUser();
> > > > >   $user -> login($user_object);
>
> > > > > On 27 Jan, 13:00, Lupu Alexandru-Emil <[email protected]> wrote:
>
> > > > > > On Tue, Jan 27, 2009 at 1:17 PM, dantleech <[email protected]> 
> > > > > > wrote:
>
> > > > > > > I am trying to write functional tests for an authenticated
> > > > > > > application, but every time I authenticate the user it seems that 
> > > > > > > the
> > > > > > > users state is reset every time,
>
> > > > > > >  i.e. the next [-> get] doesn't seem to recognize the fact that I
> > > > > > > have previously authenticated the user and when running the test I
> > > > > > > receive the login HTML rather than the page I want to test
>
> > > > > > > I have tried both authenticating the user using 
> > > > > > > sfContext::getUser()
> > > > > > > and logging in manually by using:
>
> > > > > > > $sf_test_functional -> post('/user_plugin_module/login', 
> > > > > > > array('email'
> > > > > > > => '[email protected]', 'password' => 'blah');
>
> > > > > > > and the dev log seems to suggest that the user was indeed logged 
> > > > > > > in,
> > > > > > > but the subsequent request redirects to the login page anyway ..
>
> > > > > > > cheers
>
> > > > > > > dan
>
> > > > > > Hi!
> > > > > > before you call "sfContext::getUser()" each time, you could try
> > > > > > <?php
>
> > > > > > $my_test_user = sfContext::getUser();
> > > > > > $my_test_user->getFOO();
> > > > > > ....
> > > > > > ?>
> > > > > > Also you might wanna try :
> > > > > > <?php
> > > > > > $context = sfContext::getInstance();
> > > > > > $my_test_user = $context->getUser();
> > > > > > $my_test_user->getFOO();
> > > > > > ....
> > > > > > ?>
>
> > > > > > Alecs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to