8000 feature: transform both switchToXHR and removeXhr to a xhrRequest · symfony/symfony@cbdfa5d · GitHub
[go: up one dir, main page]

Skip to content

Commit cbdfa5d

Browse files
author
Amrouche Hamza
committed
feature: transform both switchToXHR and removeXhr to a xhrRequest
1 parent a8dc953 commit cbdfa5d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,20 @@ public function getServerParameter($key, $default = '')
150150
return isset($this->server[$key]) ? $this->server[$key] : $default;
151151
}
152152

153-
public function switchToXHR()
153+
/**
154+
* Calls a URI with XMLHttpRequest.
155+
*
156+
* @return Crawler
157+
*/
158+
public function xhrRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)
154159
{
155160
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
156-
}
157161

158-
public function removeXHR()
159-
{
160-
unset($this->server['HTTP_X_REQUESTED_WITH']);
162+
try {
163+
return $this->request($method, $uri, $parameters, $files, $server, $content, $changeHistory);
164+
} finally {
165+
unset($this->server['HTTP_X_REQUESTED_WITH']);
166+
}
161167
}
162168

163169
/**

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ public function testGetRequest()
9797
public function testGetRequestWithXHR()
9898
{
9999
$client = new TestClient();
100-
$client->switchToXHR();
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->removeXHR();
100+
$client->xhrRequest('GET', 'http://example.com/', array(), array(), array(), null, true);
104101
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
105102
}
106103

0 commit comments

Comments
 (0)
0