feature: transform both switchToXHR and removeXhr to a xhrRequest
This commit is contained in:
parent
6059bdc80e
commit
4ed08896fa
@ -151,15 +151,16 @@ abstract class Client
|
|||||||
return isset($this->server[$key]) ? $this->server[$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');
|
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
|
||||||
}
|
|
||||||
|
|
||||||
public function removeXHR()
|
try {
|
||||||
{
|
return $this->request($method, $uri, $parameters, $files, $server, $content, $changeHistory);
|
||||||
|
} finally {
|
||||||
unset($this->server['HTTP_X_REQUESTED_WITH']);
|
unset($this->server['HTTP_X_REQUESTED_WITH']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the History instance.
|
* Returns the History instance.
|
||||||
|
@ -104,13 +104,11 @@ class ClientTest extends TestCase
|
|||||||
$this->assertNull($client->getRequest());
|
$this->assertNull($client->getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRequestWithXHR()
|
public function testXmlHttpRequest()
|
||||||
{
|
{
|
||||||
$client = new TestClient();
|
$client = new TestClient();
|
||||||
$client->switchToXHR();
|
$client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true);
|
||||||
$client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true);
|
|
||||||
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
|
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
|
||||||
$client->removeXHR();
|
|
||||||
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
|
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user