request = new PurchaseRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize(array( 'accountId' => '111111', 'siteId' => '222222', 'siteCode' => '333333', 'notifyUrl' => 'http://localhost/notify', 'cancelUrl' => 'http://localhost/cancel', 'returnUrl' => 'http://localhost/return', 'gateway' => 'IDEAL', 'issuer' => 'issuer', 'transactionId' => '123456', 'currency' => 'EUR', 'amount' => '100.00', 'description' => 'desc', 'extraData1' => 'extra 1', 'extraData2' => 'extra 2', 'extraData3' => 'extra 3', 'language' => 'a language', 'items' => array( array('name' => 'item 1', 'quantity' => 1), array('name' => 'item 2', 'quantity' => 2) ), 'clientIp' => '127.0.0.1', 'googleAnalyticsCode' => 'analytics code', 'card' => array( 'email' => 'something@example.com', 'firstName' => 'first name', 'lastName' => 'last name', 'address1' => 'address 1', 'address2' => 'address 2', 'postcode' => '1000', 'city' => 'a city', 'country' => 'a country', 'phone' => 'phone number', ) )); } public function testSendSuccess() { $this->setMockHttpResponse('XmlPurchaseSuccess.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals( 'https://testpay.multisafepay.com/pay/?transaction=1373536347Hz4sFtg7WgMulO5q123456&lang=', $response->getRedirectUrl() ); $this->assertEquals('123456', $response->getTransactionReference()); } public function testSendFailure() { $this->setMockHttpResponse('XmlPurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Invalid amount', $response->getMessage()); $this->assertEquals(1001, $response->getCode()); } /** * @dataProvider allDataProvider */ public function testGetData($xml) { $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @dataProvider noIssuerDataProvider */ public function testGetDataWithNonIDEALGatewayDoesNotSetIssuer($xml) { $this->request->setGateway('another'); $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @dataProvider specialCharsDataProvider */ public function testGetDataWithUrlsWithSpecialChars($xml) { $this->request->setReturnUrl('http://localhost/?one=1&two=2'); $this->request->setCancelUrl('http://localhost/?one=1&two=2'); $this->request->setNotifyUrl('http://localhost/?one=1&two=2'); $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @covers \Omnipay\MultiSafepay\Message\PurchaseRequest::generateSignature() */ public function testGenerateSignature() { $method = new ReflectionMethod('\Omnipay\MultiSafepay\Message\PurchaseRequest', 'generateSignature'); $method->setAccessible(true); $signature = $method->invoke($this->request); $this->assertEquals('ad447bab87b8597853432c891e341db1', $signature); } public function allDataProvider() { $xml = << 111111 222222 333333 http://localhost/notify http://localhost/cancel http://localhost/return 127.0.0.1 a language something@example.com first name last name address 1 address 2 1000 a city a country phone number analytics code 123456 EUR 10000 desc extra 1 extra 2 extra 3 IDEAL <ul><li>1 x item 1</li><li>2 x item 2</li></ul> issuer ad447bab87b8597853432c891e341db1 EOF; return array( array($xml), ); } public function noIssuerDataProvider() { $xml = << 111111 222222 333333 http://localhost/notify http://localhost/cancel http://localhost/return 127.0.0.1 a language something@example.com first name last name address 1 address 2 1000 a city a country phone number analytics code 123456 EUR 10000 desc extra 1 extra 2 extra 3 another <ul><li>1 x item 1</li><li>2 x item 2</li></ul> ad447bab87b8597853432c891e341db1 EOF; return array( array($xml), ); } public function specialCharsDataProvider() { $xml = << 111111 222222 333333 http://localhost/?one=1&two=2 http://localhost/?one=1&two=2 http://localhost/?one=1&two=2 127.0.0.1 a language something@example.com first name last name address 1 address 2 1000 a city a country phone number analytics code 123456 EUR 10000 desc extra 1 extra 2 extra 3 IDEAL <ul><li>1 x item 1</li><li>2 x item 2</li></ul> issuer ad447bab87b8597853432c891e341db1 EOF; return array( array($xml), ); } }