r100730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100729‎ | r100730 | r100731 >
Date:19:12, 25 October 2011
Author:jpostlethwaite
Status:deferred
Tags:fundraising 
Comment:
Added helpers for unit testing.
Modified paths:
  • /trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php
@@ -34,20 +34,29 @@
3535 */
3636 abstract class DonationInterfaceTestCase extends PHPUnit_Framework_TestCase
3737 {
 38+
 39+ /**
 40+ * This will be set by a test method with the adapter object.
 41+ *
 42+ * @var GatewayAdapter $gatewayAdapter
 43+ */
 44+ protected $gatewayAdapter;
3845
3946 /**
4047 * This fetches test data to be used for gateway adapters.
4148 *
 49+ * This method also sets up $_SERVER
 50+ *
4251 * The returned result is populated with a test user from Spain, attempting
4352 * a bank transfer for 350 EUR.
4453 *
 54+ * @param array $options
 55+ *
4556 * Options that may need to be set:
4657 * - adapter: (string) Defaults to TESTS_ADAPTER_DEFAULT
4758 * - gateway: (string) Defaults to TESTS_GATEWAY_DEFAULT
4859 * - test: (boolean) $test may be legacy code, use with caution.
4960 *
50 - *
51 - *
5261 * This test data has these defaults:
5362 * - amount: Amount is set to an integer, by default, for the amount of 350
5463 * - payment_method: bt
@@ -83,8 +92,9 @@
8493 * - owa_session:
8594 * - owa_ref: http://localhost/defaultTestData
8695 *
 96+ * @return array Contains: postDefaults, testData
8797 */
88 - public function getGatewayAdapterTestDataFromSpain( $options = array() ) {
 98+ public function getGatewayAdapterTestData( $options = array() ) {
8999
90100 extract( $options );
91101
@@ -120,6 +130,7 @@
121131
122132 $payment_method = isset( $payment_method ) ? (string) $payment_method : 'bt' ;
123133 $payment_submethod = isset( $payment_submethod ) ? (string) $payment_submethod : 'bt' ;
 134+ $issuer_id = isset( $issuer_id ) ? (string) $issuer_id : '' ;
124135 $amount = isset( $amount ) ? $amount : 350 ;
125136 $currency = isset( $currency ) ? (string) $currency : 'EUR' ;
126137 $language = isset( $language ) ? (string) $language : 'en' ;
@@ -176,14 +187,108 @@
177188 'owa_ref' => 'http://localhost/defaultTestData',
178189 );
179190
 191+ // Set the issuer id if available
 192+ if ( !empty( $issuer_id ) ) {
 193+
 194+ $return['testData']['issuer_id'] = $issuer_id;
 195+ }
 196+
 197+ // Set the gateway
180198 if ( $gateway == 'GlobalCollectGateway' ) {
181199 $return['testData']['gateway'] = 'globalcollect';
182200 }
183201 elseif ( $gateway == 'PayflowProGateway' ) {
184202 $return['testData']['gateway'] = 'payflowpro';
185203 }
 204+
 205+ $_SERVER = array();
 206+
 207+ $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
 208+ $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME;
 209+ $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME;
 210+ $_SERVER['REQUEST_URI'] = '/index.php/Special:' . $gateway . '?form_name=' . $form_name;
186211
187212 return $return;
 213+ }
 214+
 215+
 216+ /**
 217+ * This fetches test data to be used for gateway adapters.
 218+ *
 219+ * The returned result is populated with a test user from Spain, attempting
 220+ * a bank transfer for 350 EUR.
 221+ *
 222+ * If you need more locations to test, implement another method like this
 223+ * one, overriding options as needed.
 224+ *
 225+ * Use the naming conventions with:
 226+ * - From<Location>
 227+ * - Using<BankTransfer>
 228+ *
 229+ * The above parameters would map to: getGatewayAdapterTestDataFromSpainUsingBankTransfer()
 230+ *
 231+ * @see DonationInterfaceTestCase::getGatewayAdapterTestData()
 232+ */
 233+ public function getGatewayAdapterTestDataFromSpain( $options = array() ) {
188234
 235+ $options['city'] = 'Barcelona';
 236+ $options['state'] = 'XX';
 237+ $options['zip'] = '';
 238+ $options['country'] = 'ES';
 239+ $options['currency'] = 'EUR';
 240+
 241+ return $this->getGatewayAdapterTestData( $options );
189242 }
 243+
 244+ /**
 245+ * Get the expected XML request from GlobalCollect
 246+ *
 247+ * @return string The expected XML request
 248+ */
 249+ public function getExpectedXmlRequestForGlobalCollect( $optionsForTestData, $options = array() ) {
 250+
 251+ $orderId = $this->gatewayAdapter->getData( 'order_id' );
 252+
 253+ $expected = '<?xml version="1.0"?>' . "\n";
 254+ $expected .= '<XML>';
 255+ $expected .= '<REQUEST>';
 256+ $expected .= '<ACTION>INSERT_ORDERWITHPAYMENT</ACTION>';
 257+ $expected .= '<META><MERCHANTID>' . $this->gatewayAdapter->getGatewayMerchantId() . '</MERCHANTID><VERSION>1.0</VERSION></META>';
 258+ $expected .= '<PARAMS>';
 259+ $expected .= '<ORDER>';
 260+ $expected .= '<ORDERID>' . $orderId . '</ORDERID>';
 261+ $expected .= '<AMOUNT>' . $options['testData']['amount'] * 100 . '</AMOUNT>';
 262+ $expected .= '<CURRENCYCODE>' . $options['testData']['currency'] . '</CURRENCYCODE>';
 263+ $expected .= '<LANGUAGECODE>' . $options['testData']['language'] . '</LANGUAGECODE>';
 264+ $expected .= '<COUNTRYCODE>' . $options['testData']['country'] . '</COUNTRYCODE>';
 265+ $expected .= '<MERCHANTREFERENCE>' . $orderId . '</MERCHANTREFERENCE>';
 266+ $expected .= '</ORDER>';
 267+ $expected .= '<PAYMENT>';
 268+ $expected .= '<PAYMENTPRODUCTID>' . $optionsForTestData['payment_product_id'] . '</PAYMENTPRODUCTID>';
 269+
 270+ // Set the issuer id if it is passed.
 271+ if ( isset( $optionsForTestData['issuer_id'] ) ) {
 272+ $expected .= '<ISSUERID>' . $optionsForTestData['issuer_id'] . '</ISSUERID>';
 273+ }
 274+
 275+ $expected .= '<AMOUNT>' . $options['testData']['amount'] * 100 . '</AMOUNT>';
 276+ $expected .= '<CURRENCYCODE>' . $options['testData']['currency'] . '</CURRENCYCODE>';
 277+ $expected .= '<LANGUAGECODE>' . $options['testData']['language'] . '</LANGUAGECODE>';
 278+ $expected .= '<COUNTRYCODE>' . $options['testData']['country'] . '</COUNTRYCODE>';
 279+ $expected .= '<HOSTEDINDICATOR>1</HOSTEDINDICATOR>';
 280+ $expected .= '<RETURNURL>http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGatewayResult?order_id=' . $orderId . '</RETURNURL>';
 281+ $expected .= '<FIRSTNAME>' . $options['testData']['fname'] . '</FIRSTNAME>';
 282+ $expected .= '<SURNAME>' . $options['testData']['lname'] . '</SURNAME>';
 283+ $expected .= '<STREET>' . $options['testData']['street'] . '</STREET>';
 284+ $expected .= '<CITY>' . $options['testData']['city'] . '</CITY>';
 285+ $expected .= '<STATE>' . $options['testData']['state'] . '</STATE>';
 286+ $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>';
 287+ $expected .= '</PAYMENT>';
 288+ $expected .= '</PARAMS>';
 289+ $expected .= '</REQUEST>';
 290+ $expected .= '</XML>';
 291+
 292+ return $expected;
 293+
 294+ }
190295 }

Status & tagging log