jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/363972 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment de328fa8 Move fraud filter config to TestConfiguration 655a931c Fix antifraud messages, add tests 4c4fdbe6 Fix function visibility in default getRequestProcessId a249c8be Allow CUIT for Argentina e257265d Localisation updates from https://translatewiki.net. 4438f41b Add one more yahoo tld c8a675e4 Test cleanup - closures can use $this, fix PP test assert 1d95a7ac One more bit of $that = $this cleanup Change-Id: I95d4dbd09b532a2d4a9d62c209dce13de92f9bb6 --- M gateway_common/gateway.adapter.php D tests/phpunit/Adapter/Amazon/AmazonTest.php D tests/phpunit/Adapter/AstroPay/AstroPayTest.php D tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php D tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php D tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php D tests/phpunit/Adapter/PayPal/PayPalExpressTest.php D tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php D tests/phpunit/DataValidatorTest.php D tests/phpunit/FormChooserTest.php D tests/phpunit/FraudFiltersTest.php D tests/phpunit/TestConfiguration.php D tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php 13 files changed, 0 insertions(+), 2,765 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index 50ea23b..e34988d 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -1460,11 +1460,7 @@ * @param array $requestValues * @return int|string Order id */ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch 'master' into deployment"") - protected function getRequestProcessId( $requestValues ) { -======= public function getRequestProcessId( $requestValues ) { ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") return null; } diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php b/tests/phpunit/Adapter/Amazon/AmazonTest.php deleted file mode 100644 index 1846e5f..0000000 --- a/tests/phpunit/Adapter/Amazon/AmazonTest.php +++ /dev/null @@ -1,294 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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(); - DonationInterface::initializeSmashPig( 'amazon' ); - - 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 - * - * FIXME: Merge with currency fallback tests? - * - * @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(); - - $locale = $init['language'] . '_' . $init['country']; - $expectedDisplayAmount = Amount::format( $expectedAmount, 'USD', $locale ); - - $convertTest = function( $amountString ) use ( $expectedDisplayAmount ) { - $this->assertEquals( $expectedDisplayAmount, trim( $amountString ), 'Displaying wrong amount' ); - }; - - $assertNodes = array( - 'selected-amount' => array( 'innerhtml' => $convertTest ), - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$expectedNotification.*/" - ) - ); - $this->verifyFormOutput( 'AmazonGateway', $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['first_name'] ); - unset( $init['last_name'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - $this->assertFalse( $result->isFailed(), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'first_name' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'last_name' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $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_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'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $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['first_name'] ); - unset( $init['last_name'] ); - - $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->assertEquals( - 'InvalidPaymentMethod', - $errors[0]->getErrorCode(), - '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['first_name'] ); - unset( $init['last_name'] ); - - $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['first_name'] ); - unset( $init['last_name'] ); - - $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['first_name'] ); - unset( $init['last_name'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->exceptions['authorize'][] = new Exception( 'Test' ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $errors = $result->getErrors(); - - $this->assertEquals( - ResponseCodes::NO_RESPONSE, - $errors[0]->getErrorCode(), - '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['first_name'] ); - unset( $init['last_name'] ); - - $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( 'first_name' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'last_name' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $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'], $authorizeOnBillingAgreementDetailsArgs['currency_code'], 'Did not authorize correct currency code' ); - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $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 (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php deleted file mode 100644 index b119014..0000000 --- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php +++ /dev/null @@ -1,581 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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. - * - */ - -use \Psr\Log\LogLevel; -use SmashPig\Core\Configuration; -use SmashPig\Core\Context; -use SmashPig\CrmLink\Messages\SourceFields; -use Wikimedia\TestingAccessWrapper; - -/** - * - * @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 setUp() { - parent::setUp(); - $this->setMwGlobals( array( - 'wgAstroPayGatewayEnabled' => true, - ) ); - $config = Configuration::createForView( 'astropay' ); - Context::initWithLogger( $config ); - } - - /** - * 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.' - ); - } - - /** - * Test the NewInvoice transaction is making a sane request and signing - * it correctly - */ - function testNewInvoiceRequest() { - $init = $this->getDonorTestData( 'BR' ); - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $this->setLanguage( $init['language'] ); - $gateway = new TestingAstroPayAdapter(); - - $gateway->do_transaction( 'NewInvoice' ); - parse_str( $gateway->curled[0], $actual ); - - $expected = array( - 'x_login' => 'createlogin', - 'x_trans_key' => 'createpass', - 'x_invoice' => '123456789', - 'x_amount' => '100.00', - 'x_currency' => 'BRL', - 'x_bank' => 'TE', - 'x_country' => 'BR', - 'x_description' => wfMessage( 'donate_interface-donation-description' )->inLanguage( $init['language'] )->text(), - 'x_iduser' => 'nob...@example.org', - 'x_cpf' => '00003456789', - 'x_name' => 'Nome Apelido', - 'x_email' => 'nob...@example.org', - // 'x_address' => 'Rua Falso 123', - // 'x_zip' => '01110-111', - // 'x_city' => 'São Paulo', - // 'x_state' => 'SP', - 'control' => 'AC43664E0C4DF30607A26F271C8998BC4EE26511366E65AFB69B96E89BFD4359', - 'type' => 'json', - ); - $this->assertEquals( $expected, $actual, 'NewInvoice is not including the right parameters' ); - } - - /** - * When AstroPay sends back valid JSON with status "0", we should set txn - * status to true and errors should be empty. - */ - function testStatusNoErrors() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'NewInvoice' ); - - $this->assertEquals( true, $gateway->getTransactionStatus(), - 'Transaction status should be true for code "0"' ); - - $this->assertFalse( $gateway->getErrorState()->hasErrors(), - 'Transaction errors should be empty for code "0"' ); - } - - /** - * If astropay sends back non-JSON, communication status should be false - */ - function testGibberishResponse() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'notJson' ); - - $gateway->do_transaction( 'NewInvoice' ); - - $this->assertEquals( false, $gateway->getTransactionStatus(), - 'Transaction status should be false for bad format' ); - } - - /** - * When AstroPay sends back valid JSON with status "1", we should set - * error array to generic error and log a warning. - */ - function testStatusErrors() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '1' ); - - $gateway->do_transaction( 'NewInvoice' ); - - $errors = $gateway->getErrorState()->getErrors(); - - $this->assertEquals( - 'internal-0000', - $errors[0]->getErrorCode(), - 'Wrong error for code "1"' - ); - $logged = $this->getLogMatches( LogLevel::WARNING, '/This error message should appear in the log./' ); - $this->assertNotEmpty( $logged ); - } - - /** - * do_transaction should set redirect key when we get a valid response. - */ - function testRedirectOnSuccess() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'NewInvoice' ); - - // from the test response - $expected = 'https://sandbox.astropaycard.com/go_to_bank?id=A5jvKfK1iHIRUTPXXt8lDFGaRRLzPgBg'; - $response = $gateway->getTransactionResponse(); - $this->assertEquals( $expected, $response->getRedirect(), - 'do_transaction is not setting the right redirect' ); - } - - /** - * do_transaction should set redirect key when we get a valid response. - */ - function testDoPaymentSuccess() { - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - - $result = $gateway->doPayment(); - - // from the test response - $expected = 'https://sandbox.astropaycard.com/go_to_bank?id=A5jvKfK1iHIRUTPXXt8lDFGaRRLzPgBg'; - $this->assertEquals( $expected, $result->getRedirect(), - 'doPayment is not setting the right redirect' ); - } - - /** - * When AstroPay sends back valid JSON with status "1", we should set - * error array to generic error and log a warning. - */ - function testDoPaymentErrors() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '1' ); - - $result = $gateway->doPayment(); - - $errors = $result->getErrors(); - $this->assertNotEmpty( - $errors, - 'Should be an error in PaymentResult' - ); - - $logged = $this->getLogMatches( LogLevel::WARNING, '/This error message should appear in the log./' ); - $this->assertNotEmpty( $logged ); - // TODO: Should this really be a refresh, or should we finalize to failed here? - $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); - } - - /** - * Should set a validation error on amount - */ - function testDoPaymentLimitExceeded() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'limit_exceeded' ); - - $result = $gateway->doPayment(); - $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); - - $errors = $gateway->getTransactionResponse()->getErrors(); - $this->assertEquals( 'donate_interface-error-msg-limit', $errors[0]->getMessageKey() ); - $this->assertEquals( 'amount', $errors[0]->getField() ); - } - - /** - * Should set a validation error on fiscal_number - */ - function testDoPaymentBadFiscalNumber() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'fiscal_number' ); - - $result = $gateway->doPayment(); - $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); - - $errors = $gateway->getTransactionResponse()->getErrors(); - $this->assertEquals( 'donate_interface-error-msg-fiscal_number', $errors[0]->getMessageKey() ); - $this->assertEquals( 'fiscal_number', $errors[0]->getField() ); - } - - /** - * Should finalize to failed - */ - function testDoPaymentUserUnauthorized() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'user_unauthorized' ); - - $result = $gateway->doPayment(); - $this->assertTrue( $result->isFailed() ); - } - - /** - * Should tell the user to try again - */ - function testDoPaymentCouldNotRegister() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'could_not_register' ); - - $result = $gateway->doPayment(); - $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); - - $errors = $gateway->getTransactionResponse()->getErrors(); - - $this->assertEquals( 'internal-0001', $errors[0]->getErrorCode() ); - } - - /** - * Should tell the user to try again - */ - function testDoPaymentCouldNotMakeDeposit() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'could_not_make_deposit' ); - - $result = $gateway->doPayment(); - $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); - - $errors = $gateway->getTransactionResponse()->getErrors(); - - $this->assertEquals( 'internal-0001', $errors[0]->getErrorCode() ); - } - - /** - * PaymentStatus transaction should interpret the delimited response - */ - function testPaymentStatus() { - $init = $this->getDonorTestData( 'BR' ); - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $gateway = new TestingAstroPayAdapter(); - - $gateway->do_transaction( 'PaymentStatus' ); - - // from the test response - $expected = array( - 'result' => '9', - 'x_amount' => '100.00', - 'x_iduser' => '08feb2d12771bbcfeb86', - 'x_invoice' => '123456789', - 'PT' => '1', - 'x_control' => '0656B92DF44B814D48D84FED2F444CCA1E991A24A365FBEECCCA15B73CC08C2A', - 'x_document' => '987654321', - 'x_bank' => 'TE', - 'x_payment_type' => '03', - 'x_bank_name' => 'GNB', - 'x_currency' => 'BRL', - ); - $results = $gateway->getTransactionData(); - $this->assertEquals( $expected, $results, - 'PaymentStatus response not interpreted correctly' ); - // Should not throw exception - $gateway->verifyStatusSignature( $results ); - } - - /** - * Invalid signature should be recognized as such. - */ - function testInvalidSignature() { - $init = $this->getDonorTestData( 'BR' ); - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $gateway = new TestingAstroPayAdapter(); - - $gateway->setDummyGatewayResponseCode( 'badsig' ); - $gateway->do_transaction( 'PaymentStatus' ); - - $results = $gateway->getTransactionData(); - $this->setExpectedException( 'ResponseProcessingException' ); - $gateway->verifyStatusSignature( $results ); - } - - /** - * If status is paid and signature is correct, processDonorReturn should not - * throw exception and final status should be 'completed' - */ - function testSuccessfulReturn() { - $init = $this->getDonorTestData( 'BR' ); - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $gateway = new TestingAstroPayAdapter(); - - $requestValues = array( - 'result' => '9', - 'x_amount' => '100.00', - 'x_amount_usd' => '42.05', - 'x_control' => 'DDF89085AC70C0B0628150C51D64419D8592769F2439E3936570E26D24881730', - 'x_description' => 'Donation to the Wikimedia Foundation', - 'x_document' => '32869', - 'x_iduser' => '08feb2d12771bbcfeb86', - 'x_invoice' => '123456789', - ); - - $result = $gateway->processDonorReturn( $requestValues ); - $this->assertFalse( $result->isFailed() ); - $status = $gateway->getFinalStatus(); - $this->assertEquals( FinalStatus::COMPLETE, $status ); - } - - /** - * Make sure we record the actual amount charged, even if the donor has - * opened a new window and screwed up their session data. - */ - function testReturnUpdatesAmount() { - $init = $this->getDonorTestData( 'BR' ); - $init['amount'] = '22.55'; // junk session data from another banner click - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $gateway = new TestingAstroPayAdapter(); - - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $this->assertEquals( '22.55', $amount ); - - $requestValues = array( - 'result' => '9', - 'x_amount' => '100.00', - 'x_amount_usd' => '42.05', - 'x_control' => 'DDF89085AC70C0B0628150C51D64419D8592769F2439E3936570E26D24881730', - 'x_description' => 'Donation to the Wikimedia Foundation', - 'x_document' => '32869', - 'x_iduser' => '08feb2d12771bbcfeb86', - 'x_invoice' => '123456789', - ); - - $result = $gateway->processDonorReturn( $requestValues ); - $this->assertFalse( $result->isFailed() ); - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $this->assertEquals( '100.00', $amount, 'Not recording correct amount' ); - } - - /** - * If payment is rejected, final status should be 'failed' - */ - function testRejectedReturn() { - $init = $this->getDonorTestData( 'BR' ); - $session['Donor']['order_id'] = '123456789'; - $this->setUpRequest( $init, $session ); - $gateway = new TestingAstroPayAdapter(); - - $requestValues = array( - 'result' => '8', // rejected by bank - 'x_amount' => '100.00', - 'x_amount_usd' => '42.05', - 'x_control' => '706F57BC3E74906B14B1DEB946F027104513797CC62AC0F5107BC98F42D5DC95', - 'x_description' => 'Donation to the Wikimedia Foundation', - 'x_document' => '32869', - 'x_iduser' => '08feb2d12771bbcfeb86', - 'x_invoice' => '123456789', - ); - - $result = $gateway->processDonorReturn( $requestValues ); - $this->assertTrue( $result->isFailed() ); - $status = $gateway->getFinalStatus(); - $this->assertEquals( FinalStatus::FAILED, $status ); - } - - function testStageBankCode() { - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'elo'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->doPayment(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $bank_code = $exposed->getData_Staged( 'bank_code' ); - $this->assertEquals( 'EL', $bank_code, 'Not setting bank_code in doPayment' ); - } - - /** - * Test that we run the AntiFraud filters before redirecting - */ - function testAntiFraudFilters() { - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'cc'; - $init['bank_code'] = 'VD'; - // following data should trip fraud alarms - $init['utm_medium'] = 'somethingmedia'; - $init['utm_source'] = 'somethingmedia'; - $init['email'] = 'someb...@wikipedia.org'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failure if fraud filters say challenge' ); - $this->assertEquals( 'challenge', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 60, $exposed->risk_score, 'RiskScore is not as expected' ); - $message = DonationQueue::instance()->pop( 'payments-antifraud' ); - SourceFields::removeFromMessage( $message ); - $expected = array( - 'validation_action' => 'challenge', - 'risk_score' => 60, - 'score_breakdown' => array( - 'initial' => 0, - 'getScoreUtmCampaignMap' => 0, - 'getScoreCountryMap' => 0, - 'getScoreUtmSourceMap' => 10.5, - 'getScoreUtmMediumMap' => 12, - 'getScoreEmailDomainMap' => 37.5, - ), - 'user_ip' => '127.0.0.1', - 'gateway_txn_id' => false, - 'date' => $message['date'], - 'server' => gethostname(), - 'gateway' => 'astropay', - 'contribution_tracking_id' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'order_id' => $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'payment_method' => 'cc', - ); - $this->assertEquals( $expected, $message ); - } - - function testStageFiscalNumber() { - $init = $this->getDonorTestData( 'BR' ); - $init['fiscal_number'] = '000.034.567-89'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->doPayment(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $staged = $exposed->getData_Staged( 'fiscal_number' ); - $this->assertEquals( '00003456789', $staged, 'Not stripping fiscal_number punctuation in doPayment' ); - } - - /** - * We should increment the order ID with each NewInvoice call - */ - function testNewInvoiceOrderId() { - $init = $this->getDonorTestData( 'BR' ); - $firstRequest = $this->setUpRequest( $init ); - $firstAttempt = new TestingAstroPayAdapter(); - $firstAttempt->setDummyGatewayResponseCode( '1' ); - - $firstAttempt->doPayment(); - - $this->setUpRequest( $init, $firstRequest->getSessionArray() ); - $secondAttempt = new TestingAstroPayAdapter(); - $secondAttempt->doPayment(); - - parse_str( $firstAttempt->curled[0], $firstParams ); - parse_str( $secondAttempt->curled[0], $secondParams ); - - $this->assertNotEquals( $firstParams['x_invoice'], $secondParams['x_invoice'], - 'Not generating new order id for NewInvoice call' - ); - } - - /** - * We should increment the order ID with each NewInvoice call, even when - * retrying inside a single doPayment call - */ - function testNewInvoiceOrderIdRetry() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'collision' ); - - $gateway->doPayment(); - - parse_str( $gateway->curled[0], $firstParams ); - parse_str( $gateway->curled[1], $secondParams ); - - $this->assertNotEquals( $firstParams['x_invoice'], $secondParams['x_invoice'], - 'Not generating new order id for retried NewInvoice call' - ); - } - - /** - * We should show an error for incompatible country / currency combinations - */ - function testBadCurrencyForCountry() { - $init = $this->getDonorTestData( 'BR' ); - $init['currency'] = 'CLP'; - $gateway = $this->getFreshGatewayObject( $init ); - - $errorState = $gateway->getErrorState(); - - $this->assertTrue( - $errorState->hasValidationError( 'currency' ), - 'Should show a currency code error for trying to use CLP in BR' - ); - } - - function testDummyFiscalNumber() { - $init = $this->getDonorTestData( 'MX' ); - $init['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->doPayment(); - - parse_str( $gateway->curled[0], $firstParams ); - $fiscalNumber = $firstParams['x_cpf']; - $this->assertEquals( - 13, strlen( $fiscalNumber ), - 'Fake fiscal number should be 13 digits' - ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php deleted file mode 100644 index 9c23674..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php +++ /dev/null @@ -1,273 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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 GlobalCollect - */ -class GlobalCollectFormLoadTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $vmad_countries = array( 'US', ); - $vmaj_countries = array( - 'AD', 'AT', 'AU', 'BE', 'BH', 'DE', 'EC', 'ES', 'FI', 'FR', 'GB', - 'GF', 'GR', 'HK', 'IE', 'IT', 'JP', 'KR', 'LU', 'MY', 'NL', 'PR', - 'PT', 'SG', 'SI', 'SK', 'TH', 'TW', - ); - $vma_countries = array( - 'AE', 'AL', 'AN', 'AR', 'BG', 'CA', 'CH', 'CN', 'CR', 'CY', 'CZ', 'DK', - 'DZ', 'EE', 'EG', 'JO', 'KE', 'HR', 'HU', 'IL', 'KW', 'KZ', 'LB', 'LI', - 'LK', 'LT', 'LV', 'MA', 'MT', 'NO', 'NZ', 'OM', 'PK', 'PL', 'QA', 'RO', - 'RU', 'SA', 'SE', 'TN', 'TR', 'UA', - ); - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'discover' )), - 'countries' => array( - '+' => $vmad_countries, - ), - ), - 'cc-vmaj' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'jcb' )), - 'countries' => array( - '+' => $vmaj_countries, - ), - ), - 'cc-vma' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex' )), - 'countries' => array( - // Array merge with cc-vmaj as fallback in case 'j' goes down - // Array merge with cc-vmad as fallback in case 'd' goes down - '+' => array_merge( - $vmaj_countries, - $vmad_countries, - $vma_countries - ), - ), - ), - 'rtbt-sofo' => array( - 'gateway' => 'globalcollect', - 'countries' => array( - '+' => array( 'AT', 'BE', 'CH', 'DE' ), - '-' => 'GB' - ), - 'currencies' => array( '+' => 'EUR' ), - 'payment_methods' => array('rtbt' => 'rtbt_sofortuberweisung'), - ), - ), - ) ); - } - - public function testGCFormLoad() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmad'; - - $assertNodes = array ( - 'submethod-mc' => array ( - 'nodename' => 'input' - ), - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'USD', $init['language'] . '_' . $init['country'] ) - ). - '\s*$/', - ), - 'state_province' => array ( - 'nodename' => 'select', - 'selected' => 'CA', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - function testGCFormLoad_FR() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'value' => 'Prénom', - ), - 'last_name' => array ( - 'nodename' => 'input', - 'value' => 'Nom', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'FR', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Ensure that form loads for Italy - */ - public function testGlobalCollectFormLoad_IT() { - $init = $this->getDonorTestData( 'IT' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( 'it' )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( 'it' )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( 'it' )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'IT', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Belgian form loads in all of that country's supported languages - * @dataProvider belgiumLanguageProvider - */ - public function testGlobalCollectFormLoad_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - $init['language'] = $language; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( $language )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'BE', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Canadian CC form loads in English and French - * @dataProvider canadaLanguageProvider - */ - public function testGlobalCollectFormLoad_CA( $language ) { - $init = $this->getDonorTestData( 'CA' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vma'; - $init['language'] = $language; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'CAD', $init['language'] . '_' . $init['country'] ) - ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( $language )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'state_province' => array ( - 'nodename' => 'select', - 'selected' => 'SK', - ), - 'postal_code' => array ( - 'nodename' => 'input', - 'value' => $init['postal_code'], - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'CA', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php deleted file mode 100644 index 03a429e..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php +++ /dev/null @@ -1,211 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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. - * - */ - -use Psr\Log\LogLevel; -use SmashPig\Core\Configuration; -use SmashPig\Core\Context; -use SmashPig\CrmLink\Messages\SourceFields; -use Wikimedia\TestingAccessWrapper; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - * @group OrphanSlayer - */ -class DonationInterface_Adapter_GlobalCollect_Orphans_GlobalCollectTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $config = Configuration::createForView( 'globalcollect' ); - Context::initWithLogger( $config ); - - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'discover' )), - 'countries' => array( - '+' => array( 'US', ), - ), - ), - ), - ) ); - } - - /** - * @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 = 'TestingGlobalCollectOrphanAdapter'; - $this->dummy_utm_data = array ( - 'utm_source' => 'dummy_source', - 'utm_campaign' => 'dummy_campaign', - 'utm_medium' => 'dummy_medium', - 'date' => time(), - ); - } - - public function testConstructor() { - - $options = $this->getDonorTestData(); - $class = $this->testAdapterClass; - - $gateway = $this->getFreshGatewayObject(); - - $this->assertInstanceOf( $class, $gateway ); - - $this->verifyNoLogErrors(); - } - - - public function testBatchOrderID_generate() { - - //no data on construct, generate Order IDs - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Order_id generation may be broken.' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is not left as null, when generating our own' ); - - $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $data['order_id'] = '55555'; - - //now, add data and check that we didn't kill the oid. Still generating. - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '55555', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '444444'; - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '444444', 'loadDataAndReInit failed to stick OrderID' ); - - $this->verifyNoLogErrors(); - } - - public function testBatchOrderID_no_generate() { - - //no data on construct, do not generate Order IDs - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertFalse( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Deferred order_id generation may be broken.' ); - $this->assertEmpty( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); - - $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $data['order_id'] = '66666'; - - //now, add data and check that we didn't kill the oid. Still not generating - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '66666', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '777777'; - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '777777', 'loadDataAndReInit failed to stick OrderID on second batch item' ); - - $this->verifyNoLogErrors(); - } - - /** - * Tests to make sure that certain error codes returned from GC will - * trigger order cancellation, even if retryable errors also exist. - * @dataProvider mcNoRetryCodeProvider - */ - public function testNoMastercardFinesForRepeatOnBadCodes( $code ) { - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - - //Toxic card should not retry, even if there's an order id collision - $init = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = 'innoc...@clean.com'; - $init['contribution_tracking_id'] = mt_rand(); - $gateway->loadDataAndReInit( $init ); - - $gateway->setDummyGatewayResponseCode( $code ); - $result = $gateway->do_transaction( 'Confirm_CreditCard' ); - $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! MasterCard could fine us a thousand bucks for that!" ); - $this->assertEquals( false, $result->getCommunicationStatus(), "Error code $code should mean status of do_transaction is false" ); - $errors = $result->getErrors(); - $this->assertFalse( empty( $errors ), 'Orphan adapter needs to see the errors to consider it rectified' ); - $finder = function( $error ) { - return $error->getErrorCode() == '1000001'; - }; - $this->assertNotEmpty( array_filter( $errors, $finder ), 'Orphan adapter needs error 1000001 to consider it rectified' ); - $loglines = $this->getLogMatches( LogLevel::INFO, "/Got error code $code, not retrying to avoid MasterCard fines./" ); - $this->assertNotEmpty( $loglines, "GC Error $code is not generating the expected payments log error" ); - } - - /** - * Make sure we're incorporating GET_ORDERSTATUS AVS and CVV responses into - * fraud scores. - */ - function testGetOrderstatusPostProcessFraud() { - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableCustomFilters' => true, - 'wgGlobalCollectGatewayCustomFiltersFunctions' => array( - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - ) ); - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - - $init = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = 'innoc...@manichean.com'; - $init['contribution_tracking_id'] = mt_rand(); - $init['payment_method'] = 'cc'; - - $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'review', $action, - 'Orphan gateway should fraud fail on bad CVV and AVS' ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 40, $exposed->risk_score, - 'Risk score was incremented correctly.' ); - $message = DonationQueue::instance()->pop( 'payments-antifraud' ); - SourceFields::removeFromMessage( $message ); - $expected = array( - 'validation_action' => 'review', - 'risk_score' => 40, - 'score_breakdown' => array( - // FIXME: need to enable utm / email / country checks ??? - 'initial' => 0, - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - 'user_ip' => null, // FIXME - 'gateway_txn_id' => '55555', - 'date' => $message['date'], - 'server' => gethostname(), - 'gateway' => 'globalcollect', - 'contribution_tracking_id' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'order_id' => $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'payment_method' => 'cc', - ); - $this->assertEquals( $expected, $message ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php b/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php deleted file mode 100644 index f56357f..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - */ -class DonationInterface_Adapter_GlobalCollect_ResultSwitcherTest extends DonationInterfaceTestCase { - protected $testAdapterClass = 'TestingGlobalCollectAdapter'; - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( - array( - 'wgGlobalCollectGatewayEnabled' => true, - ) - ); - } - - /** - * Assuming we've popped out of the frame, does processing succeed? - */ - public function testResultSwitcherLiberatedSuccess() { - $donorTestData = $this->getDonorTestData( 'FR' ); - $donorTestData['payment_method'] = 'cc'; - $donorTestData['payment_submethod'] = 'visa'; - $donorTestData['email'] = 'innoc...@localhost.net'; - $donorTestData['order_id'] = mt_rand(); - $session['Donor'] = $donorTestData; - // Mark the order as already popped out of the iframe - $session['order_status'][$donorTestData['order_id']] = 'liberated'; - $request = array( - 'REF' => $donorTestData['order_id'], - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0', - 'language' => 'fr', // FIXME: verifyFormOutput conflates request with other stuff - ); - $assertNodes = array( - 'headers' => array( - 'Location' => function( $location ) use ( $donorTestData ) { - // Do this after the real processing to avoid side effects - $gateway = $this->getFreshGatewayObject( $donorTestData ); - $url = ResultPages::getThankYouPage( $gateway ); - $this->assertEquals( $url, $location ); - } - ) - ); - - $this->verifyFormOutput( 'GlobalCollectGatewayResult', $request, $assertNodes, false, $session ); - // Make sure we logged the expected cURL attempts - $messages = $this->getLogMatches( 'info', '/Preparing to send GET_ORDERSTATUS transaction to Global Collect/' ); - $this->assertNotEmpty( $messages ); - $messages = $this->getLogMatches( 'info', '/Preparing to send SET_PAYMENT transaction to Global Collect/' ); - $this->assertNotEmpty( $messages ); - } -} diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php deleted file mode 100644 index d91347c..0000000 --- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php +++ /dev/null @@ -1,323 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch 'master' into deployment"") -======= -<?php -/** - * 'TIMESTAMP=2016%2d05%2d02T19%3a58%3a19Z&CORRELATIONID=b33e6ff7eba&ACK=Failure&VERSION=0%2e000000&BUILD=21669447&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call&L_SEVERITYCODE0=Error' - * - * TOKEN=EC%2d1YM52022PV490383V&PHONENUM=408%2d123%2d4567&BILLINGAGREEMENTACCEPTEDSTATUS=0&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2016%2d05%2d03T19%3a57%3a56Z&CORRELATIONID=c3811aeb1e7f5&ACK=Success&VERSION=124&BUILD=21669447&EMAIL=fr%2dtech%2bdonor%40wikimedia%2eorg&PAYERID=FLJLQ2GV38E4Y&PAYERSTATUS=verified&FIRSTNAME=f&LASTNAME=doner&COUNTRYCODE=US&ADDRESSSTATUS=Confirmed&CURRENCYCODE=JPY&AMT=500&ITEMAMT=500&SHIPPINGAMT=0&HANDLINGAMT=0&TAXAMT=0&CUSTOM=4116&DESC=Donation%20to%20the%20Wikimedia%20Foundation&INVNUM=4116&INSURANCEAMT=0&SHIPDISCAMT=0&INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_CURRENCYCODE=JPY&PAYMENTREQUEST_0_AMT=500&PAYMENTREQUEST_0_ITEMAMT=500&PAYMENTREQUEST_0_SHIPPINGAMT=0&PAYMENTREQUEST_0_HANDLINGAMT=0&PAYMENTREQUEST_0_TAXAMT=0&PAYMENTREQUEST_0_CUSTOM=4116&PAYMENTREQUEST_0_DESC=Donation%20to%20the%20Wikimedia%20Foundation&PAYMENTREQUEST_0_INVNUM=4116&PAYMENTREQUEST_0_INSURANCEAMT=0&PAYMENTREQUEST_0_SHIPDISCAMT=0&PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=fr%2dtech%2dfacilitator%40wikimedia%2eorg&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&PAYMENTREQUESTINFO_0_ERRORCODE=0 - * - * TIMESTAMP=2016%2d05%2d03T21%3a43%3a20Z&CORRELATIONID=f624ed5aa5db0&ACK=Failure&VERSION=124&BUILD=21669447&L_ERRORCODE0=10412&L_SHORTMESSAGE0=Duplicate%20invoice&L_LONGMESSAGE0=Payment%20has%20already%20been%20made%20for%20this%20InvoiceID%2e&L_SEVERITYCODE0=Error - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group PayPal - */ -class DonationInterface_Adapter_PayPal_Express_Test extends DonationInterfaceTestCase { - - protected $testAdapterClass = 'TestingPaypalExpressAdapter'; - - public function setUp() { - parent::setUp(); - DonationInterface::initializeSmashPig( 'paypal' ); - $this->setMwGlobals( array( - 'wgDonationInterfaceCancelPage' => 'https://example.com/tryAgain.php', - 'wgPaypalExpressGatewayEnabled' => true, - 'wgDonationInterfaceThankYouPage' => 'https://example.org/wiki/Thank_You', - ) ); - } - - protected function unsetVariableFields( &$message ) { - $fields = array( - 'date', 'source_enqueued_time', 'source_host', 'source_run_id', 'source_version', 'gateway_account' - ); - foreach ( $fields as $field ) { - unset( $message[$field] ); - } - } - - function testPaymentSetup() { - $init = array( - 'amount' => 1.55, - 'currency' => 'USD', - 'payment_method' => 'paypal', - 'utm_source' => 'CD1234_FR', - 'utm_medium' => 'sitenotice', - 'country' => 'US', - 'contribution_tracking_id' => strval( mt_rand() ), - 'language' => 'fr', - ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); - $result = $gateway->doPayment(); - $gateway->logPending(); // GatewayPage calls this for redirects - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8US12345X1234567U', - $result->getRedirect(), - 'Wrong redirect for PayPal EC payment setup' - ); - $message = DonationQueue::instance()->pop( 'pending' ); - $this->assertNotEmpty( $message, 'Missing pending message' ); - $this->unsetVariableFields( $message ); - $expected = array( - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => null, - 'language' => 'fr', - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'utm_source' => 'CD1234_FR..paypal', - 'currency' => 'USD', - 'email' => '', - 'gross' => '1.55', - 'recurring' => '', - 'response' => false, - 'utm_medium' => 'sitenotice', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'gateway_session_id' => 'EC-8US12345X1234567U', - 'user_ip' => '127.0.0.1', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - ); - $this->assertEquals( - $expected, - $message, - 'PayPal EC setup sending wrong pending message' - ); - } - - /** - * Check that the adapter makes the correct calls for successful donations - * and sends a good queue message. - */ - function testProcessDonorReturn() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); - $gateway->processDonorReturn( array( - 'token' => 'EC%2d4V987654XA123456V', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - 'gateway_session_id' => 'EC-4V987654XA123456V', - 'language' => 'en', - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'response' => false, - 'user_ip' => '127.0.0.1', - 'utm_source' => '..paypal', - 'city' => 'San Francisco', - 'currency' => 'USD', - 'email' => 'do...@generous.net', - 'first_name' => 'Fezziwig', - 'gross' => '1.55', - 'last_name' => 'Fowl', - 'recurring' => '', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'postal_code' => '94105', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - ); - $this->assertEquals( $expected, $message ); - - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending extra messages to donations queue!' - ); - } - - public function testProcessDonorReturnRecurring() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['recurring'] = '1'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'Recurring-OK' ); - $gateway->processDonorReturn( array( - 'token' => 'EC%2d4V987654XA123456V', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - 'gateway_session_id' => 'EC-4V987654XA123456V', - 'language' => 'en', - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'response' => false, - 'user_ip' => '127.0.0.1', - 'utm_source' => '..rpaypal', - 'city' => 'San Francisco', - 'currency' => 'USD', - 'email' => 'do...@generous.net', - 'first_name' => 'Fezziwig', - 'gross' => '1.55', - 'last_name' => 'Fowl', - 'recurring' => '1', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'postal_code' => '94105', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - 'subscr_id' => 'I-88J1M3DLSF0', - ); - $this->assertEquals( $expected, $message ); - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending extra messages to donations queue!' - ); - } - - /** - * Check that we send the donor back to paypal to try a different source - */ - function testProcessDonorReturnPaymentRetry() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); - $result = $gateway->processDonorReturn( array( - 'token' => 'EC%2d2D123456D9876543U', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNull( $message, 'Should not queue a message' ); - $this->assertFalse( $result->isFailed() ); - $redirect = $result->getRedirect(); - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2D123456D9876543U', - $redirect - ); - } - - public function testProcessDonorReturnRecurringRetry() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['recurring'] = '1'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); - $result = $gateway->processDonorReturn( array( - 'token' => 'EC%2d2D123456D9876543U', - 'PayerID' => 'ASDASD' - ) ); - - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending a spurious message to the donations queue!' - ); - $this->assertFalse( $result->isFailed() ); - $redirect = $result->getRedirect(); - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2D123456D9876543U', - $redirect - ); - } - - /** - * The result switcher should redirect the donor to the thank you page and mark the token as - * processed. - */ - public function testResultSwitcher() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['gateway_session_id'] = mt_rand(); - $init['language'] = 'pt'; - $session = array( 'Donor' => $init ); - - $request = array( - 'token' => $init['gateway_session_id'], - 'PayerID' => 'ASdASDAS', - 'language' => $init['language'] // FIXME: mashing up request vars and other stuff in verifyFormOutput - ); - $assertNodes = array( - 'headers' => array( - 'Location' => function( $location ) use ( $init ) { - // Do this after the real processing to avoid side effects - $gateway = $this->getFreshGatewayObject( $init ); - $url = ResultPages::getThankYouPage( $gateway ); - $this->assertEquals( $url, $location ); - } - ) - ); - - $this->verifyFormOutput( 'PaypalExpressGatewayResult', $request, $assertNodes, false, $session ); - $processed = RequestContext::getMain()->getRequest()->getSessionData( 'processed_requests' ); - $this->assertArrayHasKey( $request['token'], $processed ); - - // Make sure we logged the expected cURL attempts - $messages = $this->getLogMatches( 'info', '/Preparing to send GetExpressCheckoutDetails transaction to Paypal Express Checkout/' ); - $this->assertNotEmpty( $messages ); - $messages = $this->getLogMatches( 'info', '/Preparing to send DoExpressCheckoutPayment transaction to Paypal Express Checkout/' ); - $this->assertNotEmpty( $messages ); - } - - /** - * The result switcher should redirect the donor to the thank you page without - * re-processing the donation. - */ - public function testResultSwitcherRepeat() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['gateway_session_id'] = mt_rand(); - $init['language'] = 'pt'; - $session = array( - 'Donor' => $init, - 'processed_requests' => array( - $init['gateway_session_id'] => true - ) - ); - - $request = array( - 'token' => $init['gateway_session_id'], - 'PayerID' => 'ASdASDAS', - 'language' => $init['language'] // FIXME: mashing up request vars and other stuff in verifyFormOutput - ); - $assertNodes = array( - 'headers' => array( - 'Location' => function( $location ) use ( $init ) { - // Do this after the real processing to avoid side effects - $gateway = $this->getFreshGatewayObject( $init ); - $url = ResultPages::getThankYouPage( $gateway ); - $this->assertEquals( $url, $location ); - } - ) - ); - - $this->verifyFormOutput( 'PaypalExpressGatewayResult', $request, $assertNodes, false, $session ); - - // We should not have logged any cURL attempts - $messages = $this->getLogMatches( 'info', '/Preparing to send .*/' ); - $this->assertEmpty( $messages ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php b/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php deleted file mode 100644 index 059bd19..0000000 --- a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php +++ /dev/null @@ -1,336 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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_Legacy_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 = 'TestingPaypalLegacyAdapter'; - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceCancelPage' => 'https://example.com/tryAgain.php', - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceThankYouPage' => 'https://example.org/wiki/Thank_You', - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'paypal' => array( - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - ), - 'paypal-recurring' => array( - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - 'recurring', - ), - ), - ) ); - } - - public function tearDown() { - TestingPaypalLegacyAdapter::$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'], - 'country' => $init['country'], - 'business' => 'phpunittest...@wikimedia.org', - '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->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), - "Paypal order_id should equal ct_id" - ); - } - - /** - * 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'], - 'country' => $init['country'], - 'business' => 'phpunittest...@wikimedia.org', - '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(); - - TestingPaypalLegacyAdapter::$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'], - 'country' => $init['country'], - 'business' => 'phpunittest...@wikimedia.org', - '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 ); - - $redirectTest = function( $location ) use ( $init ) { - parse_str( parse_url( $location, PHP_URL_QUERY ), $actual ); - $this->assertEquals( $init['amount'], $actual['amount'] ); - }; - $assertNodes = array( - 'headers' => array( - 'Location' => $redirectTest, - ) - ); - - $this->verifyFormOutput( 'PaypalLegacyGateway', $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( 'PaypalLegacyGateway', $init, $assertNodes, false, $session ); - } - - /** - * Stay on the payments form if there's a currency conversion notification. - */ - function testShowFormOnCurrencyFallback() { - $init = $this->getDonorTestData(); - $init['currency'] = 'BBD'; - $init['amount'] = 15.00; - $session = array( 'Donor' => $init ); - $this->setMwGlobals( array( - 'wgDonationInterfaceFallbackCurrency' => 'USD', - 'wgDonationInterfaceNotifyOnConvert' => true, - ) ); - $errorMessage = wfMessage( 'donate_interface-fallback-currency-notice', 'USD' )->text(); - $assertNodes = array( - 'headers' => array( - 'location' => null, - ), - 'currencyMsg' => array( - 'innerhtmlmatches' => "/.*$errorMessage.*/" - ) - ); - - $this->verifyFormOutput( 'PaypalLegacyGateway', $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'], - 'country' => 'BE', - 'business' => 'phpunittest...@wikimedia.org', - '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->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), - "Paypal order_id should equal ct_id" - ); - } - - /** - * 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' => 'phpunittest...@wikimedia.org', - '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->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), - "Paypal order_id should equal ct_id" - ); - } - - /** - * 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'], - 'country' => 'IT', - 'business' => 'phpunittest...@wikimedia.org', - '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->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), - "Paypal order_id should equal ct_id" - ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/DataValidatorTest.php b/tests/phpunit/DataValidatorTest.php deleted file mode 100644 index 1394ee1..0000000 --- a/tests/phpunit/DataValidatorTest.php +++ /dev/null @@ -1,159 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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 Validation - * @category UnitTesting - */ -class DataValidatorTest extends PHPUnit_Framework_TestCase { - /** - * Test the Luhn check algorithm - * @dataProvider luhnDataProvider - */ - public function testLuhnCheck( $number, $expresult, $helpful_message ) { - $result = DataValidator::cc_number_exists_in_str( $number ); - $this->assertEquals( $expresult, $result, "$number failed expected luhn check ($helpful_message)" ); - } - - public function luhnDataProvider() { - return array( - // Mastercard - array ( '5333331605740535', true, 'Mastercard' ), - array ( '5143792293131636', true, 'Mastercard' ), - array ( 'John Doe 5199122553269905 Random', true, 'Mastercard' ), - array ( '5497-8801-7320-5943', true, 'Mastercard' ), - array ( '5370 5369 5295 3903', true, 'Mastercard' ), - array ( '5295975049354398', true, 'Mastercard' ), - array ( '5122728197617259', true, 'Mastercard' ), - array ( '5372869474419840', true, 'Mastercard' ), - array ( '5479089850576103', true, 'Mastercard' ), - array ( '5375122664558457', true, 'Mastercard' ), - // VISA array(16), digit - array ( '4024007145540307', true, 'Visa 16 digit' ), - array ( '4532676809474030', true, 'Visa 16 digit' ), - array ( '4024007139174626', true, 'Visa 16 digit' ), - array ( '4556384391069166', true, 'Visa 16 digit' ), - array ( '4916423001204113', true, 'Visa 16 digit' ), - array ( '4716409516522919', true, 'Visa 16 digit' ), - array ( '4296465885589572', true, 'Visa 16 digit' ), - array ( '4532969094459737', true, 'Visa 16 digit' ), - array ( '4485480938896362', true, 'Visa 16 digit' ), - array ( '4539357366702682', true, 'Visa 16 digit' ), - // VISA array(13), digit - array ( '4916199124929', true, 'Visa 13 digit' ), - array ( '4916237697951', true, 'Visa 13 digit' ), - array ( '4929247091115', true, 'Visa 13 digit' ), - array ( '4024007169572', true, 'Visa 13 digit' ), - array ( '4716716919391', true, 'Visa 13 digit' ), - // American Express - array ( '343114236688284', true, 'Amex' ), - array ( '379274178561225', true, 'Amex' ), - // Discover - array ( '6011013905647431', true, 'Discover' ), - array ( '6011045341391380', true, 'Discover' ), - array ( '6011324325736120', true, 'Discover' ), - // Diners Club is not currently working at all - /** - array ( '30343484937451', true, 'Diners Club' ), - array ( '30037415730064', true, 'Diners Club' ), - array ( '30392872026500', true, 'Diners Club' ), - */ - // enRoute - array ( '201454799826249', true, 'enRoute' ), - array ( '201498205795993', true, 'enRoute' ), - array ( '214960886496931', true, 'enRoute' ), - // JCB - array ( '3582219461343499', true, 'JCB' ), - array ( '3534022982879267', true, 'JCB' ), - //not sure what is wrong with the next one, but it's failing - //array ( '3519002211673029', true, 'JCB' ), - // Voyager is also not currently working at all - /** - array ( '869952786819898', true, 'Voyager' ), - array ( '869967184704708', true, 'Voyager' ), - array ( '869901879171733', true, 'Voyager' ), - */ - // Not credit cards - array ( 'John Doe', false, 'Not a valid credit card' ), - array ( 'Peter 123456', false, 'Not a valid credit card' ), - array ( '1234567', false, 'Not a valid credit card' ) - ); - } - - /** - * Oh Shit: It's an actual simple unit test! - * @covers DataValidator::getZeroPaddedValue() - */ - public function testGetZeroPaddedValue() { - //make sure that it works in the two main categories of ways it should work - $this->assertEquals( '00123', DataValidator::getZeroPaddedValue( '123', 5 ), "getZeroPaddedValue does not properly pad out a value in the simplest case" ); - $this->assertEquals( '00123', DataValidator::getZeroPaddedValue( '0000123', 5 ), "getZeroPaddedValue does not properly unpad and re-pad a value when leading zeroes exist in the initial value" ); - - //make sure it fails gracefully when asked to do something silly. - $this->assertFalse( DataValidator::getZeroPaddedValue( '123456', 5 ), "getZeroPaddedValue does not return false when the exact desired value is impossible" ); - } - - public function fiscalNumberProvider() { - return array( - array( 'BR', '', false ), // empty not OK for BR - array( 'US', '', true ), // empty OK for US - array( 'BR', '12345', false ), // too short for BR - array( 'BR', '00003456789', true ), - array( 'BR', '000.034.567-89', true ), // strip punctuation - array( 'BR', '00.000.000/0001-00', true ), // CPNJ should pass too - array( 'BR', '1111222233334444', false ), - array( 'BR', 'ABC11122233', false ), - array( 'CL', '12.123.123-K', true ), - array( 'CL', '12.12.12-4', false ), - array( 'CO', '123-456', true ), - array( 'CO', '1234-5678-90', true ), - array( 'CO', '12A-456-7', false ), - array( 'CO', '1234-5678-901', false ), - array( 'AR', 'ABC12312', false ), - array( 'AR', '12341234', true ), - array( 'AR', '12-34123412-1', true ), // 11 digit CUIT should pass - array( 'AR', '1112223', true ), - array( 'AR', '111222', false ), - array( 'MX', '', true ), // Not required for MX - ); - } - - /** - * @dataProvider fiscalNumberProvider - * TODO: Test modular validator integration with DonationData - */ - public function testValidateFiscalNumber( $country, $value, $valid ) { - $validator = new FiscalNumber(); - $errors = new ErrorState(); - $validator->validate( - new TestingGenericAdapter(), - array( 'country' => $country, 'fiscal_number' => $value, 'language' => 'en' ), - $errors - ); - $expectation = $valid ? "should" : "should not"; - $this->assertEquals( - !$valid, - $errors->hasValidationError( 'fiscal_number' ), - "$value $expectation be a valid fiscal number for $country" - ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/FormChooserTest.php b/tests/phpunit/FormChooserTest.php deleted file mode 100644 index 85b5991..0000000 --- a/tests/phpunit/FormChooserTest.php +++ /dev/null @@ -1,128 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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 FormChooser - */ -class DonationInterface_FormChooserTest 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 = '' ) { - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableFormChooser' => true, - 'wgGlobalCollectGatewayEnabled' => true, - 'wgPaypalGatewayEnabled' => true, - ) ); - } - - function testGetOneValidForm_CC_SpecificCountry() { - $tests = array ( - 0 => array ( - 'country' => 'US', - 'payment_method' => 'cc', - 'currency' => 'USD', - 'expected' => 'cc-vmad' - ), - 1 => array ( - 'country' => 'DK', - 'payment_method' => 'cc', - 'currency' => 'DKK', - 'expected' => 'cc-vma' - ), - ); - - foreach ( $tests as $testno => $data ) { - $form = GatewayFormChooser::getOneValidForm( $data['country'], $data['currency'], $data['payment_method'] ); - $this->assertEquals( $data['expected'], $form, "$form is not the preferred option for " . $data['payment_method'] . ' in ' . $data['country'] ); - } - } - - function testMaintenanceMode_Redirect() { - - $this->setMwGlobals( array( - 'wgContributionTrackingFundraiserMaintenance' => true, - ) ); - - $expectedLocation = Title::newFromText('Special:FundraiserMaintenance')->getFullURL(); - $assertNodes = array( - 'headers' => array( - 'Location' => $expectedLocation - ), - ); - $initial = array( - 'language' => 'en' - ); - $this->verifyFormOutput( 'GatewayFormChooser', $initial, $assertNodes, false ); - } - - /** - * currency should take precedence over currency_code, payment_method - * over paymentmethod, etc. - */ - function testPreferCanonicalParams() { - $assertNodes = array( - 'headers' => array( - 'Location' => function( $val ) { - $qs = array(); - parse_str( parse_url( $val, PHP_URL_QUERY ), $qs ); - $this->assertEquals( 'paypal', $qs['ffname'], 'Wrong form' ); - } - ), - ); - $initial = array( - 'language' => 'en', - 'payment_method' => 'paypal', - 'paymentmethod' => 'amazon', - 'country' => 'US', - ); - $this->verifyFormOutput( 'GatewayFormChooser', $initial, $assertNodes, false ); - } - - /** - * Make sure none of the payment form settings are horribly broken. - */ - function testBuildAllFormUrls() { - global $wgDonationInterfaceAllowedHtmlForms; - foreach ( $wgDonationInterfaceAllowedHtmlForms as $ffname => $config ) { - if ( empty( $config['special_type'] ) || $config['special_type'] != 'error' ) { - $url = GatewayFormChooser::buildPaymentsFormURL( $ffname ); - $this->assertNotNull( $url ); - } - } - } -} - - ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/FraudFiltersTest.php b/tests/phpunit/FraudFiltersTest.php deleted file mode 100644 index 2d27a58..0000000 --- a/tests/phpunit/FraudFiltersTest.php +++ /dev/null @@ -1,91 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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. - * - */ - -use SmashPig\CrmLink\Messages\SourceFields; -use Wikimedia\TestingAccessWrapper; - -/** - * @group Fundraising - * @group DonationInterface - * @group FormChooser - */ -class DonationInterface_FraudFiltersTest extends DonationInterfaceTestCase { - - function testGCFraudFilters() { - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnableMinfraud' => true, - 'wgDonationInterfaceMinFraudServers' => array('0.0.0.0'), - ) ); - - $options = $this->getDonorTestData(); - $options['email'] = 'someb...@wikipedia.org'; - $options['payment_method'] = 'cc'; - - $gateway = $this->getFreshGatewayObject( $options ); - - $gateway->runAntifraudFilters(); - - $this->assertEquals( 'reject', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 107.5, $exposed->risk_score, 'RiskScore is not as expected for failure mode' ); - $message = DonationQueue::instance()->pop( 'payments-antifraud' ); - SourceFields::removeFromMessage( $message ); - $expected = array( - 'validation_action' => 'reject', - 'risk_score' => 107.5, - 'score_breakdown' => array( - 'initial' => 0, - 'getScoreUtmCampaignMap' => 0, - 'getScoreCountryMap' => 20, - 'getScoreUtmSourceMap' => 0, - 'getScoreUtmMediumMap' => 0, - 'getScoreEmailDomainMap' => 37.5, - 'getCVVResult' => 0, - 'getAVSResult' => 0, - 'minfraud_filter' => 50, - ), - 'user_ip' => '127.0.0.1', - 'gateway_txn_id' => false, - 'date' => $message['date'], - 'server' => gethostname(), - 'gateway' => 'globalcollect', - 'contribution_tracking_id' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'order_id' => $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'payment_method' => 'cc', - ); - $this->assertEquals( $expected, $message ); - } -} -// Stub out Minfraud class for CI tests -if ( !class_exists( 'CreditCardFraudDetection' ) ) { - class CreditCardFraudDetection{ - public $server; - public function filter_field( $a, $b ) { - return 'blah'; - } - public function query() {} - public function input( $a ) {} - public function output() { - return array(); - } - } -} - ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/TestConfiguration.php b/tests/phpunit/TestConfiguration.php deleted file mode 100644 index 84d1b52..0000000 --- a/tests/phpunit/TestConfiguration.php +++ /dev/null @@ -1,247 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch '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. - * - * This file contains custom options and constants for test configuration. - */ - -/** - * TESTS_MESSAGE_NOT_IMPLEMENTED - * - * Message for code that has not been implemented. - */ -define( 'TESTS_MESSAGE_NOT_IMPLEMENTED', 'Not implemented yet!' ); - -/** - * TESTS_HOSTNAME - * - * The hostname for the system - */ -define( 'TESTS_HOSTNAME', 'localhost' ); - -/** - * TESTS_EMAIL - * - * An email address to use in case test send mail - */ -define( 'TESTS_EMAIL', 'nob...@wikimedia.org' ); - -/** - * TESTS_GATEWAY_DEFAULT - * - * This is the default gateway that will be used to implement unit tests. - */ -define( 'TESTS_GATEWAY_DEFAULT', 'GlobalCollectGateway' ); - -/** - * TESTS_ADAPTER_DEFAULT - * - * This is the default adapter that will be used to implement unit tests. - */ -define( 'TESTS_ADAPTER_DEFAULT', 'TestingGlobalCollectAdapter' ); - -global $wgDonationInterfaceTestMode, - $wgDonationInterfaceMerchantID, - $wgDonationInterfaceGatewayAdapters, - $wgDonationInterfaceAllowedHtmlForms, - $wgDonationInterfaceThankYouPage, - $wgGlobalCollectGatewayAccountInfo, - $wgPaypalGatewayAccountInfo, - $wgPaypalGatewayReturnURL, - $wgPaypalExpressGatewayURL, - $wgPaypalExpressGatewayTestingURL, - $wgPaypalExpressGatewaySignatureURL, - $wgPaypalExpressGatewayAccountInfo, - $wgAmazonGatewayReturnURL, - $wgAmazonGatewayAccountInfo, - $wgAdyenGatewayURL, - $wgAdyenGatewayAccountInfo, - $wgAstroPayGatewayURL, - $wgAstroPayGatewayTestingURL, - $wgAstroPayGatewayAccountInfo, - $wgAstroPayGatewayFallbackCurrency, - $wgMinFraudLicenseKey, - $wgMinFraudTimeout, - $wgDonationInterfaceMinFraudServers, - $wgDonationInterfaceEnableMinfraud, - $wgDonationInterfaceEnableFunctionsFilter, - $wgDonationInterfaceEnableReferrerFilter, - $wgDonationInterfaceEnableSourceFilter, - $wgDonationInterfaceCustomFiltersActionRanges, - $wgDonationInterfaceCustomFiltersRefRules, - $wgDonationInterfaceCustomFiltersSrcRules, - $wgDonationInterfaceCustomFiltersFunctions, - $wgGlobalCollectGatewayCustomFiltersFunctions, - $wgDonationInterfaceCountryMap, - $wgDonationInterfaceUtmCampaignMap, - $wgDonationInterfaceUtmSourceMap, - $wgDonationInterfaceUtmMediumMap, - $wgDonationInterfaceEmailDomainMap; - -$wgDonationInterfaceGatewayAdapters = array( - 'globalcollect'=> 'TestingGlobalCollectAdapter', - 'amazon'=> 'TestingAmazonAdapter', - 'adyen'=> 'TestingAdyenAdapter', - 'astropay'=> 'TestingAstroPayAdapter', - 'paypal_ec'=> 'TestingPaypalExpressAdapter', - 'paypal'=> 'TestingPaypalLegacyAdapter' -); -/** - * Make sure the test setup is used, else we'll have the wrong classes. - */ -/** DonationInterface General Settings **/ -$wgDonationInterfaceTestMode = true; -$wgDonationInterfaceMerchantID = 'test'; - -$wgDonationInterfaceThankYouPage = 'https://wikimediafoundation.org/wiki/Thank_You'; - - -/** GlobalCollect **/ -$wgGlobalCollectGatewayAccountInfo = array(); -$wgGlobalCollectGatewayAccountInfo['test'] = array( - 'MerchantID' => 'test', -); - - -/** Paypal **/ -$wgPaypalGatewayAccountInfo = array(); -$wgPaypalGatewayAccountInfo['testing'] = array( - 'AccountEmail' => 'phpunittest...@wikimedia.org', -); -$wgPaypalGatewayReturnURL = 'http://donate.wikimedia.org'; // whatever, doesn't matter. - - -/** Paypal Express Checkout **/ -$wgPaypalExpressGatewayURL = 'https://api-3t.sandbox.paypal.com/nvp'; -$wgPaypalExpressGatewayTestingURL = 'https://api-3t.sandbox.paypal.com/nvp'; -$wgPaypalExpressGatewaySignatureURL = $wgPaypalExpressGatewayURL; -$wgPaypalExpressGatewayAccountInfo['test'] = array( - 'User' => 'phpunittest...@wikimedia.org', - 'Password' => '9876543210', - 'Signature' => 'ABCDEFGHIJKLMNOPQRSTUV-ZXCVBNMLKJHGFDSAPOIUYTREWQ', - 'RedirectURL' => 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=', -); - - -/** Amazon **/ -$wgAmazonGatewayReturnURL = 'https://payments.wikimedia.org/index.php/Special:AmazonGateway'; -$wgAmazonGatewayAccountInfo = array(); -$wgAmazonGatewayAccountInfo['test'] = array( - 'SellerID' => 'ABCDEFGHIJKL', - 'ClientID' => 'amzn1.application-oa2-client.1a2b3c4d5e', - 'ClientSecret' => '12432g134e3421a41234b1341c324123d', - 'MWSAccessKey' => 'N0NSENSEXYZ', - 'MWSSecretKey' => 'iuasd/2jhaslk2j49lkaALksdJLsJLas+', - 'Region' => 'us', - 'WidgetScriptURL' => - 'https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js', - 'ReturnURL' => "https://example.org/index.php/Special:AmazonGateway?debug=true", -); - -/** Adyen **/ -$wgAdyenGatewayURL = 'https://testorwhatever.adyen.com'; -$wgAdyenGatewayAccountInfo = array(); -$wgAdyenGatewayAccountInfo['test'] = array( - 'AccountName' => 'wikitest', - 'SharedSecret' => 'C7F1D9E29479CF18131063A742CD2703FB9D48BAB0160693045E3FB7B8508E59', - 'SkinCode' => 'testskin', -); - -/** AstroPay **/ -$wgAstroPayGatewayURL = 'https://astropay.example.com/'; -$wgAstroPayGatewayTestingURL = 'https://sandbox.astropay.example.com/'; -$wgAstroPayGatewayAccountInfo = array(); -$wgAstroPayGatewayAccountInfo['test'] = array( - 'Create' => array( - 'Login' => 'createlogin', - 'Password' => 'createpass', - ), - 'Status' => array( - 'Login' => 'statuslogin', - 'Password' => 'statuspass', - ), - 'SecretKey' => 'NanananananananananananananananaBatman', -); -$wgAstroPayGatewayFallbackCurrency = false; - -$wgMinFraudLicenseKey = 'testkey'; -$wgMinFraudTimeout = 1; -$wgDonationInterfaceMinFraudServers = array( "minfraud.wikimedia.org" ); - -// still can't quite handle minfraud by itself yet, so default like this. -// I will turn it on for individual tests in which I want to verify that it at -// least fails closed when enabled. -$wgDonationInterfaceEnableMinfraud = false; - -// ...but we want these. -$wgDonationInterfaceEnableFunctionsFilter = true; -$wgDonationInterfaceEnableReferrerFilter = true; -$wgDonationInterfaceEnableSourceFilter = true; - -$customFilters = array( - 'getScoreCountryMap' => 50, - 'getScoreUtmCampaignMap' => 50, - 'getScoreUtmSourceMap' => 15, - 'getScoreUtmMediumMap' => 15, - 'getScoreEmailDomainMap' => 75, -); - - -$wgDonationInterfaceCustomFiltersActionRanges = array ( - 'process' => array ( 0, 25 ), - 'review' => array ( 25, 50 ), - 'challenge' => array ( 50, 75 ), - 'reject' => array ( 75, 100 ), -); - -$wgDonationInterfaceCustomFiltersRefRules = array ( - '/donate-error/i' => 5, -); - -$wgDonationInterfaceCustomFiltersSrcRules = array ( '/wikimedia\.org/i' => 80 ); - -$wgDonationInterfaceCustomFiltersFunctions = $customFilters; - -$wgGlobalCollectGatewayCustomFiltersFunctions = array( - 'getCVVResult' => 20, - 'getAVSResult' => 25, -) + $customFilters; - -$wgDonationInterfaceCountryMap = array ( - 'US' => 40, - 'CA' => 15, - 'RU' => -4, -); - -$wgDonationInterfaceUtmCampaignMap = array ( - '/^(C14_)/' => 14, - '/^(spontaneous)/' => 5 -); - -$wgDonationInterfaceUtmSourceMap = array ( - '/somethingmedia/' => 70 -); - -$wgDonationInterfaceUtmMediumMap = array ( - '/somethingmedia/' => 80 -); - -$wgDonationInterfaceEmailDomainMap = array ( - 'wikimedia.org' => 42, - 'wikipedia.org' => 50, -); ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") diff --git a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php b/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php deleted file mode 100644 index 2840592..0000000 --- a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php +++ /dev/null @@ -1,62 +0,0 @@ -<<<<<<< HEAD (a977e5 Revert "Revert "Merge branch 'master' into deployment"") -======= -<?php - -/** - * FIXME so much: DRY - */ -class TestingPaypalExpressAdapter extends PaypalExpressAdapter { - protected $dummyGatewayResponseCode = 'OK'; - - /** - * 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; - } - - /** - * Load in some dummy response XML so we can test proper response processing - */ - protected function curl_exec( $ch ) { - $code = ''; - if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) { - $code = '_' . $this->dummyGatewayResponseCode; - } - - //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 = __DIR__ . '/../'; - $file_path .= 'Responses' . '/' . self::getIdentifier() . '/'; - $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 ); - } - throw new RuntimeException( "File $file_path does not exist." ); - } - - /** - * 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, - ); - } -} ->>>>>>> BRANCH (3ce4f1 Merge "One more bit of $that = $this cleanup") -- To view, visit https://gerrit.wikimedia.org/r/363972 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I95d4dbd09b532a2d4a9d62c209dce13de92f9bb6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits