this is the _test log .. as you can see the user is authenticated in
the first sfBrowser request, but the second sfBrowser request
redirects to login

// first request
  .. buch of stuff leading up to the login call
Jan 30 16:07:21 symfony [info] {customerActions} Call "customerActions-
>executeLogin()"
Jan 30 16:07:21 symfony [info] {customerActions} Call "customerActions-
>executeLogin()"
Jan 30 16:07:21 symfony [info] {GwSessionCustomer} User is
authenticated
Jan 30 16:07:21 symfony [info] {GwSessionCustomer} User is
authenticated
Jan 30 16:07:21 symfony [info] {gwFrontWebController} Redirect to
"http://localhost/index.php/";
Jan 30 16:07:21 symfony [info] {gwFrontWebController} Redirect to
"http://localhost/index.php/";
Jan 30 16:07:21 symfony [info] {sfWebResponse} Send content (98 o)
Jan 30 16:07:21 symfony [info] {sfWebResponse} Send content (98 o)

// second request
Jan 30 16:07:22 symfony [info] {sfPatternRouting} Connect sfRoute
"overview_blank" (/)
 .. a bunch of routing connects ..
Jan 30 16:07:22 symfony [info] {sfPatternRouting} Connect sfRoute
"default" (/:module/:action/*)
Jan 30 16:07:22 symfony [info] {sfPatternRouting} Match route
"default" (/:module/:action/*) for /emCpOutOfOfficeAutoReplies/index
with parameters array (  'module' => 'emCpOutOfOfficeAutoReplies',
'action' => 'index',)
Jan 30 16:07:22 symfony [info] {sfFilterChain} Executing filter
"sfFakeRenderingFilter"
Jan 30 16:07:22 symfony [info] {sfFilterChain} Executing filter
"sfBasicSecurityFilter"
Jan 30 16:07:22 symfony [info] {sfFilterChain} Executing filter
"sfFakeRenderingFilter"
Jan 30 16:07:22 symfony [info] {sfFilterChain} Executing filter
"sfCommonFilter"
Jan 30 16:07:22 symfony [info] {sfFilterChain} Executing filter
"sfValidationExecutionFilter"
Jan 30 16:07:22 symfony [info] {customerActions} Call "customerActions-
>executeLogin()"
Jan 30 16:07:22 symfony [info] {sfPHPView} Render "/home/daniel/www/
gradwell_sf/trunk/plugins/gwCorePlugin/modules/customer/templates/
loginSuccess.php"
Jan 30 16:07:22 symfony [info] {sfPHPView} Decorate content with "/
home/daniel/www/gradwell_sf/trunk/plugins/gwCorePlugin/modules/
customer/templates/layout.php"
Jan 30 16:07:22 symfony [info] {sfPHPView} Render "/home/daniel/www/
gradwell_sf/trunk/plugins/gwCorePlugin/modules/customer/templates/
layout.php"
Jan 30 16:07:22 symfony [info] {main} Call "default->executeHeader()"
Jan 30 16:07:22 symfony [info] {sfPartialView} Render "/home/daniel/
www/gradwell_sf/trunk/plugins/gwCorePlugin/modules/default/templates/
_header.php"
Jan 30 16:07:22 symfony [info] {sfPartialView} Render "/home/daniel/
www/gradwell_sf/trunk/plugins/gwCorePlugin/modules/default/templates/
_cpHeader.php"
Jan 30 16:07:22 symfony [info] {main} Call "default->executeCpFooter
()"
Jan 30 16:07:22 symfony [info] {sfPartialView} Render "/home/daniel/
www/gradwell_sf/trunk/plugins/gwCorePlugin/modules/default/templates/
_cpFooter.php"
Jan 30 16:07:22 symfony [info] {sfWebResponse} Send content (3332 o)

Im tempted to think that its some kind of session storage issue, but
cant imagine why ..

On 30 Jan, 15:39, Jérôme TEXIER <[email protected]> wrote:
> 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