php - Setting headers for CakePHP Controller unit tests -


I am writing some unit tests for an administrator whose reaction behavior is slightly different, depending on whether < Code> $ this - & gt; Request & gt; ('Ajax') . I see, but I can not find any way to emulate the request made through AJX.

How to send the header to testAction () so I can set with the x-requested headers?

Edit: You can work around it by editing superGlobal. Does anyone have a less hacking solution?

A test is to declare manually for the duration of the required environment variables: your test:

  $ _ ENV ['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; // run your AJAX test ... unset ($ _ ENV ['HTTP_X_REQUESTED_WITH']);    

Comments