Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/235369
Change subject: Move Amazon test responses into their own files
......................................................................
Move Amazon test responses into their own files
Now more like the other adapter test responses.
Bug: T108123
Change-Id: I39e8ca959cb223b2bad81ab624d261d6ba1d6df6
---
M tests/Adapter/Amazon/AmazonTest.php
M tests/includes/MockAmazonClient.php
M tests/includes/MockAmazonResponse.php
A tests/includes/Responses/amazon/authorize.json
A tests/includes/Responses/amazon/authorize_InvalidPaymentMethod.json
A tests/includes/Responses/amazon/closeOrderReference.json
A tests/includes/Responses/amazon/confirmOrderReference.json
A tests/includes/Responses/amazon/getCaptureDetails.json
A tests/includes/Responses/amazon/getOrderReferenceDetails.json
A tests/includes/Responses/amazon/setOrderReferenceDetails.json
10 files changed, 186 insertions(+), 177 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/69/235369/1
diff --git a/tests/Adapter/Amazon/AmazonTest.php
b/tests/Adapter/Amazon/AmazonTest.php
index e34c6b5..e7ff302 100644
--- a/tests/Adapter/Amazon/AmazonTest.php
+++ b/tests/Adapter/Amazon/AmazonTest.php
@@ -33,140 +33,10 @@
$this->testAdapterClass = 'TestingAmazonAdapter';
}
- private $normalResponses = array(
- 'setOrderReferenceDetails' => array (
- 'SetOrderReferenceDetailsResult' => array (
- 'OrderReferenceDetails' => array (
- 'OrderReferenceStatus' => array (
- 'State' => 'Draft',
- ),
- 'ExpirationTimestamp' =>
'2016-02-20T21:03:47.077Z',
- 'SellerOrderAttributes' => array (),
- 'OrderTotal' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '10.00',
- ),
- 'ReleaseEnvironment' => 'Sandbox',
- 'SellerNote' => 'Donation to the
Wikimedia Foundation',
- 'AmazonOrderReferenceId' =>
'S01-0391295-0674065',
- 'CreationTimestamp' =>
'2015-08-24T21:03:47.077Z',
- ),
- ),
- 'ResponseMetadata' => array (
- 'RequestId' =>
'fce0cb84-1aa9-4f82-83a1-acf64ece1b56',
- ),
- 'ResponseStatus' => '200',
- ),
- 'confirmOrderReference' => array (
- 'ResponseMetadata' => array (
- 'RequestId' =>
'bbda771d-1739-448e-bdff-d79881dea668',
- ),
- 'ResponseStatus' => '200',
- ),
- 'getOrderReferenceDetails' => array (
- 'GetOrderReferenceDetailsResult' => array (
- 'OrderReferenceDetails' => array (
- 'OrderReferenceStatus' => array (
- 'LastUpdateTimestamp' =>
'2015-08-24T21:50:01.773Z',
- 'State' => 'Open',
- ),
- 'ExpirationTimestamp' =>
'2016-02-20T21:03:47.077Z',
- 'IdList' => array (),
- 'SellerOrderAttributes' => array (),
- 'OrderTotal' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '10.00',
- ),
- 'Buyer' => array (
- 'Name' => 'Testy Test',
- 'Email' =>
'[email protected]',
- ),
- 'ReleaseEnvironment' => 'Sandbox',
- 'SellerNote' => 'Donation to the
Wikimedia Foundation',
- 'AmazonOrderReferenceId' =>
'S01-0391295-0674065',
- 'CreationTimestamp' =>
'2015-08-24T21:03:47.077Z',
- ),
- ),
- 'ResponseMetadata' => array (
- 'RequestId' =>
'd2759fcb-fdb0-4e93-8b9f-c3156d6bc5fd',
- ),
- 'ResponseStatus' => '200',
- ),
- 'authorize' => array (
- 'AuthorizeResult' => array (
- 'AuthorizationDetails' => array (
- 'AuthorizationAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '10.00',
- ),
- 'CapturedAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0',
- ),
- 'SoftDescriptor' => 'AMZ*Wikimedia
Founda',
- 'ExpirationTimestamp' =>
'2015-09-23T21:50:58.221Z',
- 'IdList' => array (
- 'member' =>
'S01-0391295-0674065-C095112',
- ),
- 'AuthorizationStatus' => array (
- 'LastUpdateTimestamp' =>
'2015-08-24T21:50:58.221Z',
- 'ReasonCode' =>
'MaxCapturesProcessed',
- 'State' => 'Closed',
- ),
- 'AuthorizationFee' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0.00',
- ),
- 'CaptureNow' => 'true',
- 'SellerAuthorizationNote' => array (),
- 'CreationTimestamp' =>
'2015-08-24T21:50:58.221Z',
- 'AmazonAuthorizationId' =>
'S01-0391295-0674065-A095112',
- 'AuthorizationReferenceId' => '31243-0',
- ),
- ),
- 'ResponseMetadata' => array (
- 'RequestId' =>
'785d061e-e152-4180-80d1-3a492d16e24e',
- ),
- 'ResponseStatus' => '200',
- ),
- 'getCaptureDetails' => array (
- 'GetCaptureDetailsResult' => array (
- 'CaptureDetails' => array (
- 'CaptureReferenceId' => '31243-0',
- 'CaptureFee' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0.00',
- ),
- 'AmazonCaptureId' =>
'S01-0391295-0674065-C095112',
- 'CreationTimestamp' =>
'2015-08-24T21:50:58.321Z',
- 'SoftDescriptor' => 'AMZ*Wikimedia
Founda',
- 'IdList' => array (),
- 'CaptureStatus' => array (
- 'LastUpdateTimestamp' =>
'2015-08-24T21:50:58.321Z',
- 'State' => 'Completed',
- ),
- 'SellerCaptureNote' => array (),
- 'RefundedAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0',
- ),
- 'CaptureAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '10.00',
- ),
- ),
- ),
- 'ResponseMetadata' => array (
- 'RequestId' =>
'f863dd05-99f3-4e9c-b0b6-561d65281cd7',
- ),
- 'ResponseStatus' => '200',
- ),
- );
-
public function setUp() {
parent::setUp();
- $this->resetClient();
+ TestingAmazonAdapter::$client = new MockAmazonClient();
$this->setMwGlobals( array(
'wgAmazonGatewayEnabled' => true,
@@ -199,13 +69,6 @@
public function tearDown() {
TestingAmazonAdapter::$fakeGlobals = array();
parent::tearDown();
- }
-
- protected function resetClient() {
- TestingAmazonAdapter::$client = new MockAmazonClient();
- foreach ( $this->normalResponses as $function => $response ) {
- TestingAmazonAdapter::$client->returns[$function][] =
$response;
- }
}
/**
@@ -310,40 +173,9 @@
unset( $init['email'] );
unset( $init['fname'] );
unset( $init['lname'] );
+
$mockClient = TestingAmazonAdapter::$client;
- $mockClient->returns['authorize'][0] = array (
- 'AuthorizeResult' => array (
- 'AuthorizationDetails' => array (
- 'AuthorizationAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '10.00',
- ),
- 'CapturedAmount' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0',
- ),
- 'SoftDescriptor' => 'AMZ*Wikimedia
Founda',
- 'ExpirationTimestamp' =>
'2015-09-24T18:24:37.748Z',
- 'AuthorizationStatus' => array (
- 'LastUpdateTimestamp' =>
'2015-08-25T18:24:37.748Z',
- 'State' => 'Declined',
- 'ReasonCode' =>
'InvalidPaymentMethod',
- ),
- 'AuthorizationFee' => array (
- 'CurrencyCode' => 'USD',
- 'Amount' => '0.00',
- ),
- 'CaptureNow' => 'true',
- 'CreationTimestamp' =>
'2015-08-25T18:24:37.748Z',
- 'AmazonAuthorizationId' =>
'S01-2525143-9142520-A075353',
- 'AuthorizationReferenceId' => '31243-0',
- ),
- ),
- 'ResponseMetadata' => array (
- 'RequestId' =>
'0122bebe-b8c3-4435-8169-8b3a92ba1800',
- ),
- 'ResponseStatus' => '200',
- );
+ $mockClient->returns['authorize'][] = 'InvalidPaymentMethod';
$gateway = $this->getFreshGatewayObject( $init );
$result = $gateway->doPayment();
diff --git a/tests/includes/MockAmazonClient.php
b/tests/includes/MockAmazonClient.php
index b8d07d3..3f5de0a 100644
--- a/tests/includes/MockAmazonClient.php
+++ b/tests/includes/MockAmazonClient.php
@@ -16,8 +16,8 @@
// called, recording all argument values.
public $calls = array();
- // As above, but used to mock return values. Values from array are
wrapped
- // in a MockAmazonResponse so we can call toArray() on them
+ // Keys are method names, values are arrays of error codes such as
InvalidPaymentMethod
+ // When a code is not found, the operation will return a successful
result
public $returns = array();
public function __construct( $config = null ) {
@@ -30,11 +30,12 @@
protected function fakeCall( $functionName, $arguments ) {
$this->calls[$functionName][] = $arguments;
+ $status = null;
$returnIndex = count( $this->calls[$functionName] ) - 1;
if ( isset( $this->returns[$functionName] ) && isset(
$this->returns[$functionName][$returnIndex] ) ) {
- return new MockAmazonResponse(
$this->returns[$functionName][$returnIndex] );
+ $status = $this->returns[$functionName][$returnIndex];
}
- return null;
+ return new MockAmazonResponse( $functionName, $status );
}
public function authorize( $requestParameters = array() ) {
diff --git a/tests/includes/MockAmazonResponse.php
b/tests/includes/MockAmazonResponse.php
index 13448a0..a7bb059 100644
--- a/tests/includes/MockAmazonResponse.php
+++ b/tests/includes/MockAmazonResponse.php
@@ -13,9 +13,19 @@
class MockAmazonResponse { // FIXME: implements PwaResponseInterface {
protected $response;
+ protected $jsonDir = __DIR__ . '/Responses/amazon/';
- public function __construct( $response = array() ) {
- $this->response = $response;
+ /**
+ * Creates the fake response from JSON in
tests/includes/Responses/amazon
+ * @param string $operation The PwaClient function call we're faking
+ * @param string $status Set to fake responses with an error status
+ * Reads from $operation_$status.json
+ */
+ public function __construct( $operation, $status = null ) {
+ $statusPart = $status ? '_' . $status : '';
+ $filePath = $this->jsonDir . $operation . $statusPart . '.json';
+ $json = file_get_contents( $filePath );
+ $this->response = json_decode( $json, true );
}
public function getBillingAgreementDetailsStatus( $response ) {
diff --git a/tests/includes/Responses/amazon/authorize.json
b/tests/includes/Responses/amazon/authorize.json
new file mode 100644
index 0000000..39e7a89
--- /dev/null
+++ b/tests/includes/Responses/amazon/authorize.json
@@ -0,0 +1,37 @@
+{
+ "AuthorizeResult": {
+ "AuthorizationDetails": {
+ "AuthorizationAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "10.00"
+ },
+ "CapturedAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "0"
+ },
+ "SoftDescriptor": "AMZ*Wikimedia Founda",
+ "ExpirationTimestamp": "2015-09-23T21:50:58.221Z",
+ "IdList": {
+ "member": "S01-0391295-0674065-C095112"
+ },
+ "AuthorizationStatus": {
+ "LastUpdateTimestamp": "2015-08-24T21:50:58.221Z",
+ "ReasonCode": "MaxCapturesProcessed",
+ "State": "Closed"
+ },
+ "AuthorizationFee": {
+ "CurrencyCode": "USD",
+ "Amount": "0.00"
+ },
+ "CaptureNow": "true",
+ "SellerAuthorizationNote": [],
+ "CreationTimestamp": "2015-08-24T21:50:58.221Z",
+ "AmazonAuthorizationId": "S01-0391295-0674065-A095112",
+ "AuthorizationReferenceId": "31243-0"
+ }
+ },
+ "ResponseMetadata": {
+ "RequestId": "785d061e-e152-4180-80d1-3a492d16e24e"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git
a/tests/includes/Responses/amazon/authorize_InvalidPaymentMethod.json
b/tests/includes/Responses/amazon/authorize_InvalidPaymentMethod.json
new file mode 100644
index 0000000..c6ff854
--- /dev/null
+++ b/tests/includes/Responses/amazon/authorize_InvalidPaymentMethod.json
@@ -0,0 +1,33 @@
+{
+ "AuthorizeResult": {
+ "AuthorizationDetails": {
+ "AuthorizationAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "10.00"
+ },
+ "CapturedAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "0"
+ },
+ "SoftDescriptor": "AMZ*Wikimedia Founda",
+ "ExpirationTimestamp": "2015-09-24T18:24:37.748Z",
+ "AuthorizationStatus": {
+ "LastUpdateTimestamp": "2015-08-25T18:24:37.748Z",
+ "State": "Declined",
+ "ReasonCode": "InvalidPaymentMethod"
+ },
+ "AuthorizationFee": {
+ "CurrencyCode": "USD",
+ "Amount": "0.00"
+ },
+ "CaptureNow": "true",
+ "CreationTimestamp": "2015-08-25T18:24:37.748Z",
+ "AmazonAuthorizationId": "S01-2525143-9142520-A075353",
+ "AuthorizationReferenceId": "31243-0"
+ }
+ },
+ "ResponseMetadata": {
+ "RequestId": "0122bebe-b8c3-4435-8169-8b3a92ba1800"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git a/tests/includes/Responses/amazon/closeOrderReference.json
b/tests/includes/Responses/amazon/closeOrderReference.json
new file mode 100644
index 0000000..30c2166
--- /dev/null
+++ b/tests/includes/Responses/amazon/closeOrderReference.json
@@ -0,0 +1,6 @@
+{
+ "ResponseMetadata": {
+ "RequestId": "bbda771d-1739-448e-bdff-d79881dea668"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git a/tests/includes/Responses/amazon/confirmOrderReference.json
b/tests/includes/Responses/amazon/confirmOrderReference.json
new file mode 100644
index 0000000..30c2166
--- /dev/null
+++ b/tests/includes/Responses/amazon/confirmOrderReference.json
@@ -0,0 +1,6 @@
+{
+ "ResponseMetadata": {
+ "RequestId": "bbda771d-1739-448e-bdff-d79881dea668"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git a/tests/includes/Responses/amazon/getCaptureDetails.json
b/tests/includes/Responses/amazon/getCaptureDetails.json
new file mode 100644
index 0000000..daeb476
--- /dev/null
+++ b/tests/includes/Responses/amazon/getCaptureDetails.json
@@ -0,0 +1,32 @@
+{
+ "GetCaptureDetailsResult": {
+ "CaptureDetails": {
+ "CaptureReferenceId": "31243-0",
+ "CaptureFee": {
+ "CurrencyCode": "USD",
+ "Amount": "0.00"
+ },
+ "AmazonCaptureId": "S01-0391295-0674065-C095112",
+ "CreationTimestamp": "2015-08-24T21:50:58.321Z",
+ "SoftDescriptor": "AMZ*Wikimedia Founda",
+ "IdList": [],
+ "CaptureStatus": {
+ "LastUpdateTimestamp": "2015-08-24T21:50:58.321Z",
+ "State": "Completed"
+ },
+ "SellerCaptureNote": [],
+ "RefundedAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "0"
+ },
+ "CaptureAmount": {
+ "CurrencyCode": "USD",
+ "Amount": "10.00"
+ }
+ }
+ },
+ "ResponseMetadata": {
+ "RequestId": "f863dd05-99f3-4e9c-b0b6-561d65281cd7"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git a/tests/includes/Responses/amazon/getOrderReferenceDetails.json
b/tests/includes/Responses/amazon/getOrderReferenceDetails.json
new file mode 100644
index 0000000..7e97730
--- /dev/null
+++ b/tests/includes/Responses/amazon/getOrderReferenceDetails.json
@@ -0,0 +1,29 @@
+{
+ "GetOrderReferenceDetailsResult": {
+ "OrderReferenceDetails": {
+ "OrderReferenceStatus": {
+ "LastUpdateTimestamp": "2015-08-24T21:50:01.773Z",
+ "State": "Open"
+ },
+ "ExpirationTimestamp": "2016-02-20T21:03:47.077Z",
+ "IdList": [],
+ "SellerOrderAttributes": [],
+ "OrderTotal": {
+ "CurrencyCode": "USD",
+ "Amount": "10.00"
+ },
+ "Buyer": {
+ "Name": "Testy Test",
+ "Email": "[email protected]"
+ },
+ "ReleaseEnvironment": "Sandbox",
+ "SellerNote": "Donation to the Wikimedia Foundation",
+ "AmazonOrderReferenceId": "S01-0391295-0674065",
+ "CreationTimestamp": "2015-08-24T21:03:47.077Z"
+ }
+ },
+ "ResponseMetadata": {
+ "RequestId": "d2759fcb-fdb0-4e93-8b9f-c3156d6bc5fd"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
diff --git a/tests/includes/Responses/amazon/setOrderReferenceDetails.json
b/tests/includes/Responses/amazon/setOrderReferenceDetails.json
new file mode 100644
index 0000000..c5ac4b3
--- /dev/null
+++ b/tests/includes/Responses/amazon/setOrderReferenceDetails.json
@@ -0,0 +1,23 @@
+{
+ "SetOrderReferenceDetailsResult": {
+ "OrderReferenceDetails": {
+ "OrderReferenceStatus": {
+ "State": "Draft"
+ },
+ "ExpirationTimestamp": "2016-02-20T21:03:47.077Z",
+ "SellerOrderAttributes": [],
+ "OrderTotal": {
+ "CurrencyCode": "USD",
+ "Amount": "10.00"
+ },
+ "ReleaseEnvironment": "Sandbox",
+ "SellerNote": "Donation to the Wikimedia Foundation",
+ "AmazonOrderReferenceId": "S01-0391295-0674065",
+ "CreationTimestamp": "2015-08-24T21:03:47.077Z"
+ }
+ },
+ "ResponseMetadata": {
+ "RequestId": "fce0cb84-1aa9-4f82-83a1-acf64ece1b56"
+ },
+ "ResponseStatus": "200"
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/235369
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I39e8ca959cb223b2bad81ab624d261d6ba1d6df6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: amazon
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits