Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70958


Change subject: Add some tests to cover do_transaction
......................................................................

Add some tests to cover do_transaction

Took some maneuvering, but there's some more code coverage for the various
functions in GlobalCollectAdapter now, via the test adapter.

Change-Id: Ib61e231cc84bb497a9dc5c9be7faaf75eb73550d
---
M globalcollect_gateway/globalcollect.adapter.php
M tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
M tests/DonationDataTestCase.php
M tests/includes/test_gateway/test.adapter.php
4 files changed, 100 insertions(+), 25 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/58/70958/1

diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index e1132d7..103daa1 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -1256,10 +1256,11 @@
                                                        self::log( 
$this->getLogMessagePrefix() . "Running DO_FINISHPAYMENT ($loops)" );
                                                        
                                                        $dopayment_result = 
$this->do_transaction( 'DO_FINISHPAYMENT' );
+                                                       $dopayment_data = 
$dopayment_result['data'];
                                                        //Check the txn status 
and result code to see if we should bother continuing
                                                        if ( 
$this->getTransactionStatus() ){
-                                                               self::log( 
$this->getLogMessagePrefix() . "DO_FINISHPAYMENT ($loops) returned with status 
ID " . $dopayment_result['STATUSID'] );
-                                                               if ( 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', 
$dopayment_result['STATUSID'] ) === 'failed' ){
+                                                               self::log( 
$this->getLogMessagePrefix() . "DO_FINISHPAYMENT ($loops) returned with status 
ID " . $dopayment_data['STATUSID'] );
+                                                               if ( 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', 
$dopayment_data['STATUSID'] ) === 'failed' ){
                                                                        //ack 
and die. 
                                                                        
$problemflag = true; //nothing to be done.
                                                                        
$problemmessage = "DO_FINISHPAYMENT says the payment failed. Giving up 
forever.";
diff --git a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php 
b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
index 36e2a46..3031e18 100644
--- a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
+++ b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
@@ -31,7 +31,11 @@
  * @group GlobalCollect
  */
 class DonationInterface_Adapter_GlobalCollect_GlobalCollectTestCase extends 
DonationInterfaceTestCase {
-
+       public function setUp() {
+               $options = $this->getGatewayAdapterTestDataFromSpain();
+               
+               $this->gatewayAdapter = new TestingGlobalCollectAdapter( 
$options );
+       }
 
        /**
         * testDefineVarMap
@@ -42,15 +46,10 @@
         * @covers GlobalCollectAdapter::defineVarMap 
         */
        public function testDefineVarMap() {
-
                global $wgGlobalCollectGatewayTest;
 
                $wgGlobalCollectGatewayTest = true;
 
-               $options = $this->getGatewayAdapterTestDataFromSpain();
-               
-               $this->gatewayAdapter = new GlobalCollectAdapter( $options );
-               
                $var_map = array(
                        'ORDERID' => 'order_id',
                        'AMOUNT' => 'amount',
@@ -110,7 +109,32 @@
                );
                
                $this->assertEquals( $var_map,  
$this->gatewayAdapter->getVarMap() );
+       }
 
+       /**
+        * @covers GlobalCollectAdapter::do_transaction
+        * @covers GlobalCollectAdapter::transactionConfirm_CreditCard
+        * @covers GlobalCollectAdapter::transactionDirect_Debit
+        * @covers GatewayAdapter::do_transaction
+        * @covers GatewayAdapter::do_transaction_internal
+        */
+       public function testDoTransaction() {
+               $result = $this->gatewayAdapter->do_transaction( 
'INSERT_ORDERWITHPAYMENT' );
+
+               $this->assertTrue(
+                       $result['status']
+               );
+
+               $result = $this->gatewayAdapter->do_transaction( 'Direct_Debit' 
);
+
+               $this->assertTrue(
+                       $result['status']
+               );
+
+               $result = $this->gatewayAdapter->do_transaction( 
'Confirm_CreditCard' );
+
+               $this->assertTrue(
+                       $result['status']
+               );
        }
 }
-
diff --git a/tests/DonationDataTestCase.php b/tests/DonationDataTestCase.php
index 79822ce..daf92e4 100644
--- a/tests/DonationDataTestCase.php
+++ b/tests/DonationDataTestCase.php
@@ -183,7 +183,7 @@
                $ddObj = new DonationData('', true); //test mode from the 
start, no data
                $returned = $ddObj->getDataEscaped();
                $expected = array(
-                       'amount' => '35',
+                       'amount' => '35.00',
                        'email' => '[email protected]',
                        'fname' => 'Tester',
                        'mname' => 'T.',
@@ -204,7 +204,7 @@
                        'premium_language' => 'es',
                        'card_num' => '378282246310005',
                        'card_type' => 'american',
-                       'expiration' => '0614',
+                       'expiration' => '0714',
                        'cvv' => '001',
                        'currency_code' => 'USD',
                        'payment_method' => 'cc',
diff --git a/tests/includes/test_gateway/test.adapter.php 
b/tests/includes/test_gateway/test.adapter.php
index c69a717..34719d9 100644
--- a/tests/includes/test_gateway/test.adapter.php
+++ b/tests/includes/test_gateway/test.adapter.php
@@ -56,28 +56,65 @@
 
                // Get some DOM-looking things for the request body
                $dom = new SimpleXMLElement( $data );
-               $request = array_shift( $dom->xpath( '/XML/REQUEST' ) );
+               $request = $dom->xpath( '/XML/REQUEST' );
+               $request = $request[0];
 
                // Figure out the request type
-               $action = array_shift( $request->xpath( 'ACTION' ) )->asXML();
+               $action = $request->xpath( 'ACTION' );
+               $action = $action[0]->asXML();
                $action = preg_replace( '#^<ACTION>(.*)</ACTION>$#', '\\1', 
$action );
 
-               if ( $action === 'INSERT_ORDERWITHPAYMENT' ) {
-                       // Why can't we use absolute paths here? No real reason 
to
-                       // spend time figuring it out.
-                       $order = array_shift( $request->xpath( 'PARAMS/ORDER' ) 
);
-                       $orderid = array_shift( $order->xpath( 'ORDERID' ) 
)->asXML();
-                       $orderid = preg_replace( '#^<ORDERID>(.*)</ORDERID>$#', 
'\\1', $orderid );
-                       $amount = array_shift( $order->xpath( 'AMOUNT' ) 
)->asXML();
-                       $amount = preg_replace( '#^<AMOUNT>(.*)</AMOUNT>$#', 
'\\1', $amount );
-                       $currency = array_shift( $order->xpath( 'CURRENCYCODE' 
) )->asXML();
-                       $currency = preg_replace( 
'#^<CURRENCY>(.*)</CURRENCY>$#', '\\1', $currency );
+               if ( $action === 'INSERT_ORDERWITHPAYMENT' ||
+                               $action === 'GET_ORDERSTATUS' ||
+                               $action === 'DO_FINISHPAYMENT' ) {
+                       if ( $action === 'INSERT_ORDERWITHPAYMENT' ||
+                                       $action === 'GET_ORDERSTATUS' ) {
+                               // Why can't we use absolute paths here? No 
real reason to
+                               // spend time figuring it out.
+                               $order = $request->xpath( 'PARAMS/ORDER' );
+                               $order = $order[0];
+                               $orderid = $order->xpath( 'ORDERID' );
+                       } else if ( $action === 'DO_FINISHPAYMENT' ) {
+                               $orderid = $request->xpath( 
'PARAMS/PAYMENT/ORDERID' );
+                       }
+
+                       if ( $orderid ) {
+                               $orderid = $orderid[0]->asXML();
+                               $orderid = preg_replace( 
'#^<ORDERID>(.*)</ORDERID>$#', '\\1', $orderid );
+                       }
+
+                       if ( $action === 'INSERT_ORDERWITHPAYMENT' ) {
+                               $amount = $order->xpath( 'AMOUNT' );
+                               $amount = $amount[0]->asXML();
+                               $amount = preg_replace( 
'#^<AMOUNT>(.*)</AMOUNT>$#', '\\1', $amount );
+                               $currency = $order->xpath( 'CURRENCYCODE' );
+                               $currency = $currency[0]->asXML();
+                               $currency = preg_replace( 
'#^<CURRENCY>(.*)</CURRENCY>$#', '\\1', $currency );
+                       }
 
                        // Constants
                        $refnum = '000000000000000000000000000000';
-                       $statusid = '20';
+
+                       switch ( $action ) {
+                               case 'INSERT_ORDERWITHPAYMENT':
+                                       // Status pending
+                                       $statusid = '20';
+                                       break;
+
+                               case 'GET_ORDERSTATUS':
+                                       // Status pending-poke
+                                       $statusid = '200';
+                                       break;
+
+                               case 'DO_FINISHPAYMENT':
+                                       // Status complete
+                                       $statusid = '1000';
+                                       break;
+                       }
+
                        $mac = 'maQKu1wA3aLG11UymxkvFHV2LbqLxZH12COp/JEZ/uo=';
                        $datetime = date( 'YmdHis' );
+                       $mercid = 'test';
 
                        $formURI = '#';
 
@@ -88,7 +125,13 @@
                        $meta->addChild( 'REQUESTID', '1891851' );
                        $meta->addChild( 'RESPONSEDATETIME', $datetime );
 
-                       $row = $response->addChild( 'ROW' );
+                       if ( $action === 'INSERT_ORDERWITHPAYMENT' ||
+                                       $action === 'DO_FINISHPAYMENT' ) {
+                               $row = $response->addChild( 'ROW' );
+                       } else {
+                               $row = $response->addChild( 'STATUS' );
+                       }
+
                        $row->addChild( 'STATUSDATE', $datetime );
                        $row->addChild( 'PAYMENTREFERENCE', '0' );
                        $row->addChild( 'ADDITIONALREFERENCE', $orderid );
@@ -104,7 +147,14 @@
                        $row->addChild( 'RETURNMAC', 
's1h645HHsQRpCEMpOa8IyfAEHtPig+N0cEYmt08LSrw=' );
                        $row->addChild( 'MAC', $mac );
 
+                       if ( $action === 'GET_ORDERSTATUS' ) {
+                               // It turns out that we're expected to send 
back some form of CVV.
+                               $row->addChild( 'CVVRESULT', '123' );
+                       }
+
                        $xmlresponse = $dom->asXML();
+               } else {
+                       $xmlresponse = '<XML></XML>';
                }
 
                $results['result'] = (

-- 
To view, visit https://gerrit.wikimedia.org/r/70958
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib61e231cc84bb497a9dc5c9be7faaf75eb73550d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: deploy-payments_1.22
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to