Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  [Console] Application update PHPDoc of add and register methods
  [Config] Extra tests for Config component
  Fixed bugs in names of classes and methods.
  [DoctrineBridge] Fixed php doc
  [FrameworkBundle] Fixed parameters number mismatch declaration
  [BrowserKit] Added test for followRedirect method (POST method)
  Fix the money form type render with Bootstrap3
  [BrowserKit] Uppercase the "GET" method in redirects
  [DomCrawler] Inherit the namespace cache in subcrawlers
  [WebProfilerBundle] Fixed  JSDoc parameter definition
  [HttpFoundation] HttpCache refresh stale responses containing an ETag

Conflicts:
	src/Symfony/Component/Console/Application.php
  • Loading branch information
nicolas-grekas committed Jul 26, 2016
2 parents 9067044 + d2a07cc commit 014c0d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Client.php
Expand Up @@ -475,7 +475,7 @@ public function followRedirect()
$request = $this->internalRequest;

if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
$method = 'get';
$method = 'GET';
$files = array();
$content = null;
} else {
Expand All @@ -484,7 +484,7 @@ public function followRedirect()
$content = $request->getContent();
}

if ('get' === strtolower($method)) {
if ('GET' === strtoupper($method)) {
// Don't forward parameters for GET request as it should reach the redirection URI
$parameters = array();
} else {
Expand Down
22 changes: 21 additions & 1 deletion Tests/ClientTest.php
Expand Up @@ -410,7 +410,7 @@ public function testFollowRedirectWithMaxRedirects()
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));

$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
$this->assertEquals('GET', $client->getRequest()->getMethod(), '->followRedirect() uses a GET for 302');
$this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
}

Expand Down Expand Up @@ -489,6 +489,26 @@ public function testGetMaxRedirects()
$this->assertEquals(3, $client->getMaxRedirects(), '->getMaxRedirects() returns assigned value');
}

public function testFollowRedirectWithPostMethod()
{
$parameters = array('foo' => 'bar');
$files = array('myfile.foo' => 'baz');
$server = array('X_TEST_FOO' => 'bazbar');
$content = 'foobarbaz';

$client = new TestClient();

$client->setNextResponse(new Response('', 307, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);

$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect with POST method');
$this->assertArrayHasKey('foo', $client->getRequest()->getParameters(), '->followRedirect() keeps parameters with POST method');
$this->assertArrayHasKey('myfile.foo', $client->getRequest()->getFiles(), '->followRedirect() keeps files with POST method');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method');
$this->assertEquals($content, $client->getRequest()->getContent(), '->followRedirect() keeps content with POST method');
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');
}

public function testBack()
{
$client = new TestClient();
Expand Down

0 comments on commit 014c0d1

Please sign in to comment.