diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 375daf2dbfe66..deff484debee2 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -303,6 +303,9 @@ public function request($method, $uri, array $parameters = array(), array $files $uri = $this->getAbsoluteUri($uri); + if (isset($server['HTTP_HOST'])) { + $uri = str_replace(parse_url($uri, PHP_URL_HOST), $server['HTTP_HOST'], $uri); + } $server = array_merge($this->server, $server); if (!$this->history->isEmpty()) { $server['HTTP_REFERER'] = $this->history->current()->getUri(); @@ -512,6 +515,8 @@ public function followRedirect() } $server = $request->getServer(); + $server = $this->updateServerFromUri($server, $this->redirect); + unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']); $this->isMainRequest = false; @@ -594,4 +599,12 @@ protected function requestFromRequest(Request $request, $changeHistory = true) { return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory); } + + private function updateServerFromUri($server, $uri) + { + $server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST); + $server['HTTPS'] = parse_url($uri, PHP_URL_SCHEME); + + return $server; + } } diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 853106a2234ea..065856ab7bf0a 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -390,13 +390,11 @@ public function testFollowRedirectWithMaxRedirects() $client->setNextResponse(new Response('', 302, array('Location' => '/redirected'))); $client->request('GET', 'http://www.example.com/foo/foobar'); - $this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows relative URLs'); $client = new TestClient(); $client->setNextResponse(new Response('', 302, array('Location' => '//www.example.org/'))); $client->request('GET', 'https://www.example.com/'); - $this->assertEquals('https://www.example.org/', $client->getRequest()->getUri(), '->followRedirect() follows protocol-relative URLs'); $client = new TestClient(); @@ -562,4 +560,30 @@ public function testSetServerParameter() $client->setServerParameter('HTTP_USER_AGENT', 'testua'); $this->assertEquals('testua', $client->getServerParameter('HTTP_USER_AGENT')); } + + public function testSetServerParameterInRequest() + { + $client = new TestClient(); + + $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST')); + $this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT')); + + $client->request('GET', 'http://www.example.com/foo', array(), array(), array( + 'HTTP_HOST' => 'testhost', + 'HTTP_USER_AGENT' => 'testua', + 'NEW_SERVER_KEY' => 'new-server-key-value' + )); + + $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST')); + $this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT')); + + $this->assertEquals('http://testhost/foo', $client->getRequest()->getUri()); + $server = $client->getRequest()->getServer(); + $this->assertArrayHasKey('HTTP_USER_AGENT', $server); + $this->assertEquals('testua', $server['HTTP_USER_AGENT']); + $this->assertArrayHasKey('HTTP_HOST', $server); + $this->assertEquals('testhost', $server['HTTP_HOST']); + $this->assertArrayHasKey('NEW_SERVER_KEY', $server); + $this->assertEquals('new-server-key-value', $server['NEW_SERVER_KEY']); + } } diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 0f09c093320f1..9b11d5af0a403 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -58,6 +58,8 @@ public function formatCurrencyWithDecimalStyleProvider() */ public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected) { + IntlTestHelper::requireFullIntl($this); + $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $this->assertEquals($expected, $formatter->formatCurrency($value, $currency)); } @@ -84,6 +86,8 @@ public function formatCurrencyWithCurrencyStyleProvider() */ public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($value, $currency, $symbol, $expected) { + IntlTestHelper::requireFullIntl($this); + $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); } @@ -102,6 +106,8 @@ public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider( */ public function testFormatCurrencyWithCurrencyStyleBrazilianRealRounding($value, $currency, $symbol, $expected) { + IntlTestHelper::requireFullIntl($this); + $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); } @@ -129,6 +135,8 @@ public function formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider() */ public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $currency, $symbol, $expected) { + IntlTestHelper::requireFullIntl($this); + $formatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY); $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); }