Skip to content

Commit f296cfc

Browse files
committed
More test coverage.
1 parent 801a674 commit f296cfc

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

tests/Message/DPMCompleteRequestTest.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Omnipay\AuthorizeNet\Message;
44

5+
/**
6+
* The CompleteRequest object is invoked in the callback handler.
7+
*/
8+
59
use Omnipay\Tests\TestCase;
610

711
class DPMCompleteAuthorizeRequestTest extends TestCase
@@ -21,21 +25,19 @@ public function testGetDataInvalid()
2125
$this->request->getData();
2226
}
2327

24-
public function testGetHash()
28+
public function testGetDpmHash()
2529
{
2630
$this->assertSame(md5(''), $this->request->getHash());
2731

2832
$this->request->setHashSecret('hashsec');
2933
$this->request->setApiLoginId('apilogin');
30-
$this->request->setTransactionId('trnid');
31-
$this->request->setAmount('10.00');
3234

33-
$this->assertSame(md5('hashsecapilogintrnid10.00'), $this->request->getHash());
35+
$this->assertSame(md5('hashsec' . 'apilogin' . 'trnid' . '10.00'), $this->request->getDpmHash('trnid', '10.00'));
3436
}
3537

3638
public function testSend()
3739
{
38-
// Note: the hash contains no data supplied by the merchant site, apart
40+
// The hash contains no data supplied by the merchant site, apart
3941
// from the secret. This is the first point at which we see the transaction
4042
// reference (x_trans_id), and this hash is to validate that the reference and
4143
// the amount have not be tampered with en-route.
@@ -50,13 +52,39 @@ public function testSend()
5052
);
5153
$this->request->setApiLoginId('user');
5254
$this->request->setHashSecret('shhh');
53-
//$this->request->setAmount('10.00');
54-
//$this->request->setTransactionReference('12345');
55+
56+
$this->request->setAmount('10.00');
5557

5658
$response = $this->request->send();
5759

5860
$this->assertTrue($response->isSuccessful());
5961
$this->assertSame('12345', $response->getTransactionReference());
6062
$this->assertNull($response->getMessage());
6163
}
64+
65+
/**
66+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
67+
* @expectedExceptionMessage Incorrect amount
68+
*/
69+
public function testSendWrongAmount()
70+
{
71+
$this->getHttpRequest()->request->replace(
72+
array(
73+
'x_response_code' => '1',
74+
'x_trans_id' => '12345',
75+
'x_amount' => '10.00',
76+
'x_MD5_Hash' => strtolower(md5('shhh' . 'user' . '12345' . '10.00')),
77+
)
78+
);
79+
$this->request->setApiLoginId('user');
80+
$this->request->setHashSecret('shhh');
81+
82+
// In the callback, the merchant application sets the amount that
83+
// was expected to be authorised. We expected 20.00 but are being
84+
// told it was 10.00.
85+
86+
$this->request->setAmount('20.00');
87+
88+
$response = $this->request->send();
89+
}
6290
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class DPMompleteResponseTest extends TestCase
8+
{
9+
public function testSuccess()
10+
{
11+
$response = new DPMCompleteResponse($this->getMockRequest(), array('x_response_code' => '1', 'x_trans_id' => '12345'));
12+
13+
$this->assertTrue($response->isSuccessful());
14+
$this->assertSame('12345', $response->getTransactionReference());
15+
$this->assertNull($response->getMessage());
16+
}
17+
18+
public function testFailure()
19+
{
20+
$response = new DPMCompleteResponse($this->getMockRequest(), array('x_response_code' => '0', 'x_response_reason_text' => 'Declined'));
21+
22+
$this->assertFalse($response->isSuccessful());
23+
$this->assertNull($response->getTransactionReference());
24+
$this->assertSame('Declined', $response->getMessage());
25+
}
26+
}

tests/Mock/DPMAuthorizeFailure.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HTTP/1.1 200 OK
2+
CACHE-CONTROL: no-cache
3+
CONNECTION: close
4+
PRAGMA: no-cache
5+
CONTENT-TYPE: application/x-www-form-urlencoded
6+
ACCEPT: */*
7+
CONTENT-LENGTH: 739
8+
HOST: example.com
9+
10+
x_response_code=3&x_response_reason_code=98&x_response_reason_text=%28TESTMODE%29+This+transaction+cannot+be+accepted%2E&x_avs_code=P&x_auth_code=000000&x_trans_id=0&x_method=CC&x_card_type=&x_account_number=&x_first_name=&x_last_name=&x_company=&x_address=&x_city=&x_state=&x_zip=&x_country=&x_phone=&x_fax=&x_email=&x_invoice_num=&x_description=&x_type=auth%5Fonly&x_cust_id=&x_ship_to_first_name=&x_ship_to_last_name=&x_ship_to_company=&x_ship_to_address=&x_ship_to_city=&x_ship_to_state=&x_ship_to_zip=&x_ship_to_country=&x_amount=10%2E00&x_tax=0%2E00&x_duty=0%2E00&x_freight=0%2E00&x_tax_exempt=FALSE&x_po_num=&x_MD5_Hash=480AA04BE6E4BF0469B63D9E42BD568A&x_cvv2_resp_code=&x_cavv_response=&x_test_request=true

tests/Mock/DPMAuthorizeSuccess.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HTTP/1.1 200 OK
2+
CACHE-CONTROL: no-cache
3+
CONNECTION: close
4+
PRAGMA: no-cache
5+
CONTENT-TYPE: application/x-www-form-urlencoded
6+
ACCEPT: */*
7+
CONTENT-LENGTH: 877
8+
HOST: example.com
9+
10+
x_response_code=1&x_response_reason_code=1&x_response_reason_text=%28TESTMODE%29+This+transaction+has+been+approved%2E&x_avs_code=P&x_auth_code=000000&x_trans_id=2184493132&x_method=CC&x_card_type=Visa&x_account_number=XXXX4242&x_first_name=Joe&x_last_name=Bloggs&x_company=&x_address=88+Address+2&x_city=City&x_state=State&x_zip=412&x_country=GB&x_phone=01234+567+890&x_fax=&x_email=jason%40academe%2Eco%2Euk&x_invoice_num=975077375&x_description=&x_type=auth%5Fonly&x_cust_id=CUST123&x_ship_to_first_name=Joe&x_ship_to_last_name=Bloggs&x_ship_to_company=&x_ship_to_address=99+Address+2S&x_ship_to_city=CityS&x_ship_to_state=StateS&x_ship_to_zip=412S&x_ship_to_country=GB&x_amount=10%2E00&x_tax=0%2E00&x_duty=0%2E00&x_freight=0%2E00&x_tax_exempt=FALSE&x_po_num=&x_MD5_Hash=480AA04BE6E4BF0469B63D9E42BD568A&x_cvv2_resp_code=&x_cavv_response=&x_test_request=true

0 commit comments

Comments
 (0)