Exemplo n.º 1
0
    public function testFollowRedirectWithMaxRedirects()
    {
        $client = new TestClient();
        $client->setMaxRedirects(1);
        $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() follows a redirect if any');

        $client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected2')));
        try {
            $client->followRedirect();
            $this->fail('->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
        } catch (\Exception $e) {
            $this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
        }

        $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() follows a redirect if any');

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

        $this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
    }
Exemplo n.º 2
0
 public function testFollowRedirectWithMaxRedirects()
 {
     $client = new TestClient();
     $client->setMaxRedirects(1);
     $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() follows a redirect if any');
     $client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected2')));
     try {
         $client->followRedirect();
         $this->fail('->followRedirect() throws a \\LogicException if the request was redirected and limit of redirections was reached');
     } catch (\Exception $e) {
         $this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \\LogicException if the request was redirected and limit of redirections was reached');
     }
     $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() follows a redirect if any');
     $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();
     $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(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
 }
Exemplo n.º 3
0
 public function testGetMaxRedirects()
 {
     $client = new TestClient();
     $this->assertEquals(-1, $client->getMaxRedirects(), '->getMaxRedirects() returns default value');
     $client->setMaxRedirects(3);
     $this->assertEquals(3, $client->getMaxRedirects(), '->getMaxRedirects() returns assigned value');
 }