/**
     * Test apply with POST method throws an exception if status code is an
     * error.
     *
     * @param int    $code    http error code
     * @param string $message error message
     *
     * @dataProvider responseErrorCodes
     * @return void
     */
    public function testApplyPostErrorCode($code, $message)
    {
        $this->setExpectedException(
            'Klarna_Checkout_ConnectorException', $message, $code
        );

        $curl = new Klarna_Checkout_HTTP_TransportStub;

        $data = array(
            'code' => $code,
            'headers' => array(),
            'payload' => $message
        );
        $curl->addResponse($data);

        $this->digest->expects($this->once())
            ->method('create')
            ->with('[]aboogie')
            ->will($this->returnValue('stnaeu\eu2341aoaaoae=='));

        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );
        $result = $object->apply('POST', $this->orderStub);

        $this->assertNotNull($result, 'Response Object');
    }
    /**
     * Test with an infinite redirect (301) loop.
     *
     * @return void
     */
    public function testApplyGet301InfiniteLoop()
    {
        $this->setExpectedException(
            'Klarna_Checkout_ConnectorException',
            'Infinite redirect loop detected.'
        );

        $options = array('url' => 'localhost');

        $curl = new Klarna_Checkout_HTTP_TransportStub;

        $curl->addResponse(
            array(
                'code' => 301,
                'headers' => array('Location' => 'not localhost'),
                'payload' => ""
            )
        );

        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );

        $object->apply('GET', $this->orderStub, $options);
    }
    /**
     * Ensue that a 301 redirect is not followed by POST.
     *
     * @return void
     */
    public function testApplyPostDoesntFollowRedirect301()
    {
        $options = array('url' => 'localhost');

        $curl = new Klarna_Checkout_HTTP_TransportStub;

        $payload = 'Forbidden';
        $redirect = 'not localhost';

        $data = array(
            array(
                'code' => 503,
                'headers' => array(),
                'payload' => $payload
            ),
            array(
                'code' => 301,
                'headers' => array('Location' => $redirect),
                'payload' => ""
            )
        );
        foreach ($data as $response) {
            $curl->addResponse($response);
        }

        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );

        $result = null;
        try {
            $result = $object->apply('POST', $this->orderStub, $options);
        } catch (Exception $e) {
            throw $e;
        }
        $request = $curl->request;
        $this->assertNotEquals($redirect, $request->getUrl(), 'Url Option');
    }