Exemplo n.º 1
0
    /**
     * Testing getTransport always returns instance of
     * Klarna_Checkout_HTTP_TransportInterface
     *
     * @return void
     */
    public function testValidTransportType()
    {
        $curl = new Klarna_Checkout_HTTP_TransportStub;
        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );

        $this->assertInstanceOf(
            'Klarna_Checkout_HTTP_TransportInterface',
            $object->getTransport()
        );
    }
    /**
     * 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');
    }