Ejegg has submitted this change and it was merged. Change subject: Merge branch 'master' into deployment ......................................................................
Merge branch 'master' into deployment 1afab3e Parse more of AstroPay's error descriptions cb1e381 Add country-specific versions of fiscal_number 3b868b0 Check error['context'] to place error messages ea35c3e Use old error forms for AstroPay fail page 8205cfb Generate new order IDs for each NewInvoice call 4ac357a Move deleteMessage out of legacy antimessage function 4a00d5e Localisation updates from https://translatewiki.net. fc023c9 Localisation updates from https://translatewiki.net. 85821e3 Localisation updates from https://translatewiki.net. f801889 Give Japan forms correct selection weight d3d31c5 Localisation updates from https://translatewiki.net. 643abbe Undo last commit's fiscal number normalization 082a3f5 Validate fiscal number when exists, require for AstroPay df64fe1 Localisation updates from https://translatewiki.net. Conflicts: tests/Adapter/Astropay/AstropayTest.php tests/Adapter/GatewayAdapterTest.php tests/Adapter/Worldpay/WorldpayTest.php tests/DataValidatorTest.php tests/includes/Responses/astropay/NewInvoice_1.testresponse Change-Id: Id7f7faae0c5c64f218791c4ae713442642cd7426 --- D tests/Adapter/Astropay/AstropayTest.php D tests/Adapter/GatewayAdapterTest.php D tests/Adapter/Worldpay/WorldpayTest.php D tests/DataValidatorTest.php D tests/MessageTest.php D tests/includes/Responses/astropay/NewInvoice_1.testresponse D tests/includes/Responses/astropay/NewInvoice_collision.testresponse D tests/includes/Responses/astropay/NewInvoice_could_not_register.testresponse D tests/includes/Responses/astropay/NewInvoice_fiscal_number.testresponse D tests/includes/Responses/astropay/NewInvoice_limit_exceeded.testresponse D tests/includes/Responses/astropay/NewInvoice_user_unauthorized.testresponse 11 files changed, 0 insertions(+), 1,376 deletions(-) Approvals: Ejegg: Looks good to me, approved diff --git a/tests/Adapter/Astropay/AstropayTest.php b/tests/Adapter/Astropay/AstropayTest.php deleted file mode 100644 index 95d2884..0000000 --- a/tests/Adapter/Astropay/AstropayTest.php +++ /dev/null @@ -1,512 +0,0 @@ -<<<<<<< HEAD (012785 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, - ) ); - } - - function tearDown() { - TestingAstropayAdapter::clearGlobalsCache(); - parent::tearDown(); - } - - /** - * 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' ); - $this->setLanguage( $init['language'] ); - $_SESSION['Donor']['order_id'] = '123456789'; - $gateway = $this->getFreshGatewayObject( $init ); - - $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->assertEmpty( $gateway->getTransactionErrors(), - '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' ); - - $expected = array( - 'internal-0000' => wfMessage( 'donate_interface-processing-error')->inLanguage( $init['language'] )->text() - ); - $this->assertEquals( $expected, $gateway->getTransactionErrors(), - '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(); - - $expectedMessage = wfMessage( 'donate_interface-processing-error')->inLanguage( $init['language'] )->text(); - $actual = $result->getErrors(); - $this->assertEquals( $expectedMessage, $actual['internal-0000']['message'], - 'Wrong error array 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' ); - $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(); - $expectedMessage = wfMessage( 'donate_interface-error-msg-limit')->inLanguage( $init['language'] )->text(); - $this->assertEquals( $expectedMessage, $errors['internal-0000']['message'] ); - $this->assertEquals( 'amount', $errors['internal-0000']['context'] ); - } - - /** - * Should set a validation error on fiscal_number - */ - function testDoPaymentBadFiscalNumber() { - $init = $this->getDonorTestData( 'BR' ); - $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(); - $expectedMessage = DataValidator::getErrorMessage( 'fiscal_number', 'calculated', $init['language'] ); - $this->assertEquals( $expectedMessage, $errors['internal-0000']['message'] ); - $this->assertEquals( 'fiscal_number', $errors['internal-0000']['context'] ); - } - - /** - * Should finalize to failed - */ - function testDoPaymentUserUnauthorized() { - $init = $this->getDonorTestData( 'BR' ); - $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' ); - $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(); - $expectedMessage = wfMessage( 'donate_interface-try-again')->inLanguage( $init['language'] )->text(); - $this->assertEquals( $expectedMessage, $errors['internal-0000']['message'] ); - } - - /** - * PaymentStatus transaction should interpret the delimited response - */ - function testPaymentStatus() { - $init = $this->getDonorTestData( 'BR' ); - $_SESSION['Donor']['order_id'] = '123456789'; - $gateway = $this->getFreshGatewayObject( $init ); - - $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'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( 'badsig' ); - $gateway->do_transaction( 'PaymentStatus' ); - - $results = $gateway->getTransactionData(); - $this->setExpectedException( 'ResponseProcessingException' ); - $gateway->verifyStatusSignature( $results ); - } - - /** - * If status is paid and signature is correct, processResponse should not - * throw exception and final status should be 'completed' - */ - function testSuccessfulReturn() { - $init = $this->getDonorTestData( 'BR' ); - $_SESSION['Donor']['order_id'] = '123456789'; - $gateway = $this->getFreshGatewayObject( $init ); - - // Next lines mimic Astropay resultswitcher - $gateway->setCurrentTransaction( 'ProcessReturn' ); - $response = 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', - ); - - $gateway->processResponse( $response ); - $status = $gateway->getFinalStatus(); - $this->assertEquals( FinalStatus::COMPLETE, $status ); - } - - /** - * If payment is rejected, final status should be 'failed' - */ - function testRejectedReturn() { - $init = $this->getDonorTestData( 'BR' ); - $_SESSION['Donor']['order_id'] = '123456789'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setCurrentTransaction( 'ProcessReturn' ); - $response = 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', - ); - - $gateway->processResponse( $response ); - $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 hooks before redirecting - */ - function testAntiFraudHooks() { - DonationInterface_FraudFiltersTest::setupFraudMaps(); - $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' ); - } - - /** - * Before redirecting a user to the processor, we should log all of their - * details at info level - */ - function testLogDetails() { - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'cc'; - $_SESSION['Donor']['order_id'] = '123456789'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->doPayment(); - $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( - 'referrer' => 'www.yourmom.com', - 'currency_code' => 'BRL', - 'payment_submethod' => 'test_bank', - 'fname' => 'Nome', - 'lname' => 'Apelido', - 'amount' => '100.00', - 'language' => 'pt', - 'email' => 'nob...@example.org', - 'country' => 'BR', - 'payment_method' => 'cc', - 'user_ip' => '127.0.0.1', - 'recurring' => '', - 'utm_source' => '..cc', - 'gateway' => 'astropay', - 'gateway_account' => 'test', - 'gateway_txn_id' => false, - 'response' => false, - 'correlation-id' => 'astropay-123456789', - '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' ); - unset( $actual['contribution_tracking_id'] ); - unset( $actual['date'] ); - $this->assertEquals( $expected, $actual, 'Logged the wrong stuff!' ); - } - - 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' ); - $firstAttempt = $this->getFreshGatewayObject( $init ); - $firstAttempt->setDummyGatewayResponseCode( '1' ); - - $firstAttempt->doPayment(); - - $secondAttempt = $this->getFreshGatewayObject( $init ); - $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' - ); - } -} ->>>>>>> BRANCH (1afab3 Parse more of AstroPay's error descriptions) diff --git a/tests/Adapter/GatewayAdapterTest.php b/tests/Adapter/GatewayAdapterTest.php deleted file mode 100644 index d3a5d67..0000000 --- a/tests/Adapter/GatewayAdapterTest.php +++ /dev/null @@ -1,154 +0,0 @@ -<<<<<<< HEAD (012785 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. - * - */ - -/** - * TODO: Test everything. - * Make sure all the basic functions in the gateway_adapter are tested here. - * Also, the extras and their hooks firing properly and... that the fail score - * they give back is acted upon in the way we think it does. - * Hint: For that mess, use GatewayAdapter's $debugarray - * - * Also, note that it barely makes sense to test the functions that need to be - * defined in each gateway as per the abstract class. If we did that here, we'd - * basically be just testing the test code. So, don't do it. - * Those should definitely be tested in the various gateway-specific test - * classes. - * - * @group Fundraising - * @group DonationInterface - * @group Splunge - */ -class DonationInterface_Adapter_GatewayAdapterTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - global $wgDonationInterfaceAllowedHtmlForms; - global $wgDonationInterfaceTest; - $wgDonationInterfaceTest = true; - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'testytest' => array( - 'gateway' => 'globalcollect', //RAR. - ), - ), - ) ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::defineVarMap - * @covers GatewayAdapter::defineReturnValueMap - * @covers GatewayAdapter::defineTransactions - */ - public function testConstructor() { - - $options = $this->getDonorTestData(); - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( 'testytest', array ( 'gateway' => $class::getIdentifier() ) ); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway ); - - $this->resetAllEnv(); - $gateway = $this->getFreshGatewayObject( $options = array ( ) ); - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway, "Having trouble constructing a blank adapter." ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers DonationData::__construct - */ - public function testConstructorHasDonationData() { - - $_SERVER['REQUEST_URI'] = '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount'; - - $options = $this->getDonorTestData(); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( 'TestingGlobalCollectAdapter', $gateway ); - - //please define this function only inside the TESTS_ADAPTER_DEFAULT, - //which should be a test adapter object that descende from one of the - //production adapters. - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertInstanceOf( 'DonationData', $exposed->dataObj ); - } - - public function testLanguageChange() { - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'en', "'US' donor's language was inproperly set. Should be 'en'" ); - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - //so we know it tried to screw with the session and such. - - $options = $this->getDonorTestData( 'NO' ); - $gateway = $this->getFreshGatewayObject( $options ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'no', "'NO' donor's language was inproperly set. Should be 'no'" ); - } - - /** - * Make sure data is cleared out when changing gateways. - * In particular, ensure order IDs aren't leaking. - */ - public function testResetOnGatewaySwitch() { - //Fill the session with some Amazon stuff - $init = $this->getDonorTestData( 'FR' ); - $init['contribution_tracking_id'] = mt_rand(); - $amazon_gateway = new TestingAmazonAdapter( array ( - 'external_data' => $init, - ) ); - $amazon_gateway->do_transaction( 'Donate' ); - - $this->assertEquals( 'amazon', $_SESSION['Donor']['gateway'], 'Test setup failed.' ); - - //Then simpulate switching to Worldpay - $_SESSION['sequence'] = 2; - unset( $_POST['order_id'] ); - - $worldpay_gateway = new TestingWorldpayAdapter( array ( - 'external_data' => $init, - ) ); - $worldpay_gateway->batch_mode = TRUE; - - $expected_order_id = "{$init['contribution_tracking_id']}.{$_SESSION['sequence']}"; - $this->assertEquals( $expected_order_id, $worldpay_gateway->getData_Unstaged_Escaped( 'order_id' ), - 'Order ID was not regenerated on gateway switch!' ); - } -} - ->>>>>>> BRANCH (1afab3 Parse more of AstroPay's error descriptions) diff --git a/tests/Adapter/Worldpay/WorldpayTest.php b/tests/Adapter/Worldpay/WorldpayTest.php deleted file mode 100644 index f0f5da3..0000000 --- a/tests/Adapter/Worldpay/WorldpayTest.php +++ /dev/null @@ -1,492 +0,0 @@ -<<<<<<< HEAD (012785 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 Worldpay - */ -class DonationInterface_Adapter_Worldpay_WorldpayTest 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 = 'TestingWorldpayAdapter'; - } - - public function setUp() { - global $wgWorldpayGatewayHtmlFormDir; - parent::setUp(); - - $this->setMwGlobals( array( - 'wgWorldpayGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'testytest' => array( - 'gateway' => 'worldpay', - ), - 'worldpay' => array( - 'file' => $wgWorldpayGatewayHtmlFormDir . '/worldpay.html', - 'gateway' => 'worldpay', - 'countries' => array( '+' => array( 'AU', 'BE', 'CA', 'FR', 'GB', 'IL', 'NZ', 'US' ) ), - 'currencies' => array( '+' => 'ALL' ), - 'payment_methods' => array( 'cc' => 'ALL' ), - 'selection_weight' => 10 - ), - ), - ) ); - } - - /** - * Just making sure we can instantiate the thing without blowing up completely - */ - function testConstruct() { - $options = $this->getDonorTestData(); - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( 'testytest', array ( 'gateway' => $class::getIdentifier() ) ); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( 'TestingWorldpayAdapter', $gateway ); - } - - /** - * Test the AntiFraud hooks - */ - function testAntiFraudHooks() { - $options = $this->getDonorTestData( 'US' ); - $options['utm_source'] = "somethingmedia"; - $options['email'] = "someb...@wikipedia.org"; - - $gateway = $this->getFreshGatewayObject( $options ); - - $gateway->runAntifraudHooks(); - - $this->assertEquals( 'reject', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 113, $exposed->risk_score, 'RiskScore is not as expected' ); - } - - /** - * Just making sure we can instantiate the thing without blowing up completely - */ - function testNeverLog() { - $options = $this->getDonorTestData(); - $options['cvv'] = '123'; - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( 'testytest', array ( 'gateway' => $class::getIdentifier() ) ); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( 'TestingWorldpayAdapter', $gateway ); - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - $loglines = $this->getLogMatches( LogLevel::INFO, '/Request XML/' ); - - $this->assertEquals( 1, count( $loglines ), "We did not receive exactly one logline back that contains request XML" ); - $this->assertEquals( 1, preg_match( '/Cleaned/', $loglines[0] ), 'The logline did not come back marked as "Cleaned".' ); - $this->assertEquals( 0, preg_match( '/CNV/', $loglines[0] ), 'The "Cleaned" logline contained CVN data!' ); - } - - function testWorldpayFormLoad() { - $init = $this->getDonorTestData(); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['email'] = 'someb...@wikipedia.org'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'worldpay'; - $init['currency_code'] = 'EUR'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtml' => '€1.55', - ), - 'fname' => array( - 'nodename' => 'input', - 'value' => 'Firstname', - ), - 'lname' => array( - 'nodename' => 'input', - 'value' => 'Surname', - ), - 'street' => array( - 'nodename' => 'input', - 'value' => '123 Fake Street', - ), - 'city' => array( - 'nodename' => 'input', - 'value' => 'San Francisco', - ), - 'zip' => array( - 'nodename' => 'input', - 'value' => '94105', - ), - 'country' => array( - 'nodename' => 'input', - 'value' => 'US', - ), - 'emailAdd' => array( - 'nodename' => 'input', - 'value' => 'someb...@wikipedia.org', - ), - 'language' => array( - 'nodename' => 'input', - 'value' => 'en', - ), - 'state' => array( - 'nodename' => 'select', - 'selected' => 'CA', - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => "By donating, you agree to share your personal information with the Wikimedia Foundation, the nonprofit organization that hosts Wikipedia and other Wikimedia projects, and its service providers pursuant to our <a href=\"//wikimediafoundation.org/wiki/Donor_policy\">donor policy</a>. Wikimedia Foundation and its service providers are located in the United States and in other countries whose privacy laws may not be equivalent to your own. We do not sell or trade your information to anyone. For more information please read our <a href=\"//wikimediafoundation.org/wiki/Donor_policy\">donor policy</a>." - ), - ); - - $this->verifyFormOutput( 'TestingWorldpayGateway', $init, $assertNodes, true ); - } - - function testPaymentFormSubmit() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'worldpay'; - $init['currency_code'] = 'EUR'; - $init['email'] = 'noemailfraudsc...@test.org'; - - $init['OTT'] = 'SALT123456789'; - - $assertNodes = array( - 'headers' => array( - 'Location' => 'https://wikimediafoundation.org/wiki/Thank_You/fr', - ), - ); - - $this->verifyFormOutput( 'TestingWorldpayGateway', $init, $assertNodes, true ); - } - - function testWorldpayFormLoad_FR() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'worldpay'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtml' => '€1.55', - ), - 'fname' => array ( - 'nodename' => 'input', - 'value' => 'Prénom', - ), - 'lname' => array ( - 'nodename' => 'input', - 'value' => 'Nom', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'FR', - ), - ); - - $this->verifyFormOutput( 'TestingWorldpayGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Belgian form loads in all of that country's supported languages - * @dataProvider belgiumLanguageProvider - */ - public function testWorldpayFormLoad_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'worldpay'; - $init['language'] = $language; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtml' => '€1.55', - ), - 'fname-label' => array ( - 'nodename' => 'label', - 'innerhtml' => wfMessage( 'donate_interface-donor-fname' )->inLanguage( $language )->text(), - ), - 'lname-label' => array ( - 'nodename' => 'label', - 'innerhtml' => wfMessage( 'donate_interface-donor-lname' )->inLanguage( $language )->text(), - ), - 'emailAdd-label' => array ( - 'nodename' => 'label', - 'innerhtml' => wfMessage( 'donate_interface-donor-email' )->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - ); - - $this->verifyFormOutput( 'TestingWorldpayGateway', $init, $assertNodes, true ); - } - - /** - * Testing that we can retrieve the cvv_match value and run antifraud on it correctly - */ - function testAntifraudCVVMatch() { - $options = $this->getDonorTestData(); //don't really care: We'll be using the dummy response directly. - $class = $this->testAdapterClass; - - $gateway = $this->getFreshGatewayObject( $options ); - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - $this->assertEquals( '1', $gateway->getData_Unstaged_Escaped( 'cvv_result' ), 'cvv_result was not set after AuthorizePaymentForFraud' ); - $this->assertTrue( $gateway->getCVVResult(), 'getCVVResult not passing somebody with a match.' ); - - //and now, for fun, test a wrong code. - $gateway->addResponseData( array ( 'cvv_result' => '2' ) ); - $this->assertFalse( $gateway->getCVVResult(), 'getCVVResult not failing somebody with garbage.' ); - } - - /** - * Ensure we don't give too high a risk score when AVS address / zip match was not performed - */ - function testAntifraudAllowsAvsNotPerformed() { - $options = $this->getDonorTestData('FR'); //don't really care: We'll be using the dummy response directly. - - $gateway = $this->getFreshGatewayObject( $options ); - $gateway->setDummyGatewayResponseCode( 9000 ); - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - $this->assertEquals( '9', $gateway->getData_Unstaged_Escaped( 'avs_address' ), 'avs_address was not set after AuthorizePaymentForFraud' ); - $this->assertEquals( '9', $gateway->getData_Unstaged_Escaped( 'avs_zip' ), 'avs_zip was not set after AuthorizePaymentForFraud' ); - $this->assertTrue( $gateway->getAVSResult() < 25, 'getAVSResult returning too high a score for AVS not performed.' ); - } - - /** - * Check to make sure we don't run antifraud filters (and burn a minfraud query) when we know the transaction has already failed - */ - function testAntifraudNotPerformedOnGatewayError() { - $options = $this->getDonorTestData( 'FR' ); //don't really care: We'll be using the dummy response directly. - - $gateway = $this->getFreshGatewayObject( $options ); - $gateway->setDummyGatewayResponseCode( 2208 ); //account problems - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - //assert that: - //#1 - the gateway object has an appropriate transaction error set - //#2 - antifraud checks were not performed. - - //check for the error code that corresponds to the transaction coming back with a failure, rather than the one that we use for fraud fail. - $errors = $gateway->getTransactionErrors(); - $this->assertTrue( !empty( $errors ), 'No errors in getTransactionErrors after a bad "AuthorizePaymentForFraud"' ); - $this->assertTrue( array_key_exists( 'internal-0001', $errors ), 'Unexpected error code' ); - - //check more things to make sure we didn't run any fraud filters - $loglines = $this->getLogMatches( LogLevel::INFO, '/Preparing to run custom filters/' ); - $this->assertEmpty( $loglines, 'According to the logs, we ran antifraud filters and should not have' ); - $this->assertEquals( 'process', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 0, $exposed->risk_score, 'RiskScore is not as expected' ); - - } - - /** - * Check to make sure we do run antifraud filters when we know the transaction is okay to go - */ - function testAntifraudPerformedOnGatewayNoError() { - $options = $this->getDonorTestData( 'FR' ); //don't really care: We'll be using the dummy response directly. - $options['email'] = 't...@something.com'; - - $gateway = $this->getFreshGatewayObject( $options ); -// $gateway->setDummyGatewayResponseCode( 2208 ); //account problems - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - //assert that: - //#1 - the gateway object has no errors set - //#2 - antifraud checks were performed. - $errors = $gateway->getTransactionErrors(); - $this->assertTrue( empty( $errors ), 'Errors assigned in getTransactionErrors after a good "AuthorizePaymentForFraud"' ); - //check more things to make sure we did run the fraud filters - $loglines = $this->getLogMatches( LogLevel::INFO, '/CustomFiltersScores/' ); - $this->assertNotEmpty( $loglines, 'No antifraud filters were run, according to the logs' ); - $this->assertEquals( 'process', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 0, $exposed->risk_score, 'RiskScore is not as expected' ); - } - - /** - * Ensure we're staging a punctuation-stripped version of the email address in merchant_reference_2 - */ - function testMerchantReference2() { - $options = $this->getDonorTestData(); - $options['email'] = 'little+tea...@short.stout.com'; - $gateway = $this->getFreshGatewayObject( $options ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - $staged = $exposed->getData_Staged( 'merchant_reference_2' ); - $this->assertEquals( 'little teapot short stout com', $staged ); - } - - function testTransliterateUtf8forEurocentricProcessor() { - $options = $this->getDonorTestData(); - $options['fname'] = 'Barnabáš'; - $options['lname'] = 'Voříšek'; - $options['street'] = 'Truhlářská 320/62'; - $options['city'] = 'České Budějovice'; - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( 'testytest', array ( 'gateway' => $class::getIdentifier() ) ); - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - $gateway->do_transaction( 'AuthorizeAndDepositPayment' ); - $xml = new SimpleXMLElement( preg_replace( '/StringIn=/', '', $gateway->curled ) ); - $this->assertEquals( 'Barnabás', $xml->FirstName ); - $this->assertEquals( 'Vorísek', $xml->LastName ); - $this->assertEquals( 'Truhlárská 320/62', $xml->Address1 ); - $this->assertEquals( 'Ceské Budejovice', $xml->City ); - } - - /** - * Check that whacky #.# format orderid is unmolested by order_id_meta validation. - */ - function testWackyOrderIdPassedValidation() { - $init = self::$initial_vars; - - $init['order_id'] = '2143.0'; - unset( $_POST['order_id'] ); - unset( $_SESSION['Donor']['order_id'] ); - $gateway = $this->getFreshGatewayObject( $init, array( 'batch_mode' => TRUE, ) ); - $this->assertEquals( $init['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'Decimal Order ID should be allowed by orderIdMeta validation' ); - } - - /** - * Check that order_id is built from contribution_tracking id. - */ - function testWackyOrderIdBasedOnContributionTracking() { - $init = self::$initial_vars; - - $init['contribution_tracking_id'] = mt_rand(); - $_SESSION['sequence'] = 2; - unset( $_POST['order_id'] ); - $gateway = $this->getFreshGatewayObject( $init, array( 'batch_mode' => TRUE, ) ); - $expected_order_id = "{$init['contribution_tracking_id']}.{$_SESSION['sequence']}"; - $this->assertEquals( $expected_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'Decimal Order ID is not correctly built from Contribution Tracking ID.' ); - } - - /** - * Ensure processResponse doesn't fail trxn for special accounts when AVS - * nodes are missing. - */ - function testProcessResponseAllowsSnowflakeAVSMissing() { - $options = $this->getDonorTestData( 'FJ' ); // 'FJ' store ID is set up as a special exception - - $gateway = $this->getFreshGatewayObject( $options ); - $gateway->setDummyGatewayResponseCode( 'snowflake' ); - $results = $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - // internal-0001 is the error code processRespose adds for missing nodes - $this->assertFalse( array_key_exists( 'internal-0001', $results->getErrors() ), - 'processResponse is failing a special snowflake account with a response missing AVS nodes' ); - } - - /** - * Ensure we don't give too high a risk score for special accounts when - * AVS address / zip match was not performed and CVV reports failure - */ - function testAntifraudAllowsSnowflakeAVSMissingAndCVVMismatch() { - $options = $this->getDonorTestData( 'FJ' ); // 'FJ' store ID is set up as a special exception - - $gateway = $this->getFreshGatewayObject( $options ); - $gateway->setDummyGatewayResponseCode( 'snowflake' ); - $gateway->do_transaction( 'AuthorizePaymentForFraud' ); - - $this->assertTrue( $gateway->getCVVResult(), 'getCVVResult failing snowflake account' ); - - $this->assertTrue( $gateway->getAVSResult() < 25, 'getAVSResult giving snowflake account too high a risk score' ); - } - - function testNarrativeStatement1() { - $class = $this->testAdapterClass; - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( 'testytest', array ( 'gateway' => $class::getIdentifier() ) ); - $options = $this->getDonorTestData(); - $options['contribution_tracking_id'] = mt_rand(); - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - $gateway->do_transaction( 'AuthorizeAndDepositPayment' ); - $xml = new SimpleXMLElement( preg_replace( '/StringIn=/', '', $gateway->curled ) ); - $this->assertEquals( "Wikimedia {$options['contribution_tracking_id']}", $xml->NarrativeStatement1 ); - } - - /** - * doPayment should return an empty result with normal data - */ - function testDoPaymentSuccess() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = 'innoc...@clean.com'; - $init['ffname'] = 'worldpay'; - $init['currency_code'] = 'EUR'; - $init['OTT'] = 'SALT123456789'; - unset( $init['order_id'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - $this->assertEmpty( $result->isFailed(), 'PaymentResult should not be failed' ); - $this->assertEmpty( $result->getErrors(), 'PaymentResult should have no errors' ); - } - - /** - * doPayment should return a failed result with data that triggers the fraud - * filter - */ - function testDoPaymentFailed() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = 'nefari...@wikimedia.org'; //configured as fraudy - $init['ffname'] = 'worldpay'; - $init['currency_code'] = 'EUR'; - $init['OTT'] = 'SALT123456789'; - unset( $init['order_id'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - $this->assertTrue( $result->isFailed(), 'PaymentResult should be failed' ); - $this->assertEmpty( $result->getErrors(), 'PaymentResult should have no errors' ); - } -} ->>>>>>> BRANCH (1afab3 Parse more of AstroPay's error descriptions) diff --git a/tests/DataValidatorTest.php b/tests/DataValidatorTest.php deleted file mode 100644 index d631326..0000000 --- a/tests/DataValidatorTest.php +++ /dev/null @@ -1,141 +0,0 @@ -<<<<<<< HEAD (012785 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( 'AR', 'ABC12312', false ), - array( 'AR', '12341234', true ), - array( 'AR', '1112223', false ), - array( 'MX', 'ABC1234567', true ), - array( 'MX', 'ZYX12345', false ), - ); - } - - /** - * @dataProvider fiscalNumberProvider - */ - public function testValidateFiscalNumber( $country, $value, $valid ) { - $this->assertEquals( $valid, DataValidator::validate_fiscal_number( $value, $country ) ); - } -} ->>>>>>> BRANCH (1afab3 Parse more of AstroPay's error descriptions) diff --git a/tests/MessageTest.php b/tests/MessageTest.php deleted file mode 100644 index 701a58c..0000000 --- a/tests/MessageTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * @group DonationInterface - * @group Messages - */ -class MessageTest extends MediaWikiTestCase { - - public function testGetCountrySpecificMessage() { - $actual = MessageUtils::getCountrySpecificMessage( - 'donate_interface-donor-fiscal_number', - 'BR', - 'pt' - ); - $expected = wfMessage( 'donate_interface-donor-fiscal_number-br' ) - ->inLanguage( 'pt' ) - ->text(); - $this->assertEquals( $expected, $actual, 'Not using the country specific message' ); - } -} diff --git a/tests/includes/Responses/astropay/NewInvoice_1.testresponse b/tests/includes/Responses/astropay/NewInvoice_1.testresponse deleted file mode 100644 index 315b3b4..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_1.testresponse +++ /dev/null @@ -1,12 +0,0 @@ -<<<<<<< HEAD (012785 Merge branch 'master' into deployment) -======= -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 69 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"This error message should appear in the log."} ->>>>>>> BRANCH (1afab3 Parse more of AstroPay's error descriptions) diff --git a/tests/includes/Responses/astropay/NewInvoice_collision.testresponse b/tests/includes/Responses/astropay/NewInvoice_collision.testresponse deleted file mode 100644 index 21e2ec0..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_collision.testresponse +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 45 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"Invoice already used"} diff --git a/tests/includes/Responses/astropay/NewInvoice_could_not_register.testresponse b/tests/includes/Responses/astropay/NewInvoice_could_not_register.testresponse deleted file mode 100644 index aec059a..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_could_not_register.testresponse +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 67 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"Could not register user","error_code":"700"} diff --git a/tests/includes/Responses/astropay/NewInvoice_fiscal_number.testresponse b/tests/includes/Responses/astropay/NewInvoice_fiscal_number.testresponse deleted file mode 100644 index d744454..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_fiscal_number.testresponse +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 63 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"Invalid param x_cpf","error_code":"300"} diff --git a/tests/includes/Responses/astropay/NewInvoice_limit_exceeded.testresponse b/tests/includes/Responses/astropay/NewInvoice_limit_exceeded.testresponse deleted file mode 100644 index ad89f0e..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_limit_exceeded.testresponse +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 58 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"The user limit has been exceeded."} diff --git a/tests/includes/Responses/astropay/NewInvoice_user_unauthorized.testresponse b/tests/includes/Responses/astropay/NewInvoice_user_unauthorized.testresponse deleted file mode 100644 index b80e57d..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_user_unauthorized.testresponse +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 88 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"User unauthorized due to cadastral situation","error_code":"504"} -- To view, visit https://gerrit.wikimedia.org/r/227463 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id7f7faae0c5c64f218791c4ae713442642cd7426 Gerrit-PatchSet: 1 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