[BrowserKit] Allow Referer set by history to be overridden (3.4)

This commit is contained in:
Filippo Tessarotto 2020-04-27 08:55:12 +02:00
parent 048e6f3dd8
commit 4774946fbd
2 changed files with 10 additions and 1 deletions

View File

@ -294,7 +294,7 @@ abstract class Client
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}
if (!$this->history->isEmpty()) {
if (!isset($server['HTTP_REFERER']) && !$this->history->isEmpty()) {
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}

View File

@ -233,6 +233,15 @@ class ClientTest extends TestCase
$this->assertEquals('http://www.example.com/foo/foobar', $server['HTTP_REFERER'], '->request() sets the referer');
}
public function testRequestRefererCanBeOverridden()
{
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'bar', [], [], ['HTTP_REFERER' => 'xyz']);
$server = $client->getRequest()->getServer();
$this->assertEquals('xyz', $server['HTTP_REFERER'], '->request() allows referer to be overridden');
}
public function testRequestHistory()
{
$client = new TestClient();