From 0d07af896b9d228780a064d6243ff4dec54a2f7a Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 6 May 2013 14:37:29 +0200 Subject: [PATCH] [BrowserKit] Pass headers when `followRedirect()` is called --- src/Symfony/Component/BrowserKit/Client.php | 2 +- .../Component/BrowserKit/Tests/ClientTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 8664f31ab0..c4dffdf77f 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -420,7 +420,7 @@ abstract class Client throw new \LogicException('The request was not redirected.'); } - return $this->request('get', $this->redirect); + return $this->request('get', $this->redirect, array(), array(), $this->history->current()->getServer()); } /** diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 1bf9e5c844..26616a8888 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -342,6 +342,33 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => 'bar'), $client->getRequest()->getCookies()); } + public function testFollowRedirectWithHeaders() + { + $headers = array( + 'HTTP_HOST' => 'www.example.com', + 'HTTP_USER_AGENT' => 'Symfony2 BrowserKit', + 'CONTENT_TYPE' => 'application/vnd.custom+xml', + 'HTTPS' => false, + ); + + $client = new TestClient(); + $client->followRedirects(false); + $client->setNextResponse(new Response('', 302, array( + 'Location' => 'http://www.example.com/redirected', + ))); + $client->request('GET', 'http://www.example.com/', array(), array(), array( + 'CONTENT_TYPE' => 'application/vnd.custom+xml', + )); + + $this->assertEquals($headers, $client->getRequest()->getServer()); + + $client->followRedirect(); + + $headers['HTTP_REFERER'] = 'http://www.example.com/'; + + $this->assertEquals($headers, $client->getRequest()->getServer()); + } + public function testBack() { $client = new TestClient();