Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public function getServerParameter($key, $default = '')
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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public function testGetRequest()
$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();
Expand Down