[BrowserKit] add a way to switch to ajax for one request

This commit is contained in:
Amrouche Hamza 2017-11-01 07:23:32 +01:00
parent b0facfec01
commit a10eae7d9e
No known key found for this signature in database
GPG Key ID: 6968F2785ED4F012
2 changed files with 20 additions and 0 deletions

View File

@ -150,6 +150,16 @@ abstract class Client
return isset($this->server[$key]) ? $this->server[$key] : $default;
}
public function switchToXHR()
{
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
}
public function removeXHR()
{
unset($this->server['HTTP_X_REQUESTED_WITH']);
}
/**
* Returns the History instance.
*

View File

@ -94,6 +94,16 @@ class ClientTest extends TestCase
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
}
public function testGetRequestWithXHR()
{
$client = new TestClient();
$client->switchToXHR();
$client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true);
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
$client->removeXHR();
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
}
public function testGetRequestWithIpAsHttpHost()
{
$client = new TestClient();