Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1a3bf19

Browse filesBrowse files
author
Amrouche Hamza
committed
[BrowserKit] add a way to switch to ajax for one request
1 parent b0facfe commit 1a3bf19
Copy full SHA for 1a3bf19

File tree

2 files changed

+21
-1
lines changed
Filter options

2 files changed

+21
-1
lines changed

‎src/Symfony/Component/BrowserKit/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Client.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public function getServerParameter($key, $default = '')
150150
return isset($this->server[$key]) ? $this->server[$key] : $default;
151151
}
152152

153+
public function switchToXMLHttpRequest()
154+
{
155+
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
156+
}
157+
158+
public function removeXMLHttpRequestHeader()
159+
{
160+
unset($this->server['HTTP_X_REQUESTED_WITH']);
161+
}
162+
153163
/**
154164
* Returns the History instance.
155165
*
@@ -256,7 +266,7 @@ public function submit(Form $form, array $values = array())
256266
{
257267
$form->setValues($values);
258268

259-
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles());
269+
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), array(), null, true);
260270
}
261271

262272
/**

‎src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Tests/ClientTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public function testGetRequest()
9494
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
9595
}
9696

97+
public function testGetRequestWithXMLHttpRequest()
98+
{
99+
$client = new TestClient();
100+
$client->switchToXMLHttpRequest();
101+
$client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true);
102+
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
103+
$client->removeXMLHttpRequestHeader();
104+
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
105+
}
106+
97107
public function testGetRequestWithIpAsHttpHost()
98108
{
99109
$client = new TestClient();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.