use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\Client;
-use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\CookieJar;
+use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\Response;
class SpecialResponse extends Response
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');
}
+ public function testFollowRedirectDropPostMethod()
+ {
+ $parameters = array('foo' => 'bar');
+ $files = array('myfile.foo' => 'baz');
+ $server = array('X_TEST_FOO' => 'bazbar');
+ $content = 'foobarbaz';
+
+ $client = new TestClient();
+
+ foreach (array(301, 302, 303) as $code) {
+ $client->setNextResponse(new Response('', $code, 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 on response code: '.$code.'.');
+ $this->assertEmpty($client->getRequest()->getParameters(), '->followRedirect() drops parameters with POST method on response code: '.$code.'.');
+ $this->assertEmpty($client->getRequest()->getFiles(), '->followRedirect() drops files with POST method on response code: '.$code.'.');
+ $this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method on response code: '.$code.'.');
+ $this->assertEmpty($client->getRequest()->getContent(), '->followRedirect() drops content with POST method on response code: '.$code.'.');
+ $this->assertEquals('GET', $client->getRequest()->getMethod(), '->followRedirect() drops request method to GET on response code: '.$code.'.');
+ }
+ }
+
public function testBack()
{
$client = new TestClient();
$this->assertEquals($content, $client->getRequest()->getContent(), '->forward() keeps content');
}
+ public function testBackAndFrowardWithRedirects()
+ {
+ $client = new TestClient();
+
+ $client->request('GET', 'http://www.example.com/foo');
+ $client->setNextResponse(new Response('', 301, array('Location' => 'http://www.example.com/redirected')));
+ $client->request('GET', 'http://www.example.com/bar');
+
+ $this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), 'client followed redirect');
+
+ $client->back();
+
+ $this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->back() goes back in the history skipping redirects');
+
+ $client->forward();
+
+ $this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->forward() goes forward in the history skipping redirects');
+ }
+
public function testReload()
{
$client = new TestClient();