/** * Test so 201 statuscode will update the location on the resource. * * @return void */ public function testApplyPost201UpdatedLocation() { $curl = new Klarna_Checkout_HTTP_TransportStub; $payload = '{"flobadob":["bobcat","wookie"]}'; $location = 'not localhost'; $data = array( 'code' => 201, 'headers' => array('Location' => $location), 'payload' => $payload ); $curl->addResponse($data); $this->orderStub->parse(json_decode($payload, true)); $expected = 'stnaeu\eu2341aoaaoae=='; $this->digest->expects($this->once()) ->method('create') ->with("{$payload}aboogie") ->will($this->returnValue($expected)); $object = new Klarna_Checkout_BasicConnector( $curl, $this->digest, 'aboogie' ); $this->assertNull($this->orderStub->getLocation(), 'Original Location'); $result = $object->apply('POST', $this->orderStub); $this->assertEquals($payload, $result->getData(), 'Response payload'); $this->assertEquals( "Klarna {$expected}", $curl->request->getHeader('Authorization'), 'Header' ); $this->assertEquals( $location, $this->orderStub->getLocation(), 'Location should have beet updated' ); $this->assertEquals( json_decode($payload, true), $this->orderStub->marshal(), 'The data on the resource should not be updated!' ); $this->assertEquals( $this->orderStub->getContentType(), $curl->request->getHeader('Accept'), 'Accept Content Type' ); }
/** * Get the url to use * * @param Klarna_Checkout_ResourceInterface $resource resource * @param array $options Options * * @return string Url to use for HTTP requests */ protected function getUrl( Klarna_Checkout_ResourceInterface $resource, array $options ) { if (array_key_exists('url', $options)) { return $options['url']; } return $resource->getLocation(); }