Index: trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php |
— | — | @@ -34,20 +34,29 @@ |
35 | 35 | */ |
36 | 36 | abstract class DonationInterfaceTestCase extends PHPUnit_Framework_TestCase |
37 | 37 | { |
| 38 | + |
| 39 | + /** |
| 40 | + * This will be set by a test method with the adapter object. |
| 41 | + * |
| 42 | + * @var GatewayAdapter $gatewayAdapter |
| 43 | + */ |
| 44 | + protected $gatewayAdapter; |
38 | 45 | |
39 | 46 | /** |
40 | 47 | * This fetches test data to be used for gateway adapters. |
41 | 48 | * |
| 49 | + * This method also sets up $_SERVER |
| 50 | + * |
42 | 51 | * The returned result is populated with a test user from Spain, attempting |
43 | 52 | * a bank transfer for 350 EUR. |
44 | 53 | * |
| 54 | + * @param array $options |
| 55 | + * |
45 | 56 | * Options that may need to be set: |
46 | 57 | * - adapter: (string) Defaults to TESTS_ADAPTER_DEFAULT |
47 | 58 | * - gateway: (string) Defaults to TESTS_GATEWAY_DEFAULT |
48 | 59 | * - test: (boolean) $test may be legacy code, use with caution. |
49 | 60 | * |
50 | | - * |
51 | | - * |
52 | 61 | * This test data has these defaults: |
53 | 62 | * - amount: Amount is set to an integer, by default, for the amount of 350 |
54 | 63 | * - payment_method: bt |
— | — | @@ -83,8 +92,9 @@ |
84 | 93 | * - owa_session: |
85 | 94 | * - owa_ref: http://localhost/defaultTestData |
86 | 95 | * |
| 96 | + * @return array Contains: postDefaults, testData |
87 | 97 | */ |
88 | | - public function getGatewayAdapterTestDataFromSpain( $options = array() ) { |
| 98 | + public function getGatewayAdapterTestData( $options = array() ) { |
89 | 99 | |
90 | 100 | extract( $options ); |
91 | 101 | |
— | — | @@ -120,6 +130,7 @@ |
121 | 131 | |
122 | 132 | $payment_method = isset( $payment_method ) ? (string) $payment_method : 'bt' ; |
123 | 133 | $payment_submethod = isset( $payment_submethod ) ? (string) $payment_submethod : 'bt' ; |
| 134 | + $issuer_id = isset( $issuer_id ) ? (string) $issuer_id : '' ; |
124 | 135 | $amount = isset( $amount ) ? $amount : 350 ; |
125 | 136 | $currency = isset( $currency ) ? (string) $currency : 'EUR' ; |
126 | 137 | $language = isset( $language ) ? (string) $language : 'en' ; |
— | — | @@ -176,14 +187,108 @@ |
177 | 188 | 'owa_ref' => 'http://localhost/defaultTestData', |
178 | 189 | ); |
179 | 190 | |
| 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 |
180 | 198 | if ( $gateway == 'GlobalCollectGateway' ) { |
181 | 199 | $return['testData']['gateway'] = 'globalcollect'; |
182 | 200 | } |
183 | 201 | elseif ( $gateway == 'PayflowProGateway' ) { |
184 | 202 | $return['testData']['gateway'] = 'payflowpro'; |
185 | 203 | } |
| 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; |
186 | 211 | |
187 | 212 | 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() ) { |
188 | 234 | |
| 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 ); |
189 | 242 | } |
| 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 | + } |
190 | 295 | } |