Ejegg has uploaded a new change for review.

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

Change subject: Use transaction-specific URLs for Astropay
......................................................................

Use transaction-specific URLs for Astropay

And set up Astropay testing scaffold.

Bug: T90503
Change-Id: Ie258f8f8a0f7f79d01c2ef75332d6695f1f84a43
---
M DonationInterface.php
M astropay_gateway/astropay.adapter.php
A tests/Adapter/Astropay/AstropayTest.php
M tests/DonationInterfaceTestCase.php
M tests/TestConfiguration.php
A tests/includes/test_gateway/TestingAstropayAdapter.php
6 files changed, 185 insertions(+), 0 deletions(-)


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

diff --git a/DonationInterface.php b/DonationInterface.php
index cb8c468..366c0f5 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -1079,6 +1079,7 @@
 
        $wgAutoloadClasses['TestingAdyenAdapter'] = $testDir . 
'includes/test_gateway/TestingAdyenAdapter.php';
        $wgAutoloadClasses['TestingAmazonAdapter'] = $testDir . 
'includes/test_gateway/TestingAmazonAdapter.php';
+       $wgAutoloadClasses['TestingAstropayAdapter'] = $testDir . 
'includes/test_gateway/TestingAstropayAdapter.php';
        $wgAutoloadClasses['TestingAmazonGateway'] = $testDir . 
'includes/test_page/TestingAmazonGateway.php';
        $wgAutoloadClasses['TestingDonationLogger'] = $testDir . 
'includes/TestingDonationLogger.php';
        $wgAutoloadClasses['TestingGatewayPage'] = $testDir . 
'includes/TestingGatewayPage.php';
diff --git a/astropay_gateway/astropay.adapter.php 
b/astropay_gateway/astropay.adapter.php
index f55395c..0c0064f 100644
--- a/astropay_gateway/astropay.adapter.php
+++ b/astropay_gateway/astropay.adapter.php
@@ -290,4 +290,18 @@
                        hash_hmac( 'sha256', pack( 'A*', $message ), pack( 
'A*', $this->accountInfo['secretKey'] ) )
                );
        }
+
+       /**
+        * Overrides parent function to provide transaction-specific urls
+        * @return array
+        */
+       function getCurlBaseOpts() {
+               $transaction_name = $this->getCurrentTransaction();
+               $transaction = $this->transactions[$transaction_name];
+
+               $opts = parent::getCurlBaseOpts();
+               $opts[CURLOPT_URL] = $this->url . $transaction['path'];
+
+               return $opts;
+       }
 }
diff --git a/tests/Adapter/Astropay/AstropayTest.php 
b/tests/Adapter/Astropay/AstropayTest.php
new file mode 100644
index 0000000..ef72dd8
--- /dev/null
+++ b/tests/Adapter/Astropay/AstropayTest.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/**
+ *
+ * @group Fundraising
+ * @group DonationInterface
+ * @group Astropay
+ */
+class DonationInterface_Adapter_Astropay_AstropayTest extends 
DonationInterfaceTestCase {
+
+       /**
+        * @param $name string The name of the test case
+        * @param $data array Any parameters read from a dataProvider
+        * @param $dataName string|int The name or index of the data set
+        */
+       function __construct( $name = null, array $data = array(), $dataName = 
'' ) {
+               parent::__construct( $name, $data, $dataName );
+               $this->testAdapterClass = 'TestingAstropayAdapter';
+       }
+
+       function tearDown() {
+               TestingAstropayAdapter::clearGlobalsCache();
+               parent::tearDown();
+       }
+
+       /**
+        * Ensure we're setting the right url for each transaction
+        * @covers AstropayAdapter::getCurlBaseOpts
+        */
+       function testCurlUrl() {
+               $init = $this->getDonorTestData( 'BR' );
+               $gateway = $this->getFreshGatewayObject( $init );
+               $gateway->setCurrentTransaction( 'NewInvoice' );
+
+               $result = $gateway->getCurlBaseOpts();
+
+               $this->assertEquals(
+                       
'https://sandbox.astropay.example.com/api_curl/streamline/NewInvoice',
+                       $result[CURLOPT_URL],
+                       'Not setting URL to transaction-specific value.'
+               );
+       }
+}
diff --git a/tests/DonationInterfaceTestCase.php 
b/tests/DonationInterfaceTestCase.php
index 1618603..af21573 100644
--- a/tests/DonationInterfaceTestCase.php
+++ b/tests/DonationInterfaceTestCase.php
@@ -218,6 +218,17 @@
                                'amount' => '1.55',
                                'language' => 'en',
                        ),
