Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing ajax header problems #3246

Closed
luispastendev opened this issue Jul 8, 2020 · 1 comment
Closed

Testing ajax header problems #3246

luispastendev opened this issue Jul 8, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@luispastendev
Copy link

luispastendev commented Jul 8, 2020

Hi!

I am trying to test by generating a request, my controller is verifying with the isAJAX() method

if($this->request->isAJAX())
    ......

The problem is that when I put it that way the test fails.

$request->appendHeader('X-Requested-With','XMLHttpRequest');
$request->setMethod('post');
$request->setGlobal('post', [ ... ]);
$result = $this->withRequest($request)
                        ->controller(Foo::class)
                        ->execute('FooMethod');

I have looked into the code of IncomingRequest and
I see that it verifies that the variable $ _SERVER ['HTTP_X_REQUESTED_WITH'] is equal to xmlhttprequest therefore my test was only valid adding the variable directly

$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';

I think the setHeader() function should be enough to configure an ajax request but for some reason it is not succeeding.

Thanks for everything!

@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 10, 2020
@luispastendev
Copy link
Author

@michalsn thankyou bro!! ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants