public function ClientTest::testFollowRedirect in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/browser-kit/Tests/ClientTest.php \Symfony\Component\BrowserKit\Tests\ClientTest::testFollowRedirect()
File
- vendor/
symfony/ browser-kit/ Tests/ ClientTest.php, line 340
Class
Namespace
Symfony\Component\BrowserKit\TestsCode
public function testFollowRedirect() {
$client = new TestClient();
$client
->followRedirects(false);
$client
->request('GET', 'http://www.example.com/foo/foobar');
try {
$client
->followRedirect();
$this
->fail('->followRedirect() throws a \\LogicException if the request was not redirected');
} catch (\Exception $e) {
$this
->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \\LogicException if the request was not redirected');
}
$client
->setNextResponse(new Response('', 302, array(
'Location' => 'http://www.example.com/redirected',
)));
$client
->request('GET', 'http://www.example.com/foo/foobar');
$client
->followRedirect();
$this
->assertEquals('http://www.example.com/redirected', $client
->getRequest()
->getUri(), '->followRedirect() follows a redirect if any');
$client = new TestClient();
$client
->setNextResponse(new Response('', 302, array(
'Location' => 'http://www.example.com/redirected',
)));
$client
->request('GET', 'http://www.example.com/foo/foobar');
$this
->assertEquals('http://www.example.com/redirected', $client
->getRequest()
->getUri(), '->followRedirect() automatically follows redirects if followRedirects is true');
$client = new TestClient();
$client
->setNextResponse(new Response('', 201, array(
'Location' => 'http://www.example.com/redirected',
)));
$client
->request('GET', 'http://www.example.com/foo/foobar');
$this
->assertEquals('http://www.example.com/foo/foobar', $client
->getRequest()
->getUri(), '->followRedirect() does not follow redirect if HTTP Code is not 30x');
$client = new TestClient();
$client
->setNextResponse(new Response('', 201, array(
'Location' => 'http://www.example.com/redirected',
)));
$client
->followRedirects(false);
$client
->request('GET', 'http://www.example.com/foo/foobar');
try {
$client
->followRedirect();
$this
->fail('->followRedirect() throws a \\LogicException if the request did not respond with 30x HTTP Code');
} catch (\Exception $e) {
$this
->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \\LogicException if the request did not respond with 30x HTTP Code');
}
}