+                       'BR' => array (
+                               'city' => 'São Paulo',
+                               'state' => 'SP',
+                               'zip' => '01110-111',
+                               'currency_code' => 'BRL',
+                               'street' => 'Rua 123',
+                               'fname' => 'Nome',
+                               'lname' => 'Apelido',
+                               'amount' => '100',
+                               'language' => 'pt',
+                       ),
                );
                //default to US
                if ( $country === '' ) {
diff --git a/tests/TestConfiguration.php b/tests/TestConfiguration.php
index 064a73b..9a248f2 100644
--- a/tests/TestConfiguration.php
+++ b/tests/TestConfiguration.php
@@ -63,6 +63,9 @@
        $wgAmazonGatewayAccountInfo,
        $wgAdyenGatewayBaseURL,
        $wgAdyenGatewayAccountInfo,
+       $wgAstropayGatewayURL,
+       $wgAstropayGatewayTestingURL,
+       $wgAstropayGatewayAccountInfo,
        $wgWorldPayGatewayAccountInfo,
        $wgWorldPayGatewayURL,
        $wgMinFraudLicenseKey,
@@ -120,6 +123,15 @@
        'SkinCode' => 'testskin',
 );
 
+/** Astropay **/
+$wgAstropayGatewayURL = 'https://astropay.example.com/';
+$wgAstropayGatewayTestingURL = 'https://sandbox.astropay.example.com/';
+$wgAstropayGatewayAccountInfo['test'] = array (
+       'Login' => 'testlogin',
+       'Password' => 'testpass',
+       'SecretKey' => 'NanananananananananananananananaBatman',
+);
+
 /** WorldPay **/
 $wgWorldPayGatewayAccountInfo['test'] = array (
        'Username' => 'testname',
diff --git a/tests/includes/test_gateway/TestingAstropayAdapter.php 
b/tests/includes/test_gateway/TestingAstropayAdapter.php
new file mode 100644
index 0000000..bbe7cac
--- /dev/null
+++ b/tests/includes/test_gateway/TestingAstropayAdapter.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * TestingAstropayAdapter
+ *
+ * TODO: Add dependency injection to the base class so we don't have to repeat
+ * code (or this comment) here.
+ */
+class TestingAstropayAdapter extends AstropayAdapter {
+
+       public $curled = array();
+
+       /**
+        * Clear the static globals cache.
+        */
+       public static function clearGlobalsCache() {
+               self::$globalsCache = array();
+       }
+
+       /**
+        * Set the error code you want the dummy response to return
+        */
+       public function setDummyGatewayResponseCode( $code ) {
+               $this->dummyGatewayResponseCode = $code;
+       }
+
+       /**
+        * Set the error code you want the dummy response to return
+        */
+       public function setDummyCurlResponseCode( $code ) {
+               $this->dummyCurlResponseCode = $code;
+       }
+
+       protected function curl_transaction( $data ) {
+               $this->curled[] = $data;
+               return parent::curl_transaction( $data );
+       }
+
+       /**
+        * Load in some dummy response JSON so we can test proper response 
processing
+        */
+       protected function curl_exec( $ch ) {
+               $code = '';
+               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
+                       $code = '_' . $this->dummyGatewayResponseCode;
+                       if ( $this->dummyGatewayResponseCode == 'Exception' ) {
+                               throw new Exception( 'blah!' );
+                       }
+               }
+
+               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
+               //but frankly I don't want to write tests that test our dummy 
responses.
+               $file_path = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . 
DIRECTORY_SEPARATOR;
+               $file_path .= 'Responses' . DIRECTORY_SEPARATOR . 
self::getIdentifier() . DIRECTORY_SEPARATOR;
+               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
+
+               //these are all going to be short, so...
+               if ( file_exists( $file_path ) ) {
+                       return file_get_contents( $file_path );
+               } else {
+                       echo "File $file_path does not exist.\n"; //<-That will 
deliberately break the test.
+                       return false;
+               }
+       }
+
+       /**
+        * Load in some dummy curl response info so we can test proper response 
processing
+        */
+       protected function curl_getinfo( $ch, $opt = null ) {
+               $code = 200; //response OK
+               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
+                       $code = ( int ) $this->dummyCurlResponseCode;
+               }
+
+               //put more here if it ever turns out that we care about it.
+               return array (
+                       'http_code' => $code,
+               );
+       }
+
+       /**
+        * Set a protected member
+        * @param string $transaction
+        */
+       public function setCurrentTransaction( $transaction ) {
+               $this->current_transaction = $transaction;
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie258f8f8a0f7f79d01c2ef75332d6695f1f84a43
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to