I am testing a controller action in CakePHP that redirects to
different URL depending on certain conditions:

if ( !$userIsAdmin ) {
  $this->Session->setFlash(__('Not allowed.'));
  $this->redirect('/users');
}

if ( $this->MyModel->delete($id) ) {
  $this->Session->setFlash(__('Success.'));
  $this->redirect('/users');
}
else {
  $this->Session->setFlash(__('Failed. Please, try again.'));
  $this->redirect("/my_models/edit/$id");
}

The problem is that redirect(...) does not actually redirect when
doing unit tests since it's a mocked method.

So when I try to assert $this->headers to compare with the expected
URL it fails because the last URL tracked is the one in the last
redirect() call that gets executed.

Is there any way to avoid that?

Thanks!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to