Skip to content

Transform both switchToXHR() and removeXhr() to xmlHttpRequest() #26381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
feature: transform both switchToXHR and removeXhr to a xhrRequest
  • Loading branch information
Amrouche Hamza committed Mar 20, 2018
commit 4ed08896fa35adb05379eebfb51b334a40bebc2e
11 changes: 6 additions & 5 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ public function getServerParameter($key, $default = '')
return isset($this->server[$key]) ? $this->server[$key] : $default;
}

public function switchToXHR()
public function xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true): Crawler
{
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
}

public function removeXHR()
{
unset($this->server['HTTP_X_REQUESTED_WITH']);
try {
return $this->request($method, $uri, $parameters, $files, $server, $content, $changeHistory);
} finally {
unset($this->server['HTTP_X_REQUESTED_WITH']);
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ public function testGetRequestNull()
$this->assertNull($client->getRequest());
}

public function testGetRequestWithXHR()
public function testXmlHttpRequest()
{
$client = new TestClient();
$client->switchToXHR();
$client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true);
$client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true);
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
$client->removeXHR();
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
}

Expand Down