Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/276624
Change subject: Merge master into deployment ...................................................................... Merge master into deployment 52d3cc4 Fix one currency selector edge case d46629e Fix bug so we use invalid amount error 796ab44 Add UYU currency to AstroPay adapter 925e5bd Add PSE bank trasfer to AstroPay adapter 790678b Add form settings for new AstroPay methods 8b66bc8 Fix some Mustache CSS for narrow screens e8cc617 Fix BBVA Bancomer bank code a55717b Move getBlahPage methods out of gateway class 6884527 Localisation updates from https://translatewiki.net. 63e5549 Localisation updates from https://translatewiki.net. 844f98a Don't ask for fiscal number in Mexico or Peru Removed tests Change-Id: Icc30b5590c647399e84a9f8d20936501ed23cd55 --- D tests/Adapter/Amazon/AmazonTest.php D tests/Adapter/GatewayAdapterTest.php D tests/Adapter/PayPal/PayPalTest.php 3 files changed, 0 insertions(+), 899 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/24/276624/1 diff --git a/tests/Adapter/Amazon/AmazonTest.php b/tests/Adapter/Amazon/AmazonTest.php deleted file mode 100644 index e63e94f..0000000 --- a/tests/Adapter/Amazon/AmazonTest.php +++ /dev/null @@ -1,286 +0,0 @@ -<<<<<<< HEAD (da6e94 Merge master into deployment) -======= -<?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 Amazon - */ -class DonationInterface_Adapter_Amazon_Test 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 - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingAmazonAdapter'; - } - - public function setUp() { - parent::setUp(); - - TestingAmazonAdapter::$mockClient = new MockAmazonClient(); - - $this->setMwGlobals( array( - 'wgAmazonGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'amazon' => array( - 'gateway' => 'amazon', - 'payment_methods' => array('amazon' => 'ALL'), - 'redirect', - ), - 'amazon-recurring' => array( - 'gateway' => 'amazon', - 'payment_methods' => array('amazon' => 'ALL'), - 'redirect', - 'recurring', - ), - ), - ) ); - } - - public function tearDown() { - TestingAmazonAdapter::$fakeGlobals = array(); - parent::tearDown(); - } - - /** - * Integration test to verify that the Amazon gateway converts Canadian - * dollars before redirecting - * - * @dataProvider canadaLanguageProvider - */ - function testCanadianDollarConversion( $language ) { - $init = $this->getDonorTestData( 'CA' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'amazon'; - $init['ffname'] = 'amazon'; - $init['language'] = $language; - $rates = CurrencyRates::getCurrencyRates(); - $cadRate = $rates['CAD']; - - $expectedAmount = floor( $init['amount'] / $cadRate ); - - TestingAmazonAdapter::$fakeGlobals = array( - 'FallbackCurrency' => 'USD', - 'NotifyOnConvert' => true, - ); - - $expectedNotification = wfMessage( - 'donate_interface-fallback-currency-notice', - 'USD' - )->inLanguage( $language )->text(); - - $that = $this; //needed for PHP pre-5.4 - $convertTest = function( $amountString ) use ( $expectedAmount, $that ) { - $actual = explode( ' ', trim( $amountString ) ); - $that->assertTrue( is_numeric( $actual[0] ) ); - $difference = abs( floatval( $actual[0] ) - $expectedAmount ); - $that->assertTrue( $difference <= 1 ); - $that->assertEquals( 'USD', $actual[1] ); - }; - - $assertNodes = array( - 'selected-amount' => array( 'innerhtml' => $convertTest ), - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$expectedNotification.*/" - ) - ); - $this->verifyFormOutput( 'TestingAmazonGateway', $init, $assertNodes, false ); - } - - /** - * Integration test to verify that the Amazon gateway shows an error message when validation fails. - */ - function testShowFormOnError() { - $init = $this->getDonorTestData(); - $init['OTT'] = 'SALT123456789'; - $init['amount'] = '-100.00'; - $init['ffname'] = 'amazon'; - $session = array( 'Donor' => $init ); - $errorMessage = wfMessage( 'donate_interface-error-msg-invalid-amount' )->text(); - $assertNodes = array( - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$errorMessage.*/" - ) - ); - - $this->verifyFormOutput( 'AmazonGateway', $init, $assertNodes, false, $session ); - } - - /** - * Check that the adapter makes the correct calls for successful donations - */ - function testDoPaymentSuccess() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - // FIXME: PaymentResult->isFailed returns null for false - $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( '[email protected]', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); - $mockClient = TestingAmazonAdapter::$mockClient; - $setOrderReferenceDetailsArgs = $mockClient->calls['setOrderReferenceDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $this->assertEquals( $oid, $setOrderReferenceDetailsArgs['seller_order_reference_id'], 'Did not set order id on order reference' ); - $this->assertEquals( $init['amount'], $setOrderReferenceDetailsArgs['amount'], 'Did not set amount on order reference' ); - $this->assertEquals( $init['currency_code'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); - $queued = $gateway->queue_messages; - $this->assertNotEmpty( $queued['complete'], 'Not sending a message to the complete queue' ); - $message = $queued['complete'][0]; - $this->assertEquals( 'S01-0391295-0674065-C095112', $message['gateway_txn_id'], 'Queue message has wrong txn ID' ); - } - - /** - * Check that declined authorization is reflected in the result's errors - */ - function testDoPaymentDeclined() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'InvalidPaymentMethod'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->getRefresh(), 'Result should be a refresh on error' ); - $errors = $result->getErrors(); - $this->assertTrue( isset( $errors['InvalidPaymentMethod'] ), 'InvalidPaymentMethod error should be set' ); - } - - /** - * This apparently indicates a shady enough txn that we should turn them away - */ - function testFailOnAmazonRejected() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'AmazonRejected'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - // Could assert something about errors after rebasing onto master - // $errors = $result->getErrors(); - // $this->assertTrue( isset( $errors['AmazonRejected'] ), 'AmazonRejected error should be set' ); - } - - /** - * When the transaction times out, just gotta fail it till we work out an - * asynchronous authorization flow - */ - function testTransactionTimedOut() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'TransactionTimedOut'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - } - - /** - * When the SDK throws an exceptions, we should handle it. - */ - function testClientException() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->exceptions['authorize'][] = new Exception( 'Test' ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $errors = $result->getErrors(); - $this->assertTrue( isset( $errors[ResponseCodes::NO_RESPONSE] ), 'NO_RESPONSE error should be set' ); - } - - /** - * Check the adapter makes the correct calls for successful monthly donations - */ - function testDoRecurringPaymentSuccess() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['recurring'] = '1'; - $init['subscr_id'] = 'C01-9650293-7351908'; - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - // FIXME: PaymentResult->isFailed returns null for false - $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( '[email protected]', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); - $mockClient = TestingAmazonAdapter::$mockClient; - $setBillingAgreementDetailsArgs = $mockClient->calls['setBillingAgreementDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $this->assertEquals( $oid, $setBillingAgreementDetailsArgs['seller_billing_agreement_id'], 'Did not set order id on billing agreement' ); - $authorizeOnBillingAgreementDetailsArgs = $mockClient->calls['authorizeOnBillingAgreement'][0]; - $this->assertEquals( $init['amount'], $authorizeOnBillingAgreementDetailsArgs['authorization_amount'], 'Did not authorize correct amount' ); - $this->assertEquals( $init['currency_code'], $authorizeOnBillingAgreementDetailsArgs['currency_code'], 'Did not authorize correct currency code' ); - $queued = $gateway->queue_messages; - $this->assertNotEmpty( $queued['complete'], 'Not sending a message to the complete queue' ); - $message = $queued['complete'][0]; - $this->assertEquals( 'S01-5318994-6362993-C004044', $message['gateway_txn_id'], 'Queue message has wrong txn ID' ); - $this->assertEquals( $init['subscr_id'], $message['subscr_id'], 'Queue message has wrong subscription ID' ); - } -} ->>>>>>> BRANCH (774bd5 Merge "Don't ask for fiscal number in Mexico or Peru") diff --git a/tests/Adapter/GatewayAdapterTest.php b/tests/Adapter/GatewayAdapterTest.php deleted file mode 100644 index db5083c..0000000 --- a/tests/Adapter/GatewayAdapterTest.php +++ /dev/null @@ -1,313 +0,0 @@ -<<<<<<< HEAD (da6e94 Merge master into deployment) -======= -<?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. - * - */ - -/** - * TODO: Test everything. - * Make sure all the basic functions in the gateway_adapter are tested here. - * Also, the extras and their hooks firing properly and... that the fail score - * they give back is acted upon in the way we think it does. - * Hint: For that mess, use GatewayAdapter's $debugarray - * - * Also, note that it barely makes sense to test the functions that need to be - * defined in each gateway as per the abstract class. If we did that here, we'd - * basically be just testing the test code. So, don't do it. - * Those should definitely be tested in the various gateway-specific test - * classes. - * - * @group Fundraising - * @group DonationInterface - * @group Splunge - */ -class DonationInterface_Adapter_GatewayAdapterTest 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 - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - global $wgDonationInterfaceAllowedHtmlForms; - global $wgDonationInterfaceTest; - $wgDonationInterfaceTest = true; - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'testytest' => array( - 'gateway' => 'globalcollect', // RAR. - ), - 'rapidFailError' => array( - 'file' => 'error-cc.html', - 'gateway' => array( 'globalcollect', 'adyen', 'amazon', 'astropay', 'paypal', 'worldpay' ), - 'special_type' => 'error', - ) - ), - ) ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::defineVarMap - * @covers GatewayAdapter::defineReturnValueMap - * @covers GatewayAdapter::defineTransactions - */ - public function testConstructor() { - - $options = $this->getDonorTestData(); - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( - 'testytest', array( 'gateway' => $class::getIdentifier() ) - ); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway ); - - $this->resetAllEnv(); - $gateway = $this->getFreshGatewayObject( $options = array() ); - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway, "Having trouble constructing a blank adapter." ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers DonationData::__construct - */ - public function testConstructorHasDonationData() { - - $_SERVER['REQUEST_URI'] = '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount'; - - $options = $this->getDonorTestData(); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( 'TestingGlobalCollectAdapter', $gateway ); - - // please define this function only inside the TESTS_ADAPTER_DEFAULT, - // which should be a test adapter object that descende from one of the - // production adapters. - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertInstanceOf( 'DonationData', $exposed->dataObj ); - } - - public function testLanguageChange() { - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'en', "'US' donor's language was inproperly set. Should be 'en'" ); - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - // so we know it tried to screw with the session and such. - - $options = $this->getDonorTestData( 'NO' ); - $gateway = $this->getFreshGatewayObject( $options ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'no', "'NO' donor's language was inproperly set. Should be 'no'" ); - } - - /** - * Make sure data is cleared out when changing gateways. - * In particular, ensure order IDs aren't leaking. - */ - public function testResetOnGatewaySwitch() { - // Fill the session with some GlobalCollect stuff - $init = $this->getDonorTestData( 'FR' ); - $init['contribution_tracking_id'] = mt_rand(); - $firstRequest = $this->setUpRequest( $init ); - $globalcollect_gateway = new TestingGlobalCollectAdapter(); - $globalcollect_gateway->do_transaction( 'Donate' ); - - $session = $firstRequest->getSessionArray(); - $this->assertEquals( 'globalcollect', $session['Donor']['gateway'], 'Test setup failed.' ); - - //Then simpulate switching to Worldpay - $session['sequence'] = 2; - unset( $init['order_id'] ); - - $secondRequest = $this->setUpRequest( $init, $session ); - $worldpay_gateway = new TestingWorldpayAdapter(); - $worldpay_gateway->batch_mode = true; - - $session = $secondRequest->getSessionArray(); - $expected_order_id = "{$init['contribution_tracking_id']}.{$session['sequence']}"; - $this->assertEquals( $expected_order_id, $worldpay_gateway->getData_Unstaged_Escaped( 'order_id' ), - 'Order ID was not regenerated on gateway switch!' ); - } - - public function testResetOnRecurringSwitch() { - // Donor initiates a non-recurring donation - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - - $firstRequest = $this->setUpRequest( $init ); - - $gateway = new TestingGlobalCollectAdapter(); - $gateway->do_transaction( 'Donate' ); - - $donorData = $firstRequest->getSessionData( 'Donor' ); - $this->assertEquals( '', $donorData['recurring'], 'Test setup failed.' ); - $oneTimeOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - // Then they go back and decide they want to make a recurring donation - - $init['recurring'] = '1'; - $secondRequest = $this->setUpRequest( $init, $firstRequest->getSessionArray() ); - - $gateway = new TestingGlobalCollectAdapter(); - $gateway->do_transaction( 'Donate' ); - $donorData = $secondRequest->getSessionData( 'Donor' ); - $this->assertEquals( '1', $donorData['recurring'], 'Test setup failed.' ); - - $recurOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - $this->assertNotEquals( $oneTimeOrderId, $recurOrderId, - 'Order ID was not regenerated on recurring switch!' ); - } - - public function testResetSubmethodOnMethodSwitch() { - // Donor thinks they want to make a bank transfer, submits form - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'bt'; - $init['payment_submethod'] = 'itau'; - - $firstRequest = $this->setUpRequest( $init ); - - $gateway = new TestingAstropayAdapter(); - $gateway->do_transaction( 'Donate' ); - - $donorData = $firstRequest->getSessionData( 'Donor' ); - $this->assertEquals( 'itau', $donorData['payment_submethod'], 'Test setup failed.' ); - - // Then they go back and decide they want to donate via credit card - $init['payment_method'] = 'cc'; - unset( $init['payment_submethod'] ); - - $secondRequest = $this->setUpRequest( $init, $firstRequest->getSessionArray() ); - - $gateway = new TestingAstropayAdapter(); - $newMethod = $gateway->getData_Unstaged_Escaped( 'payment_method' ); - $newSubmethod = $gateway->getData_Unstaged_Escaped( 'payment_submethod' ); - - $this->assertEquals( 'cc', $newMethod, 'Test setup failed' ); - $this->assertEquals( '', $newSubmethod, 'Submethod was not blanked on method switch' ); - } - - public function testStreetStaging() { - $options = $this->getDonorTestData( 'BR' ); - unset( $options['street'] ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $this->setUpRequest( $options ); - $gateway = new TestingGlobalCollectAdapter(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $this->assertEquals( 'N0NE PROVIDED', $exposed->getData_Staged( 'street' ), - 'Street must be stuffed with fake data to prevent AVS scam.' ); - } - - public function testZipStaging() { - $options = $this->getDonorTestData( 'BR' ); - unset( $options['zip'] ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $this->setUpRequest( $options ); - $gateway = new TestingGlobalCollectAdapter(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $this->assertEquals( '0', $exposed->getData_Staged( 'zip' ), - 'Postal code must be stuffed with fake data to prevent AVS scam.' ); - } - - public function testGetRapidFailPage() { - $this->setMwGlobals( array( - 'wgDonationInterfaceRapidFail' => true, - ) ); - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $options ); - $pageUrlParts = explode( '?', ResultPages::getFailPage( $gateway ) ); - parse_str( $pageUrlParts[1], $params ); - $this->assertEquals( 'rapidFailError', $params['ffname'] ); - $this->assertEquals( 'cc', $params['payment_method'] ); - $this->assertEquals( 'en', $params['language'] ); - } - - public function testGetFallbackFailPage() { - $this->setMwGlobals( array( - 'wgDonationInterfaceRapidFail' => false, - 'wgDonationInterfaceFailPage' => 'Main_Page', //coz we know it exists - ) ); - $options = $this->getDonorTestData( 'US' ); - $gateway = $this->getFreshGatewayObject( $options ); - $page = ResultPages::getFailPage( $gateway ); - $expectedTitle = Title::newFromText( 'Main_Page' ); - $expectedURL = wfAppendQuery( $expectedTitle->getFullURL(), 'uselang=en' ); - $this->assertEquals( $expectedURL, $page ); - } - - public function testCannotOverrideIp() { - $data = $this->getDonorTestData( 'FR' ); - unset( $data['country'] ); - $data['user_ip'] = '8.8.8.8'; - - $gateway = $this->getFreshGatewayObject( $data ); - $this->assertEquals( '127.0.0.1', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); - } - - public function testCanOverrideIpInBatchMode() { - $data = $this->getDonorTestData( 'FR' ); - unset( $data['country'] ); - $data['user_ip'] = '8.8.8.8'; - - $gateway = $this->getFreshGatewayObject( $data, array( 'batch_mode' => true ) ); - $this->assertEquals( '8.8.8.8', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); - } - - function testGetScoreName() { - $rule = array( - 'KeyMapA' => array( 'a','s','d','f','q','w','e','r','t' ), - 'KeyMapB' => array(), - 'GibberishWeight' => .9, - 'Score' => 10 - ); - $this->setMwGlobals( - array( 'wgDonationInterfaceNameFilterRules' => array( $rule ) ) - ); - $init = $this->getDonorTestData(); - $init['fname'] = 'asdf'; - $init['lname'] = 'qwert'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->getScoreName(); - $this->assertNotEquals( 0, $result, 'Bad name not detected'); - } -} - ->>>>>>> BRANCH (774bd5 Merge "Don't ask for fiscal number in Mexico or Peru") diff --git a/tests/Adapter/PayPal/PayPalTest.php b/tests/Adapter/PayPal/PayPalTest.php deleted file mode 100644 index 41db58e..0000000 --- a/tests/Adapter/PayPal/PayPalTest.php +++ /dev/null @@ -1,300 +0,0 @@ -<<<<<<< HEAD (da6e94 Merge master into deployment) -======= -<?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 PayPal - */ -class DonationInterface_Adapter_PayPal_Test 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 - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingPaypalAdapter'; - } - - public function setUp() { - global $wgPaypalGatewayHtmlFormDir; - - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceCancelPage' => 'https://example.com/tryAgain.php', - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceThankYouPage' => 'https://example.org/wiki/Thank_You', - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'paypal' => array( - 'file' => $wgPaypalGatewayHtmlFormDir . '/paypal.html', - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - ), - 'paypal-recurring' => array( - 'file' => $wgPaypalGatewayHtmlFormDir . '/paypal-recurring.html', - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - 'recurring', - ), - ), - ) ); - } - - public function tearDown() { - TestingPaypalAdapter::$fakeGlobals = array(); - - parent::tearDown(); - } - - /** - * Integration test to verify that the Donate transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonate() { - $init = $this->getDonorTestData(); - $gateway = $this->getFreshGatewayObject( $init ); - - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => $init['country'], - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => $init['country'], //this works because it's a US donor... - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the DonateRecurring transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonateRecurring() { - $init = $this->getDonorTestData(); - $init['recurring'] = '1'; - $gateway = $this->getFreshGatewayObject( $init ); - - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'a3' => $init['amount'], //obviously. - 'currency_code' => $init['currency_code'], - 'country' => $init['country'], - 'business' => '[email protected]', - 'cmd' => '_xclick-subscriptions', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => $init['country'], //this works because it's a US donor... - 't3' => 'M', //hard-coded in transaction definition - 'p3' => '1', //hard-coded in transaction definition - 'src' => '1', //hard-coded in transaction definition - 'srt' => $gateway->getGlobal( 'RecurringLength' ), - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - ); - - $this->assertEquals( $expected, $res, 'Paypal "DonateRecurring" transaction not constructing the expected redirect URL' ); - } - - /** - * Integration test to verify that the Donate transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonateXclick() { - $init = $this->getDonorTestData(); - - TestingPaypalAdapter::$fakeGlobals = array( - 'XclickCountries' => array( $init['country'] ), - ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => $init['country'], - 'business' => '[email protected]', - 'cmd' => '_xclick', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '1', //hard-coded in transaction definition - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), -// 'lc' => $init['country'], //Apparently, this was removed from our implementation, because 'CN' is weird. - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - 'no_shipping' => '1', //hard-coded in transaction definition - ); - - $this->assertEquals( $expected, $res, 'Paypal "DonateXclick" transaction not constructing the expected redirect URL' ); - } - - /** - * Integration test to verify that the Paypal gateway redirects when validation is successful. - */ - function testRedirectFormOnValid() { - $init = $this->getDonorTestData(); - $session = array( 'Donor' => $init ); - - $that = $this; - $redirectTest = function( $location ) use ( $that, $init ) { - parse_str( parse_url( $location, PHP_URL_QUERY ), $actual ); - $that->assertEquals( $init['amount'], $actual['amount'] ); - }; - $assertNodes = array( - 'headers' => array( - 'Location' => $redirectTest, - ) - ); - - $this->verifyFormOutput( 'PaypalGateway', $init, $assertNodes, false, $session ); - } - - /** - * Integration test to verify that the Paypal gateway shows an error message when validation fails. - */ - function testShowFormOnError() { - $init = $this->getDonorTestData(); - $init['amount'] = '-100.00'; - $session = array( 'Donor' => $init ); - $errorMessage = wfMessage( 'donate_interface-error-msg-invalid-amount' )->text(); - $assertNodes = array( - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$errorMessage.*/" - ) - ); - - $this->verifyFormOutput( 'PaypalGateway', $init, $assertNodes, false, $session ); - } - - /** - * Integration test to verify that the Donate transaction works as expected in Belgium for fr, de, and nl. - * - * @dataProvider belgiumLanguageProvider - */ - function testDoTransactionDonate_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - $init['language'] = $language; - $this->setLanguage( $language ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( $language )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => 'BE', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'BE', - 'cancel_return' => "https://example.com/tryAgain.php/$language", - 'return' => "https://example.org/wiki/Thank_You/$language?country=BE", - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the Donate transaction works as expected - * in Canada for English and French - * - * @dataProvider canadaLanguageProvider - */ - function testDoTransactionDonate_CA( $language ) { - $init = $this->getDonorTestData( 'CA' ); - $init['language'] = $language; - $this->setLanguage( $language ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( $language )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => 'CAD', - 'country' => 'CA', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'CA', - 'cancel_return' => "https://example.com/tryAgain.php/$language", - 'return' => "https://example.org/wiki/Thank_You/$language?country=CA", - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the Donate transaction works as expected in Italy - */ - function testDoTransactionDonate_IT() { - $init = $this->getDonorTestData( 'IT' ); - $this->setLanguage( 'it' ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( 'it' )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => 'IT', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'IT', - 'cancel_return' => 'https://example.com/tryAgain.php/it', - 'return' => 'https://example.org/wiki/Thank_You/it?country=IT', - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } -} ->>>>>>> BRANCH (774bd5 Merge "Don't ask for fiscal number in Mexico or Peru") -- To view, visit https://gerrit.wikimedia.org/r/276624 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icc30b5590c647399e84a9f8d20936501ed23cd55 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
