xmlHttpRequest example

$response = $this->request('GET', '/wishlist', []);
        static::assertEquals(200, $response->getStatusCode());

        $traces = $this->getContainer()->get(ScriptTraces::class)->getTraces();

        static::assertArrayHasKey(GuestWishlistPageLoadedHook::HOOK_NAME, $traces);
    }

    public function testGuestWishlistPageletLoadedHookScriptsAreExecuted(): void
    {
        $browser = $this->registerAsGuest();
        $browser->xmlHttpRequest(
            'POST',
            $_SERVER['APP_URL'] . '/wishlist/guest-pagelet'
        );
        $response = $browser->getResponse();

        static::assertEquals(200, $response->getStatusCode());

        $traces = $this->getContainer()->get(ScriptTraces::class)->getTraces();

        static::assertArrayHasKey(GuestWishlistPageletLoadedHook::HOOK_NAME, $traces);
    }

    

        $client = $this->createSalesChannelBrowser(null, true);
        $client->request('GET', 'http://localhost/');

        static::assertEquals(200, $client->getResponse()->getStatusCode());
    }

    public function testAccessDeniedForXmlHttpRequest(): void
    {
        $client = $this->createSalesChannelBrowser(null, true);

        $client->xmlHttpRequest('GET', 'http://localhost/');

        static::assertEquals(403, $client->getResponse()->getStatusCode());
    }

    public function testPageletLoads(): void
    {
        $client = $this->createSalesChannelBrowser(null, true);

        $client->request('GET', 'http://localhost/checkout/offcanvas');

        static::assertEquals(200, $client->getResponse()->getStatusCode());
    }

        $this->expectException(BadMethodCallException::class);
        $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getRequest()".');

        $client = $this->getBrowser();
        $this->assertNull($client->getRequest());
    }

    public function testXmlHttpRequest()
    {
        $client = $this->getBrowser();
        $client->xmlHttpRequest('GET', 'http://example.com/', [][][], null, true);
        $this->assertSame('XMLHttpRequest', $client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH']);
        $this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
    }

    public function testJsonRequest()
    {
        $client = $this->getBrowser();
        $client->jsonRequest('GET', 'http://example.com/', ['param' => 1][], true);
        $this->assertSame('application/json', $client->getRequest()->getServer()['CONTENT_TYPE']);
        $this->assertSame('application/json', $client->getRequest()->getServer()['HTTP_ACCEPT']);
        $this->assertFalse($client->getServerParameter('CONTENT_TYPE', false));
        
Home | Imprint | This part of the site doesn't use cookies.