Can the testAction CakePHP method survive redirects?

I am starting to write unit tests using the CakePHP and SimpleTest platforms. The documentation describes the problem with the testAction method when your controller redirects the browser to another page. There is a reliable note with a link to a possible fix , but the link is broken.

Has anyone got this job? Know how to find where the specified broken link should be?

I found a discussion on using partial piece objects to override the redirect call, but this does not seem to work with the testAction method. I suspect that I need to somehow register the controller with the dispatcher.

Here's a similar question in Google Groups .

0
source share
1 answer

I have something to work with, so I thought I'd post it here. I am not sure if I am still satisfied with this.

If you want to check the redirection, change this:

$this->redirect(array('action'=>'index'));

:

$this->redirect(array('action'=>'index'), null, false);
return 'redirected to index';

Now your test might look something like this:

$data = array(...);
$result = $this->testAction(
    '/people/edit/1',
    array('method' => 'post', 'data' => $data));
$this->assertEqual(
    'redirected to index',
    $result);

, exit() . false $exit , return exit(). - - , , , . , .

, , , return exit(). , .

+1

All Articles