user3731174
user3731174

Reputation:

CakePHP testAction returns null after redirect

I test a controller action. I pass data to it via the POST method. After saving a data into DB I do redirect to a main page where I display a message about of the action result.

I want to test whether a text of the message equal to expected, but I get a null instead of the $this->contents value.

Yet, all data saved and messages displayed successfully via the browser.

Below is my call of the testAction

 $res = $this->testAction('/ask', array_merge(array('return' => 'contents'), array('data' => $fields_data, 'method' => 'post')));

Upvotes: 0

Views: 169

Answers (1)

ndm
ndm

Reputation: 60463

testAction() doesn't follow redirects, simple as that.

You'll have to change your tests accordingly, and maybe test for whether Controller::redirect() is being invoked, that the response has the expected headers set, that the expected flash message has been set, etc.

And the other way around test the action where you are planning to redirect to separately by defining possible flash messages before invoking the action.

Upvotes: 1

Related Questions