r100627 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100626‎ | r100627 | r100628 >
Date:17:30, 24 October 2011
Author:jpostlethwaite
Status:deferred
Tags:fundraising 
Comment:
Adding data helpers for unit testing.
Modified paths:
  • /trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php
@@ -34,4 +34,156 @@
3535 */
3636 abstract class DonationInterfaceTestCase extends PHPUnit_Framework_TestCase
3737 {
 38+
 39+ /**
 40+ * This fetches test data to be used for gateway adapters.
 41+ *
 42+ * The returned result is populated with a test user from Spain, attempting
 43+ * a bank transfer for 350 EUR.
 44+ *
 45+ * Options that may need to be set:
 46+ * - adapter: (string) Defaults to TESTS_ADAPTER_DEFAULT
 47+ * - gateway: (string) Defaults to TESTS_GATEWAY_DEFAULT
 48+ * - test: (boolean) $test may be legacy code, use with caution.
 49+ *
 50+ *
 51+ *
 52+ * This test data has these defaults:
 53+ * - amount: Amount is set to an integer, by default, for the amount of 350
 54+ * - payment_method: bt
 55+ * - payment_submethod: bt
 56+ * - email: TESTS_EMAIL
 57+ * - fname: Testy:
 58+ * - lname: Testerton:
 59+ * - street: 123 Happy Street:
 60+ * - city: Barcelona:
 61+ * - state: XX:
 62+ * - zip:
 63+ * - country: ES:
 64+ * - //size: small
 65+ * - currency: EUR:
 66+ * - payment_method:
 67+ * - //order_id: 5038287830
 68+ * - //i_order_id: 1234567890
 69+ * - numAttempt: 0
 70+ * - referrer: http:// . TESTS_HOSTNAME . /index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount:
 71+ * - utm_source: ..gc_bt:
 72+ * - utm_medium: null
 73+ * - utm_campaign: null
 74+ * - language: en:
 75+ * - comment-option:
 76+ * - comment:
 77+ * - email-opt: 1
 78+ * - test_string:
 79+ * - token:
 80+ * - contribution_tracking_id:
 81+ * - data_hash:
 82+ * - action:
 83+ * - gateway: globalcollect:
 84+ * - owa_session:
 85+ * - owa_ref: http://localhost/defaultTestData
 86+ *
 87+ */
 88+ public function getGatewayAdapterTestDataFromSpain( $options = array() ) {
 89+
 90+ extract( $options );
 91+
 92+
 93+ $adapter = isset( $adapter ) ? (string) $adapter : TESTS_ADAPTER_DEFAULT ;
 94+ $gateway = isset( $gateway ) ? (string) $gateway : TESTS_GATEWAY_DEFAULT ;
 95+
 96+ $form_name = isset( $form_name ) ? (string) $form_name : 'TwoStepAmount' ;
 97+
 98+ // This is used to make sure the gateway and adapter match for unit testing.
 99+ if ( $adapter == 'PayflowProAdapter' && $gateway == 'PayflowProGateway' ) {
 100+
 101+ $gatewayAdapterMatch = true;
 102+ }
 103+ elseif ( $adapter == 'GlobalCollectAdapter' && $gateway == 'GlobalCollectGateway' ) {
 104+
 105+ $gatewayAdapterMatch = true;
 106+ }
 107+ else {
 108+
 109+ $gatewayAdapterMatch = false;
 110+ }
 111+
 112+ if ( !$gatewayAdapterMatch ) {
 113+
 114+ $message = 'Gateway (' . $gateway . ') does not match the adapter (' . $adapter . ').';
 115+ throw new Exception( $message );
 116+ }
 117+
 118+ // $test may be legacy code, use with caution.
 119+ $test = isset( $test ) ? (boolean) $test : true ;
 120+ $return['test'] = $test;
 121+
 122+ $payment_method = isset( $payment_method ) ? (string) $payment_method : 'bt' ;
 123+ $payment_submethod = isset( $payment_submethod ) ? (string) $payment_submethod : 'bt' ;
 124+ $amount = isset( $amount ) ? $amount : 350 ;
 125+ $currency = isset( $currency ) ? (string) $currency : 'EUR' ;
 126+ $language = isset( $language ) ? (string) $language : 'en' ;
 127+
 128+ $email = isset( $email ) ? (string) $email : TESTS_EMAIL ;
 129+ $fname = isset( $fname ) ? (string) $fname : 'Testy' ;
 130+ $lname = isset( $lname ) ? (string) $lname : 'Testerton' ;
 131+ $street = isset( $street ) ? (string) $street : '123 Happy Street' ;
 132+ $city = isset( $city ) ? (string) $city : 'Barcelona' ;
 133+ $state = isset( $state ) ? (string) $state : 'XX' ;
 134+ $zip = isset( $zip ) ? (string) $zip : '' ;
 135+ $country = isset( $country ) ? (string) $country : 'ES' ;
 136+
 137+
 138+ $return = array();
 139+
 140+ $return['postDefaults'] = array(
 141+ 'returnTitle' => true,
 142+ 'returnTo' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:' . $gateway . 'Result',
 143+ );
 144+
 145+ $return['testData'] = array(
 146+ 'amount' => $amount,
 147+ 'payment_method' => $payment_method,
 148+ 'payment_submethod' => $payment_submethod,
 149+ 'email' => $email,
 150+ 'fname' => $fname,
 151+ 'lname' => $lname,
 152+ 'street' => $street,
 153+ 'city' => $city,
 154+ 'state' => $state,
 155+ 'zip' => $zip,
 156+ 'country' => $country,
 157+ //'size' => 'small',
 158+ 'currency' => $currency,
 159+ //'order_id' => '5038287830',
 160+ //'i_order_id' => '1234567890',
 161+ 'numAttempt' => 0,
 162+ 'referrer' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:' . $gateway . '?form_name=' . $form_name,
 163+ 'utm_source' => '..gc_bt',
 164+ 'utm_medium' => null,
 165+ 'utm_campaign' => null,
 166+ 'language' => $language,
 167+ 'comment-option' => '',
 168+ 'comment' => '',
 169+ 'email-opt' => 1,
 170+ 'test_string' => '',
 171+ 'token' => '',
 172+ 'contribution_tracking_id' => '',
 173+ 'data_hash' => '',
 174+ 'action' => '',
 175+ 'gateway' => '',
 176+ 'owa_session' => '',
 177+ 'owa_ref' => 'http://localhost/defaultTestData',
 178+ );
 179+
 180+ if ( $gateway == 'GlobalCollectGateway' ) {
 181+ $return['testData']['gateway'] = 'globalcollect';
 182+ }
 183+ elseif ( $gateway == 'PayflowProGateway' ) {
 184+ $return['testData']['gateway'] = 'payflowpro';
 185+ }
 186+
 187+ return $return;
 188+
 189+ }
38190 }

Status & tagging log