Skip to content

Testing ajax header problems #3246

Description

@luispastendev

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions