jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/353913 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment 7299f382 Localisation updates from https://translatewiki.net. 707e1ead Localisation updates from https://translatewiki.net. 4d321740 Localisation updates from https://translatewiki.net. 642fff22 Localisation updates from https://translatewiki.net. 718e8478 Encapsulate errors 9646ffdb Update translated error messages for new scheme d4d9eea5 Fix PP express for new encapsulated errors 45448a69 Localisation updates from https://translatewiki.net. 328686d1 Deal with retry errors in pp recurring bff2710d Don't crash error form on missing keys d41c81d5 Localisation updates from https://translatewiki.net. da5ef691 Localisation updates from https://translatewiki.net. 8604b41b Localisation updates from https://translatewiki.net. af8e633a Log session IDs when adding info & failing to find it Change-Id: I61c2d83a0d5b5553c75ccdd1b363987755a4618e --- D tests/phpunit/Adapter/Amazon/AmazonTest.php D tests/phpunit/Adapter/AstroPay/AstroPayTest.php D tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php D tests/phpunit/Adapter/PayPal/PayPalExpressTest.php D tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php D tests/phpunit/AmountTest.php D tests/phpunit/DataValidatorTest.php D tests/phpunit/GatewayPageTest.php D tests/phpunit/GatewayValidationTest.php A tests/phpunit/LintYaml.php D tests/phpunit/includes/test_gateway/TestingGenericAdapter.php 11 files changed, 50 insertions(+), 2,447 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php b/tests/phpunit/Adapter/Amazon/AmazonTest.php deleted file mode 100644 index 0a737dc..0000000 --- a/tests/phpunit/Adapter/Amazon/AmazonTest.php +++ /dev/null @@ -1,293 +0,0 @@ -<<<<<<< HEAD (b33d3e 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(); - - 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 ); - - $that = $this; //needed for PHP pre-5.4 - $convertTest = function( $amountString ) use ( $expectedDisplayAmount, $that ) { - $that->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['fname'] ); - unset( $init['lname'] ); - - $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( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( '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_code'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); - $message = DonationQueue::instance()->pop( 'complete' ); - $this->assertNotNull( $message, 'Not sending a message to the complete 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['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'InvalidPaymentMethod'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->getRefresh(), 'Result should be a refresh on error' ); - $errors = $result->getErrors(); - $this->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['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'AmazonRejected'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - // Could assert something about errors after rebasing onto master - // $errors = $result->getErrors(); - // $this->assertTrue( isset( $errors['AmazonRejected'] ), 'AmazonRejected error should be set' ); - } - - /** - * When the transaction times out, just gotta fail it till we work out an - * asynchronous authorization flow - */ - function testTransactionTimedOut() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'TransactionTimedOut'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - } - - /** - * When the SDK throws an exceptions, we should handle it. - */ - function testClientException() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['fname'] ); - unset( $init['lname'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->exceptions['authorize'][] = new Exception( 'Test' ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $errors = $result->getErrors(); - - $this->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['fname'] ); - unset( $init['lname'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - // FIXME: PaymentResult->isFailed returns null for false - $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( '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_code'], $authorizeOnBillingAgreementDetailsArgs['currency_code'], 'Did not authorize correct currency code' ); - $message = DonationQueue::instance()->pop( 'complete' ); - $this->assertNotNull( $message, 'Not sending a message to the complete 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 (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php deleted file mode 100644 index 4173d93..0000000 --- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php +++ /dev/null @@ -1,552 +0,0 @@ -<<<<<<< HEAD (b33d3e 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; - -/** - * - * @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, - ) ); - } - - /** - * 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() { - DonationInterface_FraudFiltersTest::setupFraudMaps( $this ); - $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' ); - } - - 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_code'] = 'CLP'; - $gateway = $this->getFreshGatewayObject( $init ); - - $errorState = $gateway->getErrorState(); - - $this->assertTrue( - $errorState->hasValidationError( 'currency_code' ), - '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 (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php deleted file mode 100644 index d460c32..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php +++ /dev/null @@ -1,183 +0,0 @@ -<<<<<<< HEAD (b33d3e 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; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - * @group OrphanSlayer - */ -class DonationInterface_Adapter_GlobalCollect_Orphans_GlobalCollectTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $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.' ); - } -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php deleted file mode 100644 index a3ac3a7..0000000 --- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php +++ /dev/null @@ -1,191 +0,0 @@ -<<<<<<< HEAD (b33d3e 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(); - - $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_host', 'source_run_id', 'source_version', 'gateway_account' - ); - foreach ( $fields as $field ) { - unset( $message[$field] ); - } - } - - /** - * 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'; - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); - $gateway->processDonorReturn( array( - 'token' => 'EC%2d4V987654XA123456V', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'complete' ); - $this->assertNotNull( $message, 'Not sending a message to the complete queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - '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( 'complete' ), - 'Sending extra messages to complete 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( 'complete' ); - $this->assertNotNull( $message, 'Not sending a message to the complete queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - '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( 'complete' ), - 'Sending extra messages to complete 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'; - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); - $result = $gateway->processDonorReturn( array( - 'token' => 'EC%2d2D123456D9876543U', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'complete' ); - $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( 'complete' ), - 'Sending a spurious message to the complete 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 - ); - } - -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php b/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php deleted file mode 100644 index 827d8bb..0000000 --- a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php +++ /dev/null @@ -1,337 +0,0 @@ -<<<<<<< HEAD (b33d3e 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_code'], - '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_code'], - '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_code'], - '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 ); - - $that = $this; - $redirectTest = function( $location ) use ( $that, $init ) { - parse_str( parse_url( $location, PHP_URL_QUERY ), $actual ); - $that->assertEquals( $init['amount'], $actual['amount'] ); - }; - $assertNodes = array( - 'headers' => array( - 'Location' => $redirectTest, - ) - ); - - $this->verifyFormOutput( '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, - ), - 'currency_codeMsg' => 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_code'], - '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_code'], - '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 (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/AmountTest.php b/tests/phpunit/AmountTest.php deleted file mode 100644 index 8506e70..0000000 --- a/tests/phpunit/AmountTest.php +++ /dev/null @@ -1,250 +0,0 @@ -<<<<<<< HEAD (b33d3e 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 - */ -class AmountTest extends DonationInterfaceTestCase { - - /** - * @var GatewayType - */ - protected $adapter; - /** - * @var Amount - */ - protected $validator; - /** - * @var ErrorState - */ - protected $errors; - /** - * @var array - */ - protected $normalized; - - public function setUp() { - parent::setUp(); - $this->setMwGlobals( array( - 'wgDonationInterfacePriceFloor' => 1.50, - 'wgDonationInterfacePriceCeiling' => 100, - 'wgLanguageCode' => 'en', - ) ); - - $this->setUpRequest( array( - 'country' => 'US', - 'uselang' => 'en', - ) ); - - $this->normalized = array( - 'language' => 'en', - 'country' => 'US', - 'currency_code' => 'USD', - ); - - $this->errors = new ErrorState(); - $this->adapter = new TestingGenericAdapter(); - $this->validator = new Amount(); - } - - protected function validate() { - $this->validator->validate( - $this->adapter, $this->normalized, $this->errors - ); - } - - protected function getFirstError() { - $list = $this->errors->getErrors(); - return $list[0]; - } - - public function testValidUsd() { - $this->normalized['amount'] = '10.00'; - $this->validate(); - $this->assertFalse( - $this->errors->hasValidationError(), - 'Error shown for valid amount' - ); - } - - public function testZeroAmount() { - $this->normalized['amount'] = '0.00'; - $this->validate(); - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for zero amount' - ); - $expected = DataValidator::getError( 'amount', 'not_empty' ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error for zero amount' - ); - } - - public function testWhitespaceAmount() { - $this->normalized['amount'] = ' '; - $this->validate(); - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for whitespace amount' - ); - $expected = DataValidator::getError( 'amount', 'not_empty' ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error for zero amount' - ); - } - - public function testNonNumericAmount() { - $this->normalized['amount'] = 'XYZ123'; - $this->validate(); - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for non-numeric amount' - ); - - $expected = new ValidationError( - 'amount', - 'donate_interface-error-msg-invalid-amount' - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for non-numeric amount' - ); - } - - public function testNegativeAmount() { - $this->normalized['amount'] = '-100.00'; - $this->validate(); - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for negative amount' - ); - - $expected = new ValidationError( - 'amount', - 'donate_interface-error-msg-invalid-amount' - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for non-numeric amount' - ); - } - - public function testTooMuchUsd() { - $this->normalized['amount'] = '101.00'; - $this->validate(); - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for excessive amount (USD)' - ); - $expected = new ValidationError( - 'amount', - 'donate_interface-bigamount-error', - array( - 100, - 'USD', - $this->adapter->getGlobal( 'MajorGiftsEmail' ), - ) - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for excessive amount (USD)' - ); - } - - public function testTooLittleUsd() { - $this->normalized['amount'] = '1.49'; - $this->validate(); - - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for diminutive amount (USD)' - ); - - $formattedMin = Amount::format( 1.50, 'USD', 'en_US' ); - $expected = new ValidationError( - 'amount', - 'donate_interface-smallamount-error', - array( $formattedMin ) - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for diminutive amount (USD)' - ); - } - - // Conversion tests depend on Barbadian monetary policy - // BBD is convenient as it's pegged to $0.50 - public function testTooMuchBbd() { - $this->normalized['currency_code'] = 'BBD'; - $this->normalized['amount'] = '201.00'; - $this->validate(); - - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for excessive amount (BBD)' - ); - $expected = new ValidationError( - 'amount', - 'donate_interface-bigamount-error', - array( - 200, - 'BBD', - $this->adapter->getGlobal( 'MajorGiftsEmail' ) - ) - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for excessive amount (BBD)' - ); - } - - public function testTooLittleBbd() { - $this->normalized['currency_code'] = 'BBD'; - $this->normalized['amount'] = '2.95'; - $this->validate(); - - $this->assertTrue( - $this->errors->hasValidationError( 'amount' ), - 'No error for diminutive amount (BBD)' - ); - $formattedMin = Amount::format( 3.00, 'BBD', 'en_US' ); - $expected = new ValidationError( - 'amount', - 'donate_interface-smallamount-error', - array( $formattedMin ) - ); - $this->assertEquals( - $expected, - $this->getFirstError(), - 'Wrong error message for diminutive amount (BBD)' - ); - } -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/DataValidatorTest.php b/tests/phpunit/DataValidatorTest.php deleted file mode 100644 index 3858521..0000000 --- a/tests/phpunit/DataValidatorTest.php +++ /dev/null @@ -1,158 +0,0 @@ -<<<<<<< HEAD (b33d3e 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', '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 (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/GatewayPageTest.php b/tests/phpunit/GatewayPageTest.php deleted file mode 100644 index 6971f04..0000000 --- a/tests/phpunit/GatewayPageTest.php +++ /dev/null @@ -1,208 +0,0 @@ -<<<<<<< HEAD (b33d3e 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; - -/** - * @group Fundraising - * @group DonationInterface - * @group GatewayPage - */ -class GatewayPageTest extends DonationInterfaceTestCase { - - /** - * @var GatewayPage - */ - protected $page; - /** - * @var GatewayAdapter - */ - protected $adapter; - - public function setUp() { - $this->page = new TestingGatewayPage(); - // put these here so tests can override them - TestingGenericAdapter::$fakeGlobals = array ( 'FallbackCurrency' => 'USD' ); - TestingGenericAdapter::$acceptedCurrencies[] = 'USD'; - TestingGenericAdapter::$fakeIdentifier = 'globalcollect'; - $this->setMwGlobals( array( - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'paypal' => array( - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - ), - ), - ) ); - parent::setUp(); - } - - protected function setUpAdapter( $extra = array() ) { - $externalData = array_merge( - array( - 'amount' => '200', - 'currency_code' => 'BBD', - 'contribution_tracking_id' => mt_rand( 10000, 10000000 ), - ), - $extra - ); - $this->adapter = new TestingGenericAdapter( array( - 'external_data' => $externalData, - ) ); - $this->page->adapter = $this->adapter; - } - - public function tearDown() { - TestingGenericAdapter::$acceptedCurrencies = array(); - TestingGenericAdapter::$fakeGlobals = array(); - TestingGenericAdapter::$fakeIdentifier = false; - parent::tearDown(); - } - - public function testCurrencyFallbackWithNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - $this->setUpAdapter(); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $this->assertEquals( $msgKey, $errors[0]->getMessageKey() ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testCurrencyFallbackIntermediateConversion() { - TestingGenericAdapter::$fakeGlobals['FallbackCurrency'] = 'OMR'; - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - TestingGenericAdapter::$acceptedCurrencies[] = 'OMR'; - // FIXME: Relies on app default exchange rate. Set explicitly instead. - $this->setUpAdapter(); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $this->assertEquals( $msgKey, $errors[0]->getMessageKey() ); - $this->assertEquals( 38, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'OMR', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testCurrencyFallbackWithoutNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter(); - - $this->assertTrue( $this->adapter->validatedOK() ); - - $errorState = $this->adapter->getErrorState(); - $this->assertFalse( $errorState->hasErrors() ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testCurrencyFallbackAlwaysNotifiesIfOtherErrors() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter( array( 'email' => 'notanemail' ) ); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $foundError = false; - foreach( $errors as $error ) { - if ( $error->getField() === 'currency_code' ) { - $this->assertEquals( $msgKey, $error->getMessageKey() ); - $foundError = true; - } - } - $this->assertTrue( $foundError ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testNoFallbackForSupportedCurrency() { - TestingGenericAdapter::$acceptedCurrencies[] = 'BBD'; - $this->setUpAdapter(); - - $errorState = $this->adapter->getErrorState(); - $this->assertFalse( $errorState->hasErrors() ); - $this->assertEquals( 200, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'BBD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testCurrencyFallbackByCountry() { - // With 'FallbackCurrencyByCountry', we need to return a single supported currency - TestingGenericAdapter::$acceptedCurrencies = array( 'USD' ); - TestingGenericAdapter::$fakeGlobals = array( - 'FallbackCurrency' => false, - 'FallbackCurrencyByCountry' => true, - ); - $extra = array( - 'country' => 'US', - ); - $this->setUpAdapter( $extra ); - - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - /** - * Before redirecting a user to the processor, we should log all of their - * details at info level - */ - function testLogDetailsOnRedirect() { - $init = $this->getDonorTestData(); - $session = array( 'Donor' => $init ); - - $this->verifyFormOutput( 'PaypalLegacyGateway', $init, array(), false, $session ); - - $logged = $this->getLogMatches( LogLevel::INFO, '/^Redirecting for transaction: /' ); - $this->assertEquals( 1, count( $logged ), 'Should have logged details once' ); - preg_match( '/Redirecting for transaction: (.*)$/', $logged[0], $matches ); - $detailString = $matches[1]; - $expected = array( - 'currency_code' => 'USD', - 'payment_submethod' => '', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - 'country' => 'US', - 'payment_method' => 'paypal', - 'user_ip' => '127.0.0.1', - 'recurring' => '', - 'utm_source' => '..paypal', - 'gateway' => 'paypal', - 'gateway_account' => 'testing', - 'gateway_txn_id' => false, - 'response' => false, - 'street' => '123 Fake Street', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postal_code' => '94105', - 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceMessage', - ); - $actual = json_decode( $detailString, true ); - // TODO: when tests use PHPUnit 4.4 - // $this->assertArraySubset( $expected, $actual, false, 'Logged the wrong stuff' ); - $expected['order_id'] = $actual['contribution_tracking_id']; - unset( $actual['contribution_tracking_id'] ); - unset( $actual['correlation-id'] ); - unset( $actual['date'] ); - $this->assertEquals( $expected, $actual, 'Logged the wrong stuff!' ); - } -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/GatewayValidationTest.php b/tests/phpunit/GatewayValidationTest.php deleted file mode 100644 index 17f8768..0000000 --- a/tests/phpunit/GatewayValidationTest.php +++ /dev/null @@ -1,176 +0,0 @@ -<<<<<<< HEAD (b33d3e 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 GatewayPage - */ -class GatewayValidationTest extends DonationInterfaceTestCase { - - protected $page; - protected $adapter; - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - // FIXME: base class sketchiness. - 'wgDonationInterfaceGatewayAdapters' => array( - 'donation' => 'TestingGatewayAdapter', - ), - 'wgDonationInterfacePriceFloor' => 2.00, - 'wgDonationInterfacePriceCeiling' => 100.00, - ) ); - - TestingGenericAdapter::$acceptedCurrencies[] = 'USD'; - - $this->page = new TestingGatewayPage(); - } - - protected function setUpAdapter( $data = array() ) { - $this->adapter = new TestingGenericAdapter( array( - 'external_data' => $data, - ) ); - $this->page->adapter = $this->adapter; - } - - public function tearDown() { - TestingGenericAdapter::$fakeIdentifier = null; - TestingGenericAdapter::$acceptedCurrencies = array(); - parent::tearDown(); - } - - public function assertHasValidationError( $field, $messageKey = null, $messageParams = null ) { - $hasError = false; - foreach( $this->adapter->getErrorState()->getErrors() as $error ) { - if ( $error instanceof ValidationError and $error->getField() === $field ) { - $hasError = true; - if ( $messageKey !== null ) { - $this->assertEquals( $messageKey, $error->getMessageKey() ); - } - if ( $messageParams !== null ) { - $this->assertEquals( $messageParams, $error->getMessageParams() ); - } - } - } - $this->assertTrue( $hasError ); - } - - public function testPassesValidation() { - $this->setUpAdapter( array( - 'amount' => '2.00', - 'country' => 'US', - 'currency' => 'USD', - 'email' => 'f...@localhost.net', - ) ); - - $this->assertTrue( $this->adapter->validatedOK() ); - } - - public function testLowAmountError() { - $this->setUpAdapter( array( - 'amount' => '1.99', - 'country' => 'US', - 'currency' => 'USD', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $errors = $this->adapter->getErrorState(); - $this->assertTrue( $errors->hasValidationError( 'amount' ) ); - } - - public function testHighAmountError() { - $this->setUpAdapter( array( - 'amount' => '100.99', - 'country' => 'US', - 'currency' => 'USD', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $errors = $this->adapter->getErrorState(); - $this->assertTrue( $errors->hasValidationError( 'amount' ) ); - } - - public function testCurrencyCodeError() { - $this->setUpAdapter( array( - 'amount' => '2.99', - 'country' => 'BR', - 'currency' => 'BRL', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $this->assertHasValidationError( 'currency_code' ); - } - - public function testCountryError() { - // TODO: also validate and test country=ZZ and XX - - $this->setMwGlobals( array( - 'wgDonationInterfaceForbiddenCountries' => array( 'XX' ) - ) ); - - $this->setUpAdapter( array( - 'amount' => '2.99', - 'country' => 'XX', - 'currency' => 'USD', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $this->assertHasValidationError( 'country' ); - } - - public function testEmailError() { - $this->setUpAdapter( array( - 'amount' => '2.99', - 'currency' => 'USD', - 'email' => 'foo', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $this->assertHasValidationError( 'email' ); - } - - public function testSpuriousCcError() { - $this->setUpAdapter( array( - 'amount' => '2.99', - 'currency' => 'USD', - 'fname' => '4111111111111111', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - $this->assertHasValidationError( 'fname' ); - } - - public function testMissingFieldError() { - $this->setUpAdapter( array( - 'amount' => '2.99', - ) ); - - $this->assertFalse( $this->adapter->validatedOK() ); - $this->assertHasValidationError( 'currency_code' ); - } -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) diff --git a/tests/phpunit/LintYaml.php b/tests/phpunit/LintYaml.php new file mode 100644 index 0000000..bd8a5f0 --- /dev/null +++ b/tests/phpunit/LintYaml.php @@ -0,0 +1,50 @@ +<?php +// Sadly, I didn't find any off-the-shelf yaml linters that didn't make me mad. +// Requires PHP 5.4 + +use Symfony\Component\Yaml\Parser; + +function runForYamlFiles( $callback ) { + $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/../' ); + $filter = new RecursiveCallbackFilterIterator( $directoryIterator, function( $current, $key, $iterator ) { + // Skip tests and vendor directories. + if ( $current->getFilename() === 'tests' + || $current->getFilename() === 'vendor' + || $current->getFilename() === 'node_modules' + ) { + return false; + } + + // Recurse + if ( $current->isDir() ) { + return true; + } + + // Match .yaml or .yml + return preg_match( '/\.ya?ml$/', $current->getFilename() ); + } ); + + $iterator = new RecursiveIteratorIterator( $filter ); + foreach ( $iterator as $file ) { + if ( $file->isFile() ) { + $callback( $file->getPathname() ); + } + } +} + +function lintYamlFile( $path ) { + $yamlParser = new Parser(); + try { + $data = $yamlParser->parse( file_get_contents( $path ) ); + } catch ( Exception $ex ) { + global $exitStatus; + $exitStatus = -1; + + error_log( $path . ': ' . $ex->getMessage() ); + } +} + +$exitStatus = 0; +require_once __DIR__ . '/../../vendor/autoload.php'; +runForYamlFiles( 'lintYamlFile' ); +exit($exitStatus); diff --git a/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php b/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php deleted file mode 100644 index 93d0346..0000000 --- a/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php +++ /dev/null @@ -1,99 +0,0 @@ -<<<<<<< HEAD (b33d3e 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. - * - */ - -/** - * A really dumb adapter. - */ -class TestingGenericAdapter extends GatewayAdapter { - - public static $fakeGlobals = array(); - - public static $fakeIdentifier; - - public static $acceptedCurrencies = array(); - - public function getCommunicationType() { - return 'xml'; - } - - public function normalizeOrderID( $override = null, $dataObj = null ) { - return '12345'; - } - - public static function getGlobal( $name ) { - if ( array_key_exists( $name, TestingGenericAdapter::$fakeGlobals ) ) { - return TestingGenericAdapter::$fakeGlobals[$name]; - } - return parent::getGlobal( $name ); - } - - public static function getIdentifier() { - if ( self::$fakeIdentifier ) { - return self::$fakeIdentifier; - } - return GatewayAdapter::getIdentifier(); - } - - public function loadConfig() { - } - - public function defineAccountInfo() { - } - - public function defineDataConstraints() { - } - - public function defineErrorMap() { - } - - public function defineOrderIDMeta() { - } - - public function definePaymentMethods() { - } - - public function defineReturnValueMap() { - } - - public function defineTransactions() { - } - - public function defineDataTransformers() { - $this->data_transformers = parent::getCoreDataTransformers(); - } - - public function defineVarMap() { - } - - public function setGatewayDefaults( $options = array() ) { - } - - public function getCurrencies( $options = array() ) { - return TestingGenericAdapter::$acceptedCurrencies; - } - - public function doPayment() { - } - - protected function getBasedir() { - return __DIR__; - } -} ->>>>>>> BRANCH (af8e63 Log session IDs when adding info & failing to find it) -- To view, visit https://gerrit.wikimedia.org/r/353913 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I61c2d83a0d5b5553c75ccdd1b363987755a4618e Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits