jenkins-bot has submitted this change and it was merged. Change subject: Merge master into deployment ......................................................................
Merge master into deployment 75c7086 Actually block if flagged on GatewayReady 2c263fc Localisation updates from https://translatewiki.net. acf7a36 Localisation updates from https://translatewiki.net. Removed tests Change-Id: I4911b0ef2183d208f344336ef2b3387dbea44685 --- D tests/Adapter/GatewayAdapterTest.php D tests/Adapter/GlobalCollect/DirectDebitTest.php D tests/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php D tests/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php D tests/Adapter/GlobalCollect/GlobalCollectTest.php D tests/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php D tests/Adapter/PayPal/PayPalLegacyTest.php D tests/FormChooserTest.php D tests/FraudFiltersTest.php D tests/IntegrationTest.php D tests/LoggingTest.php D tests/TestConfiguration.php D tests/includes/test_gateway/TestingGlobalCollectAdapter.php 13 files changed, 0 insertions(+), 3,054 deletions(-) Approvals: Ejegg: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/Adapter/GatewayAdapterTest.php b/tests/Adapter/GatewayAdapterTest.php deleted file mode 100644 index dc7f1aa..0000000 --- a/tests/Adapter/GatewayAdapterTest.php +++ /dev/null @@ -1,342 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * TODO: Test everything. - * Make sure all the basic functions in the gateway_adapter are tested here. - * Also, the extras and their hooks firing properly and... that the fail score - * they give back is acted upon in the way we think it does. - * Hint: For that mess, use GatewayAdapter's $debugarray - * - * Also, note that it barely makes sense to test the functions that need to be - * defined in each gateway as per the abstract class. If we did that here, we'd - * basically be just testing the test code. So, don't do it. - * Those should definitely be tested in the various gateway-specific test - * classes. - * - * @group Fundraising - * @group DonationInterface - * @group Splunge - */ -class DonationInterface_Adapter_GatewayAdapterTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - global $wgDonationInterfaceAllowedHtmlForms; - global $wgDonationInterfaceTest; - $wgDonationInterfaceTest = true; - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'testytest' => array( - 'gateway' => 'globalcollect', // RAR. - ), - 'rapidFailError' => array( - 'file' => 'error-cc.html', - 'gateway' => array( 'globalcollect', 'adyen', 'amazon', 'astropay', 'paypal' ), - 'special_type' => 'error', - ) - ), - ) ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::defineVarMap - * @covers GatewayAdapter::defineReturnValueMap - * @covers GatewayAdapter::defineTransactions - */ - public function testConstructor() { - - $options = $this->getDonorTestData(); - $class = $this->testAdapterClass; - - $_SERVER['REQUEST_URI'] = GatewayFormChooser::buildPaymentsFormURL( - 'testytest', array( 'gateway' => $class::getIdentifier() ) - ); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway ); - - $this->resetAllEnv(); - $gateway = $this->getFreshGatewayObject( $options = array() ); - $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway, "Having trouble constructing a blank adapter." ); - } - - /** - * - * @covers GatewayAdapter::__construct - * @covers DonationData::__construct - */ - public function testConstructorHasDonationData() { - - $_SERVER['REQUEST_URI'] = '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount'; - - $options = $this->getDonorTestData(); - $gateway = $this->getFreshGatewayObject( $options ); - - $this->assertInstanceOf( 'TestingGlobalCollectAdapter', $gateway ); - - // please define this function only inside the TESTS_ADAPTER_DEFAULT, - // which should be a test adapter object that descende from one of the - // production adapters. - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertInstanceOf( 'DonationData', $exposed->dataObj ); - } - - public function testLanguageChange() { - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'en', "'US' donor's language was inproperly set. Should be 'en'" ); - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - // so we know it tried to screw with the session and such. - - $options = $this->getDonorTestData( 'NO' ); - $gateway = $this->getFreshGatewayObject( $options ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'no', "'NO' donor's language was inproperly set. Should be 'no'" ); - } - - /** - * Make sure data is cleared out when changing gateways. - * In particular, ensure order IDs aren't leaking. - */ - public function testResetOnGatewaySwitch() { - // Fill the session with some GlobalCollect stuff - $init = $this->getDonorTestData( 'FR' ); - $firstRequest = $this->setUpRequest( $init ); - $globalcollect_gateway = new TestingGlobalCollectAdapter(); - $globalcollect_gateway->do_transaction( 'Donate' ); - - $session = $firstRequest->getSessionArray(); - $this->assertEquals( 'globalcollect', $session['Donor']['gateway'], 'Test setup failed.' ); - - //Then simulate switching to Adyen - $session['sequence'] = 2; - unset( $init['order_id'] ); - - $secondRequest = $this->setUpRequest( $init, $session ); - $adyen_gateway = new TestingAdyenAdapter(); - $adyen_gateway->batch_mode = true; - - $session = $secondRequest->getSessionArray(); - $ctId = $adyen_gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ); - $expected_order_id = "$ctId.{$session['sequence']}"; - $this->assertEquals( $expected_order_id, $adyen_gateway->getData_Unstaged_Escaped( 'order_id' ), - 'Order ID was not regenerated on gateway switch!' ); - } - - public function testResetOnRecurringSwitch() { - // Donor initiates a non-recurring donation - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - - $firstRequest = $this->setUpRequest( $init ); - - $gateway = new TestingGlobalCollectAdapter(); - $gateway->do_transaction( 'Donate' ); - - $donorData = $firstRequest->getSessionData( 'Donor' ); - $this->assertEquals( '', $donorData['recurring'], 'Test setup failed.' ); - $oneTimeOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - // Then they go back and decide they want to make a recurring donation - - $init['recurring'] = '1'; - $secondRequest = $this->setUpRequest( $init, $firstRequest->getSessionArray() ); - - $gateway = new TestingGlobalCollectAdapter(); - $gateway->do_transaction( 'Donate' ); - $donorData = $secondRequest->getSessionData( 'Donor' ); - $this->assertEquals( '1', $donorData['recurring'], 'Test setup failed.' ); - - $recurOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - $this->assertNotEquals( $oneTimeOrderId, $recurOrderId, - 'Order ID was not regenerated on recurring switch!' ); - } - - public function testResetSubmethodOnMethodSwitch() { - // Donor thinks they want to make a bank transfer, submits form - $init = $this->getDonorTestData( 'BR' ); - $init['payment_method'] = 'bt'; - $init['payment_submethod'] = 'itau'; - - $firstRequest = $this->setUpRequest( $init ); - - $gateway = new TestingAstroPayAdapter(); - $gateway->do_transaction( 'Donate' ); - - $donorData = $firstRequest->getSessionData( 'Donor' ); - $this->assertEquals( 'itau', $donorData['payment_submethod'], 'Test setup failed.' ); - - // Then they go back and decide they want to donate via credit card - $init['payment_method'] = 'cc'; - unset( $init['payment_submethod'] ); - - $secondRequest = $this->setUpRequest( $init, $firstRequest->getSessionArray() ); - - $gateway = new TestingAstroPayAdapter(); - $newMethod = $gateway->getData_Unstaged_Escaped( 'payment_method' ); - $newSubmethod = $gateway->getData_Unstaged_Escaped( 'payment_submethod' ); - - $this->assertEquals( 'cc', $newMethod, 'Test setup failed' ); - $this->assertEquals( '', $newSubmethod, 'Submethod was not blanked on method switch' ); - } - - public function testStreetStaging() { - $options = $this->getDonorTestData( 'BR' ); - unset( $options['street'] ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $this->setUpRequest( $options ); - $gateway = new TestingGlobalCollectAdapter(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $this->assertEquals( 'N0NE PROVIDED', $exposed->getData_Staged( 'street' ), - 'Street must be stuffed with fake data to prevent AVS scam.' ); - } - - public function testZipStaging() { - $options = $this->getDonorTestData( 'BR' ); - unset( $options['zip'] ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $this->setUpRequest( $options ); - $gateway = new TestingGlobalCollectAdapter(); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $this->assertEquals( '0', $exposed->getData_Staged( 'zip' ), - 'Postal code must be stuffed with fake data to prevent AVS scam.' ); - } - - public function testGetRapidFailPage() { - $this->setMwGlobals( array( - 'wgDonationInterfaceRapidFail' => true, - ) ); - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $options ); - $pageUrlParts = explode( '?', ResultPages::getFailPage( $gateway ) ); - parse_str( $pageUrlParts[1], $params ); - $this->assertEquals( 'rapidFailError', $params['ffname'] ); - $this->assertEquals( 'cc', $params['payment_method'] ); - $this->assertEquals( 'en', $params['language'] ); - } - - public function testGetFallbackFailPage() { - $this->setMwGlobals( array( - 'wgDonationInterfaceRapidFail' => false, - 'wgDonationInterfaceFailPage' => 'Main_Page', //coz we know it exists - ) ); - $options = $this->getDonorTestData( 'US' ); - $gateway = $this->getFreshGatewayObject( $options ); - $page = ResultPages::getFailPage( $gateway ); - $expectedTitle = Title::newFromText( 'Main_Page' ); - $expectedURL = wfAppendQuery( $expectedTitle->getFullURL(), 'uselang=en' ); - $this->assertEquals( $expectedURL, $page ); - } - - // TODO: Move to ResultsPagesTest.php - public function testGetFailPageForType() { - $url = ResultPages::getFailPageForType( 'GlobalCollectAdapter' ); - $expectedTitle = Title::newFromText( 'Donate-error' ); - $expectedURL = wfAppendQuery( $expectedTitle->getFullURL(), 'uselang=en' ); - $this->assertEquals( $expectedURL, $url ); - } - - public function testCancelPage() { - $this->setMwGlobals( array( - 'wgDonationInterfaceCancelPage' => 'Ways to give' - ) ); - $gateway = $this->getFreshGatewayObject(); - $url = ResultPages::getCancelPage( $gateway ); - $expectedTitle = Title::newFromText( 'Ways to give/en' ); - $this->assertEquals( $expectedTitle->getFullURL(), $url ); - } - - public function testCannotOverrideIp() { - $data = $this->getDonorTestData( 'FR' ); - unset( $data['country'] ); - $data['user_ip'] = '8.8.8.8'; - - $gateway = $this->getFreshGatewayObject( $data ); - $this->assertEquals( '127.0.0.1', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); - } - - public function testCanOverrideIpInBatchMode() { - $data = $this->getDonorTestData( 'FR' ); - unset( $data['country'] ); - $data['user_ip'] = '8.8.8.8'; - - $gateway = $this->getFreshGatewayObject( $data, array( 'batch_mode' => true ) ); - $this->assertEquals( '8.8.8.8', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); - } - - function testGetScoreName() { - $rule = array( - 'KeyMapA' => array( 'a','s','d','f','q','w','e','r','t' ), - 'KeyMapB' => array(), - 'GibberishWeight' => .9, - 'Score' => 10 - ); - $this->setMwGlobals( - array( 'wgDonationInterfaceNameFilterRules' => array( $rule ) ) - ); - $init = $this->getDonorTestData(); - $init['fname'] = 'asdf'; - $init['lname'] = 'qwert'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->getScoreName(); - $this->assertNotEquals( 0, $result, 'Bad name not detected'); - } - - public function TestSetValidationAction() { - $data = $this->getDonorTestData( 'FR' ); - $gateway = $this->getFreshGatewayObject( $data ); - $gateway->setValidationAction( 'process' ); - $this->assertEquals( 'process', $gateway->getValidationAction(), 'Setup failed' ); - $gateway->setValidationAction( 'reject' ); - $this->assertEquals( 'reject', $gateway->getValidationAction(), 'Unable to escalate action' ); - $gateway->setValidationAction( 'process' ); - $this->assertEquals( 'reject', $gateway->getValidationAction(), 'De-escalating action without reset!' ); - } -} - ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/GlobalCollect/DirectDebitTest.php b/tests/Adapter/GlobalCollect/DirectDebitTest.php deleted file mode 100644 index 204cec6..0000000 --- a/tests/Adapter/GlobalCollect/DirectDebitTest.php +++ /dev/null @@ -1,82 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - * @group RealTimeBankTransfer - */ -class DonationInterface_Adapter_GlobalCollect_DirectDebitTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - ) ); - } - - /** - * testBuildRequestXml - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlForDirectDebitSpain() { - - $optionsForTestData = array( - 'payment_method' => 'dd', - 'payment_submethod' => 'dd_es', - 'payment_product_id' => 709, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - unset( $options['payment_submethod'] ); - - $dd_info_supplied = array ( - 'branch_code' => '123', - 'account_name' => 'Henry', - 'account_number' => '21', - 'bank_code' => '37', - 'bank_check_digit' => 'BD', - 'direct_debit_text' => 'testy test test', - ); - $dd_info_expected = array ( - 'branch_code' => '0123', //4, apparently. - 'account_name' => 'Henry', - 'account_number' => '0000000021', //10 - 'bank_code' => '0037', //4 - 'bank_check_digit' => 'BD', - 'direct_debit_text' => 'Wikimedia Foundation', //hard-coded in the gateway - ); - $optionsForTestData = array_merge( $optionsForTestData, $dd_info_expected ); - $options = array_merge( $options, $dd_info_supplied ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } -} - ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php b/tests/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php deleted file mode 100644 index bde0154..0000000 --- a/tests/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php +++ /dev/null @@ -1,274 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - */ -class GlobalCollectFormLoadTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $vmad_countries = array( 'US', ); - $vmaj_countries = array( - 'AD', 'AT', 'AU', 'BE', 'BH', 'DE', 'EC', 'ES', 'FI', 'FR', 'GB', - 'GF', 'GR', 'HK', 'IE', 'IT', 'JP', 'KR', 'LU', 'MY', 'NL', 'PR', - 'PT', 'SG', 'SI', 'SK', 'TH', 'TW', - ); - $vma_countries = array( - 'AE', 'AL', 'AN', 'AR', 'BG', 'CA', 'CH', 'CN', 'CR', 'CY', 'CZ', 'DK', - 'DZ', 'EE', 'EG', 'JO', 'KE', 'HR', 'HU', 'IL', 'KW', 'KZ', 'LB', 'LI', - 'LK', 'LT', 'LV', 'MA', 'MT', 'NO', 'NZ', 'OM', 'PK', 'PL', 'QA', 'RO', - 'RU', 'SA', 'SE', 'TN', 'TR', 'UA', - ); - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'discover' )), - 'countries' => array( - '+' => $vmad_countries, - ), - ), - 'cc-vmaj' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'jcb' )), - 'countries' => array( - '+' => $vmaj_countries, - ), - ), - 'cc-vma' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex' )), - 'countries' => array( - // Array merge with cc-vmaj as fallback in case 'j' goes down - // Array merge with cc-vmad as fallback in case 'd' goes down - '+' => array_merge( - $vmaj_countries, - $vmad_countries, - $vma_countries - ), - ), - ), - 'rtbt-sofo' => array( - 'gateway' => 'globalcollect', - 'countries' => array( - '+' => array( 'AT', 'BE', 'CH', 'DE' ), - '-' => 'GB' - ), - 'currencies' => array( '+' => 'EUR' ), - 'payment_methods' => array('rtbt' => 'rtbt_sofortuberweisung'), - ), - ), - ) ); - } - - public function testGCFormLoad() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmad'; - - $assertNodes = array ( - 'submethod-mc' => array ( - 'nodename' => 'input' - ), - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'USD', $init['language'] . '_' . $init['country'] ) - ). - '\s*$/', - ), - 'state' => array ( - 'nodename' => 'select', - 'selected' => 'CA', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - function testGCFormLoad_FR() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'fname' => array ( - 'nodename' => 'input', - 'value' => 'Prénom', - ), - 'lname' => array ( - 'nodename' => 'input', - 'value' => 'Nom', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'FR', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Ensure that form loads for Italy - */ - public function testGlobalCollectFormLoad_IT() { - $init = $this->getDonorTestData( 'IT' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'fname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-fname')->inLanguage( 'it' )->text(), - ), - 'lname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-lname')->inLanguage( 'it' )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( 'it' )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'IT', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Belgian form loads in all of that country's supported languages - * @dataProvider belgiumLanguageProvider - */ - public function testGlobalCollectFormLoad_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - $init['language'] = $language; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'fname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-fname')->inLanguage( $language )->text(), - ), - 'lname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-lname')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'BE', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Canadian CC form loads in English and French - * @dataProvider canadaLanguageProvider - */ - public function testGlobalCollectFormLoad_CA( $language ) { - $init = $this->getDonorTestData( 'CA' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vma'; - $init['language'] = $language; - $locale = $language . '_CA'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'CAD', $init['language'] . '_' . $init['country'] ) - ) . - '\s*$/', - ), - 'fname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-fname')->inLanguage( $language )->text(), - ), - 'lname' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-lname')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'state' => array ( - 'nodename' => 'select', - 'selected' => 'SK', - ), - 'zip' => array ( - 'nodename' => 'input', - 'value' => $init['zip'], - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'CA', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php b/tests/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php deleted file mode 100644 index e4e8767..0000000 --- a/tests/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php +++ /dev/null @@ -1,194 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?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, $useDB = false ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '55555', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '444444'; - $gateway->loadDataAndReInit( $data, $useDB = false ); - $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->assertNull( $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, $useDB = false ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '66666', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '777777'; - $gateway->loadDataAndReInit( $data, $useDB = false ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '777777', 'loadDataAndReInit failed to stick OrderID on second batch item' ); - - $this->verifyNoLogErrors(); - } - - public function testGCFormLoad() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmad'; - - $assertNodes = array ( - 'submethod-mc' => array ( - 'nodename' => 'input' - ), - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'USD', $init['language'] . '_' . $init['country'] ) - ). - '\s*$/', - ), - 'state' => array ( - 'nodename' => 'select', - 'selected' => 'CA', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * 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'] = '[email protected]'; - $gateway->loadDataAndReInit( $init, $useDB = false ); - - $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' ); - $this->assertTrue( array_key_exists( '1000001', $errors ), '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" ); - } - - /** - * Don't fraud-fail someone for bad CVV if GET_ORDERSTATUS - * comes back with STATUSID 25 and no CVVRESULT - * @group CvvResult - */ - function testConfirmCreditCardStatus25() { - $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'] = '[email protected]'; - - $gateway->loadDataAndReInit( $init, $useDB = false ); - $gateway->setDummyGatewayResponseCode( '25' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'process', $action, 'Gateway should not fraud fail on STATUSID 25' ); - } -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/GlobalCollect/GlobalCollectTest.php b/tests/Adapter/GlobalCollect/GlobalCollectTest.php deleted file mode 100644 index adc67fb..0000000 --- a/tests/Adapter/GlobalCollect/GlobalCollectTest.php +++ /dev/null @@ -1,616 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?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 - */ -class DonationInterface_Adapter_GlobalCollect_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 = 'TestingGlobalCollectAdapter'; - } - - /** - * testnormalizeOrderID - * Non-exhaustive integration tests to verify that order_id - * normalization works as expected with different settings and - * conditions in theGlobalCollect adapter - * @covers GatewayAdapter::normalizeOrderID - */ - public function testNormalizeOrderID() { - $request = $this->getDonorTestData(); - $externalData = $this->getDonorTestData(); - $session = array( 'Donor' => $this->getDonorTestData() ); - - //no order_id from anywhere, explicit no generate - $gateway = $this->getFreshGatewayObject( $externalData, 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->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Self order_id generation may be broken.' ); - $this->assertInternalType( 'numeric', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is not numeric, which it should be for GlobalCollect' ); - - // conflicting order_id in request and session, default GC generation - $request['order_id'] = '55555'; - $session['Donor']['order_id'] = '44444'; - $this->setUpRequest( $request, $session ); - $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '55555', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is preferring session data over the request. Session should be secondary.' ); - - // conflicting order_id in request and session, garbage data in request, default GC generation - $request['order_id'] = 'nonsense!'; - $this->setUpRequest( $request, $session ); - $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not ignoring nonsensical order_id candidates' ); - - // order_id in session, default GC generation - unset( $request['order_id'] ); - $this->setUpRequest( $request, $session ); - $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not recognizing the session order_id' ); - - // conflicting order_id in external data, request and session, explicit GC generation, batch mode - $request['order_id'] = '33333'; - $externalData['order_id'] = '22222'; - $this->setUpRequest( $request, $session ); - $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => true ), 'batch_mode' => true ) ); - $this->assertEquals( $externalData['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an extrenally provided order id is being honored in batch mode' ); - - //make sure that decimal numbers are rejected by GC. Should be a toss and regen - $externalData['order_id'] = '2143.0'; - unset( $request['order_id'] ); - unset( $session['Donor']['order_id'] ); - $this->setUpRequest( $request, $session ); - //conflicting order_id in external data, request and session, explicit GC generation, batch mode - $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => true, 'disallow_decimals' => true ), 'batch_mode' => true ) ); - $this->assertNotEquals( $externalData['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed assering that a decimal order_id was regenerated, when disallow_decimals is true' ); - } - - /** - * Non-exhaustive integration tests to verify that order_id, when in - * self-generation mode, won't regenerate until it is told to. - * @covers GatewayAdapter::normalizeOrderID - * @covers GatewayAdapter::regenerateOrderID - */ - function testStickyGeneratedOrderID() { - $init = self::$initial_vars; - unset( $init['order_id'] ); - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is null. The rest of this test is broken.' ); - $original_order_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - $gateway->normalizeOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has changed without explicit regeneration.' ); - - //this might look a bit strange, but we need to be able to generate valid order_ids without making them stick to anything. - $gateway->generateOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'function generateOrderID auto-changed the selected order ID. Not cool.' ); - - $gateway->regenerateOrderID(); - $this->assertNotEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has not changed, after explicit regeneration.' ); - } - - /** - * Integration test to verify that order_id can be retrieved from - * performing an INSERT_ORDERWITHPAYMENT. - */ - function testOrderIDRetrieval() { - $init = $this->getDonorTestData(); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Ungenerated order_id is not null. The rest of this test is broken.' ); - - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'No order_id was retrieved from INSERT_ORDERWITHPAYMENT' ); - } - - /** - * Just run the GET_ORDERSTATUS transaction and make sure we load the data - */ - function testGetOrderStatus() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - - $data = $gateway->getTransactionData(); - - $this->assertEquals( 'N', $data['CVVRESULT'], 'CVV Result not loaded from XML response' ); - } - - /** - * Don't fraud-fail someone for bad CVV if GET_ORDERSTATUS - * comes back with STATUSID 25 and no CVVRESULT - * @group CvvResult - */ - function testConfirmCreditCardStatus25() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '25' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'process', $action, 'Gateway should not fraud fail on STATUSID 25' ); - } - - /** - * If CVVRESULT is unrecognized, fraud-fail and warn - * @group CvvResult - */ - function testConfirmCreditCardBadCVVResult() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => ' ' ) ); - DonationInterface_FraudFiltersTest::setupFraudMaps( $this ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '800' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $result = $gateway->getCvvResult(); - $this->assertEquals( false, $result, 'Gateway should fraud fail if CVVRESULT is not mapped' ); - $matches = $this->getLogMatches( LogLevel::WARNING, "/Unrecognized cvv_result ' '$/" ); - $this->assertNotEmpty( $matches, 'Did not log expected warning on unmapped CVVRESULT' ); - } - - /** - * We should skip the API call if we're already suspicious - */ - function testGetOrderStatusSkipsIfFail() { - DonationInterface_FraudFiltersTest::setupFraudMaps( $this ); - - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; //configured as a fraudy domain - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - - $data = $gateway->getTransactionData(); - - $this->assertFalse( $data, 'preprocess should stop API call if fraud detected' ); - $this->assertEmpty( $gateway->curled, 'preprocess should stop API call if fraud detected' ); - } - - /** - * Ensure the Confirm_CreditCard transaction prefers CVVRESULT from the XML - * over any value from the querystring - */ - function testConfirmCreditCardPrefersXmlCvv() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - - $this->assertEquals( 'N', $gateway->getData_Unstaged_Escaped('cvv_result'), 'CVV Result not taken from XML response' ); - } - - /** - * If querystring and XML have different CVVRESULT, that's awfully fishy - */ - function testConfirmCreditCardFailsOnCvvResultConflict() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $result = $gateway->do_transaction( 'Confirm_CreditCard' ); - // FIXME: this is not a communication failure, it's a fraud failure - $this->assertFalse( $result->getCommunicationStatus(), 'Credit card should fail if querystring and XML have different CVVRESULT' ); - } - - /** - * Make sure we record the actual amount charged, even if the donor has - * opened a new window and screwed up their session data. - */ - function testConfirmCreditCardUpdatesAmount() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - // The values in session are not the values we originally used - // for INSERT_ORDERWITHPAYMENT - $init['amount'] = '12.50'; - $init['currency_code'] = 'USD'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $currency = $gateway->getData_Unstaged_Escaped( 'currency_code' ); - $this->assertEquals( '12.50', $amount ); - $this->assertEquals( 'USD', $currency ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $currency = $gateway->getData_Unstaged_Escaped( 'currency_code' ); - $this->assertEquals( '23.45', $amount, 'Not recording correct amount' ); - $this->assertEquals( 'EUR', $currency, 'Not recording correct currency' ); - } - - /** - * testDefineVarMap - * - * This is tested with a bank transfer from Spain. - * - * @covers GlobalCollectAdapter::__construct - * @covers GlobalCollectAdapter::defineVarMap - */ - public function testDefineVarMap() { - - $gateway = $this->getFreshGatewayObject( self::$initial_vars ); - - $var_map = array( - 'ORDERID' => 'order_id', - 'AMOUNT' => 'amount', - 'CURRENCYCODE' => 'currency_code', - 'LANGUAGECODE' => 'language', - 'COUNTRYCODE' => 'country', - 'MERCHANTREFERENCE' => 'contribution_tracking_id', - 'RETURNURL' => 'returnto', - 'IPADDRESS' => 'server_ip', - 'ISSUERID' => 'issuer_id', - 'PAYMENTPRODUCTID' => 'payment_product', - 'CVV' => 'cvv', - 'EXPIRYDATE' => 'expiration', - 'CREDITCARDNUMBER' => 'card_num', - 'FIRSTNAME' => 'fname', - 'SURNAME' => 'lname', - 'STREET' => 'street', - 'CITY' => 'city', - 'STATE' => 'state', - 'ZIP' => 'zip', - 'EMAIL' => 'email', - 'ACCOUNTHOLDER' => 'account_holder', - 'ACCOUNTNAME' => 'account_name', - 'ACCOUNTNUMBER' => 'account_number', - 'ADDRESSLINE1E' => 'address_line_1e', - 'ADDRESSLINE2' => 'address_line_2', - 'ADDRESSLINE3' => 'address_line_3', - 'ADDRESSLINE4' => 'address_line_4', - 'ATTEMPTID' => 'attempt_id', - 'AUTHORISATIONID' => 'authorization_id', - 'BANKACCOUNTNUMBER' => 'bank_account_number', - 'BANKAGENZIA' => 'bank_agenzia', - 'BANKCHECKDIGIT' => 'bank_check_digit', - 'BANKCODE' => 'bank_code', - 'BANKFILIALE' => 'bank_filiale', - 'BANKNAME' => 'bank_name', - 'BRANCHCODE' => 'branch_code', - 'COUNTRYCODEBANK' => 'country_code_bank', - 'COUNTRYDESCRIPTION' => 'country_description', - 'CUSTOMERBANKCITY' => 'customer_bank_city', - 'CUSTOMERBANKSTREET' => 'customer_bank_street', - 'CUSTOMERBANKNUMBER' => 'customer_bank_number', - 'CUSTOMERBANKZIP' => 'customer_bank_zip', - 'DATECOLLECT' => 'date_collect', - 'DESCRIPTOR' => 'descriptor', - 'DIRECTDEBITTEXT' => 'direct_debit_text', - 'DOMICILIO' => 'domicilio', - 'EFFORTID' => 'effort_id', - 'IBAN' => 'iban', - 'IPADDRESSCUSTOMER' => 'user_ip', - 'PAYMENTREFERENCE' => 'payment_reference', - 'PROVINCIA' => 'provincia', - 'SPECIALID' => 'special_id', - 'SWIFTCODE' => 'swift_code', - 'TRANSACTIONTYPE' => 'transaction_type', - 'FISCALNUMBER' => 'fiscal_number', - ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( $var_map, $exposed->var_map ); - } - - public function testLanguageStaging() { - $options = $this->getDonorTestData( 'NO' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $this->assertEquals( $exposed->getData_Staged( 'language' ), 'no', "'NO' donor's language was inproperly set. Should be 'no'" ); - } - - public function testLanguageFallbackStaging() { - $options = $this->getDonorTestData( 'Catalonia' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - // Requesting the fallback language from the gateway. - $this->assertEquals( 'en', $exposed->getData_Staged( 'language' ) ); - } - - /** - * Make sure unstaging functions don't overwrite core donor data. - */ - public function testAddResponseData_underzealous() { - $options = $this->getDonorTestData( 'Catalonia' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - // This will set staged_data['language'] = 'en'. - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->stageData(); - - $ctid = mt_rand(); - - $gateway->addResponseData( array( - 'contribution_tracking_id' => $ctid . '.1', - ) ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - // Desired vars were written into normalized data. - $this->assertEquals( $ctid, $exposed->dataObj->getVal_Escaped( 'contribution_tracking_id' ) ); - - // Language was not overwritten. - $this->assertEquals( 'ca', $exposed->dataObj->getVal_Escaped( 'language' ) ); - } - - /** - * Tests to make sure that certain error codes returned from GC will or - * will not create payments error loglines. - */ - function testCCLogsOnGatewayError() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - - //this should not throw any payments errors: Just an invalid card. - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '430285' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $this->verifyNoLogErrors(); - - //Now test one we want to throw a payments error - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '21000050' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $loglines = $this->getLogMatches( LogLevel::ERROR, '/Investigation required!/' ); - $this->assertNotEmpty( $loglines, 'GC Error 21000050 is not generating the expected payments log error' ); - - //Reset logs - $this->testLogger->messages = array(); - - //Most irritating version of 20001000 - They failed to enter an expiration date on GC's form. This should log some specific info, but not an error. - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '20001000-expiry' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $this->verifyNoLogErrors(); - $loglines = $this->getLogMatches( LogLevel::INFO, '/processResponse:.*EXPIRYDATE/' ); - $this->assertNotEmpty( $loglines, 'GC Error 20001000-expiry is not generating the expected payments log line' ); - } - - /** - * 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 ) { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - //Make it not look like an orphan - $this->setUpRequest( array( - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ) ); - - //Toxic card should not retry, even if there's an order id collision - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); - $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!" ); - - // Test limbo queue contents. - $this->assertEquals( array( true ), $gateway->limbo_messages, - "Gateway did not delete limbo message for code $code!" ); - } - - /** - * Tests that two API requests don't send the same order ID and merchant - * reference. This was the case when users doubleclicked and we were - * using the last 5 digits of time in seconds as a suffix. We want to see - * what happens when a 2nd request comes in while the 1st is still waiting - * for a CURL response, so here we fake that situation by having CURL throw - * an exception during the 1st response. - */ - public function testNoDupeOrderId( ) { - $this->setUpRequest( array( - 'action'=>'donate', - 'amount'=>'3.00', - 'card_type'=>'amex', - 'city'=>'Hollywood', - 'contribution_tracking_id'=>'22901382', - 'country'=>'US', - 'currency_code'=>'USD', - 'email'=>'[email protected]', - 'fname'=>'Fakety', - 'format'=>'json', - 'gateway'=>'globalcollect', - 'language'=>'en', - 'lname'=>'Fake', - 'payment_method'=>'cc', - 'referrer'=>'http://en.wikipedia.org/wiki/Main_Page', - 'state'=>'MA', - 'street'=>'99 Fake St', - 'utm_campaign'=>'C14_en5C_dec_dsk_FR', - 'utm_medium'=>'sitenotice', - 'utm_source'=>'B14_120921_5C_lg_fnt_sans.no-LP.cc', - 'zip'=>'90210' - ) ); - - $gateway = new TestingGlobalCollectAdapter( array( 'api_request' => 'true' ) ); - $gateway->setDummyGatewayResponseCode( 'Exception' ); - try { - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - } - catch ( Exception $e ) { - // totally expected this - } - $first = $gateway->curled[0]; - //simulate another request coming in before we get anything back from GC - $anotherGateway = new TestingGlobalCollectAdapter( array( 'api_request' => 'true' ) ); - $anotherGateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - $second = $anotherGateway->curled[0]; - $this->assertFalse( $first == $second, 'Two calls to the api did the same thing'); - } - - /** - * Tests to see that we don't claim we're going to retry when we aren't - * going to. For GC, we really only want to retry on code 300620 - * @dataProvider benignNoRetryCodeProvider - */ - public function testNoClaimRetryOnBoringCodes( $code ) { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - //Make it not look like an orphan - $this->setUpRequest( array( - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $start_id = $exposed->getData_Staged( 'order_id' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $finish_id = $exposed->getData_Staged( 'order_id' ); - $loglines = $this->getLogMatches( LogLevel::INFO, '/Repeating transaction on request for vars:/' ); - $this->assertEmpty( $loglines, "Log says we are going to repeat the transaction for code $code, but that is not true" ); - $this->assertEquals( $start_id, $finish_id, "Needlessly regenerated order id for code $code "); - } - - /** - * doPayment should return an iframe result with normal data - */ - function testDoPaymentSuccess() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['ffname'] = 'cc-vmad'; - 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' ); - $this->assertEquals( 'url_placeholder', $result->getIframe(), 'PaymentResult should have iframe set' ); - } - - /** - * doPayment should recover from an attempt to use a duplicate order ID. - */ - function testDuplicateOrderId() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['ffname'] = 'cc-vmad'; - unset( $init['order_id'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $orig_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $gateway->setDummyGatewayResponseCode( function ( $gateway ) use ( $orig_id ) { - if ( $gateway->getData_Unstaged_Escaped( 'order_id' ) === $orig_id ) { - return 'duplicate'; - } else { - return null; - } - } ); - $result = $gateway->doPayment(); - $this->assertEmpty( $result->isFailed(), 'PaymentResult should not be failed' ); - $this->assertEmpty( $result->getErrors(), 'PaymentResult should have no errors' ); - $this->assertNotEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), $orig_id, - 'Order ID regenerated in DonationData.' ); - $this->assertNotEquals( $gateway->session_getData( 'order_id' ), $orig_id, - 'Order ID regenerated in session.' ); - } -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php b/tests/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php deleted file mode 100644 index 7b118eb..0000000 --- a/tests/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php +++ /dev/null @@ -1,346 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - * @group RealTimeBankTransfer - */ -class DonationInterface_Adapter_GlobalCollect_RealTimeBankTransferIdealTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'rtbt-ideal' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('rtbt' => 'rtbt_ideal'), - 'countries' => array( '+' => 'NL' ), - 'currencies' => array( '+' => 'EUR' ), - ), - ), - ) ); - } - - /** - * Test for ideal form loading - */ - public function testGCFormLoad_rtbt_Ideal() { - $init = $this->getDonorTestData( 'NL' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'rtbt'; - $init['ffname'] = 'rtbt-ideal'; - - $assertNodes = array ( - //can't do the selected-amount test here, because apparently javascript. So... - - 'amount' => array ( - 'nodename' => 'input', - 'value' => '1.55', - ), - 'currency_code' => array ( - 'nodename' => 'select', - 'selected' => 'EUR', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'NL', - ), - ); - - $this->verifyFormOutput( 'TestingGlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * testBuildRequestXmlWithIssuerId21 - * - * Rabobank: 21 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId21() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 21, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId31 - * - * ABN AMRO: 31 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId31() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 31, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId91 - * - * Rabobank: 21 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId91() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 21, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId161 - * - * Van Lanschot Bankiers: 161 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId161() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 161, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId511 - * - * Triodos Bank: 511 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId511() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 511, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId721 - * - * ING: 721 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId721() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 721, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId751 - * - * SNS Bank: 751 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId751() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 751, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId761 - * - * ASN Bank: 761 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId761() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 761, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId771 - * - * RegioBank: 771 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId771() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 771, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForGlobalCollect( $optionsForTestData, $options ); - } - - public function testFormAction() { - - $optionsForTestData = array ( - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'issuer_id' => 771, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - - $this->gatewayAdapter = $this->getFreshGatewayObject( $options ); - $this->gatewayAdapter->do_transaction( "INSERT_ORDERWITHPAYMENT" ); - $action = $this->gatewayAdapter->getTransactionDataFormAction(); - $this->assertEquals( "url_placeholder", $action, "The formaction was not populated as expected (ideal)." ); - } - -} - ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/Adapter/PayPal/PayPalLegacyTest.php b/tests/Adapter/PayPal/PayPalLegacyTest.php deleted file mode 100644 index c71dff6..0000000 --- a/tests/Adapter/PayPal/PayPalLegacyTest.php +++ /dev/null @@ -1,296 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?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' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => $init['country'], //this works because it's a US donor... - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the DonateRecurring transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonateRecurring() { - $init = $this->getDonorTestData(); - $init['recurring'] = '1'; - $gateway = $this->getFreshGatewayObject( $init ); - - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'a3' => $init['amount'], //obviously. - 'currency_code' => $init['currency_code'], - 'country' => $init['country'], - 'business' => '[email protected]', - 'cmd' => '_xclick-subscriptions', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => $init['country'], //this works because it's a US donor... - 't3' => 'M', //hard-coded in transaction definition - 'p3' => '1', //hard-coded in transaction definition - 'src' => '1', //hard-coded in transaction definition - 'srt' => $gateway->getGlobal( 'RecurringLength' ), - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - ); - - $this->assertEquals( $expected, $res, 'Paypal "DonateRecurring" transaction not constructing the expected redirect URL' ); - } - - /** - * Integration test to verify that the Donate transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonateXclick() { - $init = $this->getDonorTestData(); - - 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' => '[email protected]', - 'cmd' => '_xclick', - 'item_name' => 'Donation to the Wikimedia Foundation', - 'item_number' => 'DONATE', - 'no_note' => '1', //hard-coded in transaction definition - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), -// 'lc' => $init['country'], //Apparently, this was removed from our implementation, because 'CN' is weird. - 'cancel_return' => 'https://example.com/tryAgain.php/en', - 'return' => 'https://example.org/wiki/Thank_You/en?country=US', - 'no_shipping' => '1', //hard-coded in transaction definition - ); - - $this->assertEquals( $expected, $res, 'Paypal "DonateXclick" transaction not constructing the expected redirect URL' ); - } - - /** - * Integration test to verify that the Paypal gateway redirects when validation is successful. - */ - function testRedirectFormOnValid() { - $init = $this->getDonorTestData(); - $session = array( 'Donor' => $init ); - - $that = $this; - $redirectTest = function( $location ) use ( $that, $init ) { - parse_str( parse_url( $location, PHP_URL_QUERY ), $actual ); - $that->assertEquals( $init['amount'], $actual['amount'] ); - }; - $assertNodes = array( - 'headers' => array( - 'Location' => $redirectTest, - ) - ); - - $this->verifyFormOutput( '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 ); - } - - /** - * Integration test to verify that the Donate transaction works as expected in Belgium for fr, de, and nl. - * - * @dataProvider belgiumLanguageProvider - */ - function testDoTransactionDonate_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - $init['language'] = $language; - $this->setLanguage( $language ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( $language )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => 'BE', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'BE', - 'cancel_return' => "https://example.com/tryAgain.php/$language", - 'return' => "https://example.org/wiki/Thank_You/$language?country=BE", - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the Donate transaction works as expected - * in Canada for English and French - * - * @dataProvider canadaLanguageProvider - */ - function testDoTransactionDonate_CA( $language ) { - $init = $this->getDonorTestData( 'CA' ); - $init['language'] = $language; - $this->setLanguage( $language ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( $language )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => 'CAD', - 'country' => 'CA', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'CA', - 'cancel_return' => "https://example.com/tryAgain.php/$language", - 'return' => "https://example.org/wiki/Thank_You/$language?country=CA", - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } - - /** - * Integration test to verify that the Donate transaction works as expected in Italy - */ - function testDoTransactionDonate_IT() { - $init = $this->getDonorTestData( 'IT' ); - $this->setLanguage( 'it' ); - $gateway = $this->getFreshGatewayObject( $init ); - $donateText = wfMessage( 'donate_interface-donation-description' )->inLanguage( 'it' )->text(); - $ret = $gateway->doPayment(); - parse_str( parse_url( $ret->getRedirect(), PHP_URL_QUERY ), $res ); - - $expected = array ( - 'amount' => $init['amount'], - 'currency_code' => $init['currency_code'], - 'country' => 'IT', - 'business' => '[email protected]', - 'cmd' => '_donations', - 'item_name' => $donateText, - 'item_number' => 'DONATE', - 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'lc' => 'IT', - 'cancel_return' => 'https://example.com/tryAgain.php/it', - 'return' => 'https://example.org/wiki/Thank_You/it?country=IT', - ); - - $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Paypal order_id is not null, and we shouldn't be generating one" ); - } -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/FormChooserTest.php b/tests/FormChooserTest.php deleted file mode 100644 index 697a989..0000000 --- a/tests/FormChooserTest.php +++ /dev/null @@ -1,198 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * @group Fundraising - * @group DonationInterface - * @group FormChooser - */ -class DonationInterface_FormChooserTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableFormChooser' => true, - 'wgGlobalCollectGatewayEnabled' => true, - 'wgPaypalGatewayEnabled' => true, - ) ); - - $this->setupMoreForms(); - } - - public function setupMoreForms() { - global $wgDonationInterfaceAllowedHtmlForms; - - $moreForms = array ( ); - - $moreForms['amazon'] = array( - 'gateway' => 'amazon', - 'payment_methods' => array( 'amazon' => 'ALL' ), - 'redirect', - ); - - $moreForms['cc-vmad'] = array ( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'cc' => array ( 'visa', 'mc', 'amex', 'discover' ) ), - 'countries' => array ( - '+' => array ( 'US', ), - ), - ); - - $moreForms['cc-vmaj'] = array ( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'cc' => array ( 'visa', 'mc', 'amex', 'jcb' ) ), - 'countries' => array ( - '+' => array ( 'AD', 'AT', 'AU', 'BE', 'BH', 'DE', 'EC', 'ES', 'FI', 'FR', 'GB', - 'GF', 'GR', 'HK', 'IE', 'IT', 'JP', 'KR', 'LU', 'MY', 'NL', 'PR', - 'PT', 'SG', 'SI', 'SK', 'TH', 'TW', ), - ), - ); - - $moreForms['cc-vma'] = array ( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'cc' => array ( 'visa', 'mc', 'amex' ) ), - 'countries' => array ( - // Array merge with cc-vmaj as fallback in case 'j' goes down - // Array merge with cc-vmad as fallback in case 'd' goes down - '+' => array_merge( - $moreForms['cc-vmaj']['countries']['+'], $moreForms['cc-vmad']['countries']['+'], array ( 'AE', 'AL', 'AN', 'AR', 'BG', 'CA', 'CH', 'CN', 'CR', 'CY', 'CZ', 'DK', - 'DZ', 'EE', 'EG', 'JO', 'KE', 'HR', 'HU', 'IL', 'KW', 'KZ', 'LB', 'LI', - 'LK', 'LT', 'LV', 'MA', 'MT', 'NO', 'NZ', 'OM', 'PK', 'PL', 'QA', 'RO', - 'RU', 'SA', 'SE', 'TN', 'TR', 'UA', ) - ) - ), - ); - - $moreForms['cc'] = array ( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'cc' => 'ALL' ), - 'countries' => array ( '-' => 'VN' ) - ); - - $moreForms['rtbt-ideal'] = array ( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'rtbt' => 'rtbt_ideal' ), - 'countries' => array ( '+' => 'NL' ), - 'currencies' => array ( '+' => 'EUR' ), - ); - - $moreForms['rtbt-sofo'] = array( - 'gateway' => 'globalcollect', - 'countries' => array( - '+' => array( 'AT', 'BE', 'CH', 'DE' ), - '-' => 'GB' - ), - 'currencies' => array( '+' => 'EUR' ), - 'payment_methods' => array('rtbt' => 'rtbt_sofortuberweisung'), - ); - - $moreForms['paypal'] = array ( - 'gateway' => 'paypal', - 'payment_methods' => array ( 'paypal' => 'ALL' ), - ); - - $this->setMwGlobals( array( - 'wgDonationInterfaceAllowedHtmlForms' => array_merge( - $wgDonationInterfaceAllowedHtmlForms, - $moreForms - ), - ) ); - } - - function testGetOneValidForm_CC_SpecificCountry() { - $tests = array ( - 0 => array ( - 'country' => 'US', - 'payment_method' => 'cc', - 'currency' => 'USD', - 'expected' => 'cc-vmad' - ), - 1 => array ( - 'country' => 'DK', - 'payment_method' => 'cc', - 'currency' => 'DKK', - 'expected' => 'cc-vma' - ), - ); - - foreach ( $tests as $testno => $data ) { - $form = GatewayFormChooser::getOneValidForm( $data['country'], $data['currency'], $data['payment_method'] ); - $this->assertEquals( $data['expected'], $form, "$form is not the preferred option for " . $data['payment_method'] . ' in ' . $data['country'] ); - } - } - - function testMaintenanceMode_Redirect() { - - $this->setMwGlobals( array( - 'wgContributionTrackingFundraiserMaintenance' => true, - ) ); - - $expectedLocation = Title::newFromText('Special:FundraiserMaintenance')->getFullURL(); - $assertNodes = array( - 'headers' => array( - 'Location' => $expectedLocation - ), - ); - $initial = array( - 'language' => 'en' - ); - $this->verifyFormOutput( 'GatewayFormChooser', $initial, $assertNodes, false ); - } - - /** - * currency_code should take precedence over currency, payment_method - * over paymentmethod, etc. - */ - function testPreferCanonicalParams() { - $self = $this; // someday, my upgrade will come - $assertNodes = array( - 'headers' => array( - 'Location' => function( $val ) use ( $self ) { - $qs = array(); - parse_str( parse_url( $val, PHP_URL_QUERY ), $qs ); - $self->assertEquals( 'paypal', $qs['ffname'], 'Wrong form' ); - } - ), - ); - $initial = array( - 'language' => 'en', - 'payment_method' => 'paypal', - 'paymentmethod' => 'amazon', - 'country' => 'US', - ); - $this->verifyFormOutput( 'GatewayFormChooser', $initial, $assertNodes, false ); - } -} - - ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/FraudFiltersTest.php b/tests/FraudFiltersTest.php deleted file mode 100644 index 92e434b..0000000 --- a/tests/FraudFiltersTest.php +++ /dev/null @@ -1,133 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * @group Fundraising - * @group DonationInterface - * @group FormChooser - */ -class DonationInterface_FraudFiltersTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - self::setupFraudMaps( $this ); - } - - public static function setupFraudMaps( $testContext ) { - // Declare so setMwGlobals can override. - global $wgGlobalCollectGatewayCustomFiltersFunctions; - $wgGlobalCollectGatewayCustomFiltersFunctions = null; - - - // Declare here cos reused. - $customFilters = array( - 'getScoreCountryMap' => 50, - 'getScoreUtmCampaignMap' => 50, - 'getScoreUtmSourceMap' => 15, - 'getScoreUtmMediumMap' => 15, - 'getScoreEmailDomainMap' => 75, - ); - - $testContext->setMwGlobals( array( - 'wgDonationInterfaceCustomFiltersActionRanges' => array ( - 'process' => array ( 0, 25 ), - 'review' => array ( 25, 50 ), - 'challenge' => array ( 50, 75 ), - 'reject' => array ( 75, 100 ), - ), - - 'wgDonationInterfaceCustomFiltersRefRules' => array ( - '/donate-error/i' => 5, - ), - - 'wgDonationInterfaceCustomFiltersSrcRules' => array ( '/wikimedia\.org/i' => 80 ), - - 'wgDonationInterfaceCustomFiltersFunctions' => $customFilters, - - 'wgGlobalCollectGatewayCustomFiltersFunctions' => array( - 'getCVVResult' => 20, - 'getAVSResult' => 25, - ) + $customFilters, - - 'wgDonationInterfaceCountryMap' => array ( - 'US' => 40, - 'CA' => 15, - 'RU' => -4, - ), - - 'wgDonationInterfaceUtmCampaignMap' => array ( - '/^(C14_)/' => 14, - '/^(spontaneous)/' => 5 - ), - 'wgDonationInterfaceUtmSourceMap' => array ( - '/somethingmedia/' => 70 - ), - 'wgDonationInterfaceUtmMediumMap' => array ( - '/somethingmedia/' => 80 - ), - 'wgDonationInterfaceEmailDomainMap' => array ( - 'wikimedia.org' => 42, - 'wikipedia.org' => 50, - ), - ) ); - } - - function testGCFraudFilters() { - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnableMinfraud' => true, - ) ); - - $options = $this->getDonorTestData(); - $options['email'] = '[email protected]'; - $class = $this->testAdapterClass; - - $gateway = $this->getFreshGatewayObject( $options ); - - $gateway->runAntifraudHooks(); - - $this->assertEquals( 'reject', $gateway->getValidationAction(), 'Validation action is not as expected' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 157.5, $exposed->risk_score, 'RiskScore is not as expected' ); - } -} -// Stub out Minfraud class for CI tests -if ( !class_exists( 'CreditCardFraudDetection' ) ) { - class CreditCardFraudDetection{ - public $server; - public function filter_field( $a, $b ) { - return 'blah'; - } - public function query() {} - public function input( $a ) {} - public function output() { - return array(); - } - } -} - ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php deleted file mode 100644 index d5fd1df..0000000 --- a/tests/IntegrationTest.php +++ /dev/null @@ -1,96 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?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 DIIntegration - */ -class DonationInterface_IntegrationTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array ( 'cc' => array ( 'visa', 'mc', 'amex', 'discover' ) ), - 'countries' => array ( - '+' => array ( 'US', ), - ), - ), - 'paypal' => array( - 'gateway' => 'paypal', - 'payment_methods' => array ( 'paypal' => 'ALL' ), - ), - ), - ) ); - } - - //this is meant to simulate a user choosing paypal, then going back and choosing GC. - public function testBackClickPayPalToGC() { - $options = $this->getDonorTestData( 'US' ); - $options['payment_method'] = 'paypal'; - $options['ffname'] = 'paypal'; - $paypalRequest = $this->setUpRequest( $options ); - - $gateway = new TestingPaypalLegacyAdapter(); - $gateway->do_transaction( 'Donate' ); - - $paymentForms = $paypalRequest->getSessionData( 'PaymentForms' ); - //check to see that we have a numAttempt and form set in the session - $this->assertEquals( 'paypal', $paymentForms[0], "Paypal didn't load its form." ); - $this->assertEquals( '1', $paypalRequest->getSessionData( 'numAttempt' ), "We failed to record the initial paypal attempt in the session" ); - //now, get GC. - $options['payment_method'] = 'cc'; - unset( $options['ffname'] ); - $this->setUpRequest( $options, $paypalRequest->getSessionArray() ); - $gateway = new TestingGlobalCollectAdapter(); - $response = $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - - $this->assertEmpty( $response->getErrors() ); - - $errors = ''; - if ( array_key_exists( LogLevel::ERROR, $this->testLogger->messages ) ) { - foreach ( $this->testLogger->messages[LogLevel::ERROR] as $msg ) { - $errors .= "$msg\n"; - } - } - $this->assertEmpty( $errors, "The gateway error log had the following message(s):\n" . $errors ); - } - -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/LoggingTest.php b/tests/LoggingTest.php deleted file mode 100644 index e0be99e..0000000 --- a/tests/LoggingTest.php +++ /dev/null @@ -1,163 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?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 - */ -class DonationInterface_LoggingTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceLogCompleted' => true, - ) ); - } - - /** - * @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 = 'TestingGlobalCollectAdapter'; - } - - /** - * Check that we can log completed transactions - */ - public function testLogCompleted() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['ffname'] = 'cc-vmad'; - unset( $init['order_id'] ); - - $expectedObject = array( - 'amount' => 23.45, - 'city' => 'San Francisco', - //'contribution_tracking_id' => '1', - 'country' => 'US', - 'currency_code' => 'EUR', - 'email' => '[email protected]', - 'fname' => 'Firstname', - 'gateway' => 'globalcollect', - 'language' => 'en', - 'lname' => 'Surname', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'recurring' => '', - 'state' => 'CA', - 'street' => '123 Fake Street', - 'user_ip' => '127.0.0.1', - 'utm_source' => '..cc', - 'zip' => '94105', - 'response' => 'Original Response Status (pre-SET_PAYMENT): 200', - 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceMessage', - 'gateway_account' => 'test', - ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; - $matches = $this->getLogMatches( LogLevel::INFO, $preface_pattern ); - $this->assertTrue( $matches !== false, - 'Should log a completion message' ); - - $json = str_replace( GatewayAdapter::COMPLETED_PREFACE, '', $matches[0] ); - $actualObject = $this->stripRandomFields( json_decode( $json, true ) ); - $this->assertEquals( $expectedObject, $actualObject, - 'Completion message is as expected' ); - } - - /** - * Test robustness when passed a bad Unicode string. - */ - public function testBadUnicode() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['amount'] = '23'; - // Fake name with a bad character encoding. - $init['fname'] = 'Алексан�'; - $init['lname'] = 'Гончар'; - $init['email'] = '[email protected]'; - $init['ffname'] = 'cc-vmad'; - $init['unusual_key'] = mt_rand(); - unset( $init['order_id'] ); - - $expectedObject = array( - 'amount' => 23.45, - 'city' => 'San Francisco', - 'country' => 'US', - 'currency_code' => 'EUR', - 'email' => '[email protected]', - 'fname' => 'Алексанï', - 'gateway' => 'globalcollect', - 'language' => 'en', - 'lname' => 'Гончар', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'recurring' => '', - 'state' => 'CA', - 'street' => '123 Fake Street', - 'user_ip' => '127.0.0.1', - 'utm_source' => '..cc', - 'zip' => '94105', - 'response' => 'Original Response Status (pre-SET_PAYMENT): 200', - 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceMessage', - 'gateway_account' => 'test', - ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; - $matches = $this->getLogMatches( LogLevel::INFO, $preface_pattern ); - $this->assertTrue( $matches !== false, - 'Should log a completion message' ); - - $json = str_replace( GatewayAdapter::COMPLETED_PREFACE, '', $matches[0] ); - $actualObject = $this->stripRandomFields( json_decode( $json, true ) ); - - $this->assertEquals( $expectedObject, $actualObject, - 'Completion message is as expected' ); - } - - protected function stripRandomFields( $data ) { - $toUnset = array( - 'contribution_tracking_id', - 'correlation-id', - 'date', - 'gateway_txn_id', - 'order_id', - ); - array_map( function ( $key ) use ( &$data ) { - unset( $data[$key] ); - }, $toUnset ); - return $data; - } -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/TestConfiguration.php b/tests/TestConfiguration.php deleted file mode 100644 index 77642e1..0000000 --- a/tests/TestConfiguration.php +++ /dev/null @@ -1,167 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This file contains custom options and constants for test configuration. - */ - -/** - * TESTS_MESSAGE_NOT_IMPLEMENTED - * - * Message for code that has not been implemented. - */ -define( 'TESTS_MESSAGE_NOT_IMPLEMENTED', 'Not implemented yet!' ); - -/** - * TESTS_HOSTNAME - * - * The hostname for the system - */ -define( 'TESTS_HOSTNAME', 'localhost' ); - -/** - * TESTS_EMAIL - * - * An email address to use in case test send mail - */ -define( 'TESTS_EMAIL', '[email protected]' ); - -/** - * TESTS_GATEWAY_DEFAULT - * - * This is the default gateway that will be used to implement unit tests. - */ -define( 'TESTS_GATEWAY_DEFAULT', 'GlobalCollectGateway' ); - -/** - * TESTS_ADAPTER_DEFAULT - * - * This is the default adapter that will be used to implement unit tests. - */ -define( 'TESTS_ADAPTER_DEFAULT', 'TestingGlobalCollectAdapter' ); - -global $wgDonationInterfaceTestMode, - $wgDonationInterfaceMerchantID, - $wgDonationInterfaceAllowedHtmlForms, - $wgDonationInterfaceThankYouPage, - $wgGlobalCollectGatewayAccountInfo, - $wgPaypalGatewayAccountInfo, - $wgPaypalGatewayReturnURL, - $wgAmazonGatewayReturnURL, - $wgAmazonGatewayAccountInfo, - $wgAdyenGatewayURL, - $wgAdyenGatewayAccountInfo, - $wgAstroPayGatewayURL, - $wgAstroPayGatewayTestingURL, - $wgAstroPayGatewayAccountInfo, - $wgAstroPayGatewayFallbackCurrency, - $wgMinFraudLicenseKey, - $wgMinFraudTimeout, - $wgDonationInterfaceMinFraudServers, - $wgDonationInterfaceEnableMinfraud, - $wgDonationInterfaceEnableFunctionsFilter, - $wgDonationInterfaceEnableReferrerFilter, - $wgDonationInterfaceEnableSourceFilter; - -/** - * Make sure the test setup is used, else we'll have the wrong classes. - */ -/** DonationInterface General Settings **/ -$wgDonationInterfaceTestMode = true; -$wgDonationInterfaceMerchantID = 'test'; - -$wgDonationInterfaceAllowedHtmlForms = array( - 'test' => array( - ), -); - -$wgDonationInterfaceThankYouPage = 'https://wikimediafoundation.org/wiki/Thank_You'; - - -/** GlobalCollect **/ -$wgGlobalCollectGatewayAccountInfo = array(); -$wgGlobalCollectGatewayAccountInfo['test'] = array( - 'MerchantID' => 'test', -); - - -/** Paypal **/ -$wgPaypalGatewayAccountInfo = array(); -$wgPaypalGatewayAccountInfo['testing'] = array( - 'AccountEmail' => '[email protected]', -); -$wgPaypalGatewayReturnURL = 'http://donate.wikimedia.org'; // whatever, doesn't matter. - - -/** Amazon **/ -$wgAmazonGatewayReturnURL = 'https://payments.wikimedia.org/index.php/Special:AmazonGateway'; -$wgAmazonGatewayAccountInfo = array(); -$wgAmazonGatewayAccountInfo['test'] = array( - 'SellerID' => 'ABCDEFGHIJKL', - 'ClientID' => 'amzn1.application-oa2-client.1a2b3c4d5e', - 'ClientSecret' => '12432g134e3421a41234b1341c324123d', - 'MWSAccessKey' => 'N0NSENSEXYZ', - 'MWSSecretKey' => 'iuasd/2jhaslk2j49lkaALksdJLsJLas+', - 'Region' => 'us', - 'WidgetScriptURL' => - 'https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js', - 'ReturnURL' => "https://example.org/index.php/Special:AmazonGateway?debug=true", -); - -/** Adyen **/ -$wgAdyenGatewayURL = 'https://testorwhatever.adyen.com'; -$wgAdyenGatewayAccountInfo = array(); -$wgAdyenGatewayAccountInfo['test'] = array( - 'AccountName' => 'wikitest', - 'SharedSecret' => 'C7F1D9E29479CF18131063A742CD2703FB9D48BAB0160693045E3FB7B8508E59', - 'SkinCode' => 'testskin', -); - -/** AstroPay **/ -$wgAstroPayGatewayURL = 'https://astropay.example.com/'; -$wgAstroPayGatewayTestingURL = 'https://sandbox.astropay.example.com/'; -$wgAstroPayGatewayAccountInfo = array(); -$wgAstroPayGatewayAccountInfo['test'] = array( - 'Create' => array( - 'Login' => 'createlogin', - 'Password' => 'createpass', - ), - 'Status' => array( - 'Login' => 'statuslogin', - 'Password' => 'statuspass', - ), - 'SecretKey' => 'NanananananananananananananananaBatman', -); -$wgAstroPayGatewayFallbackCurrency = false; - -$wgMinFraudLicenseKey = 'testkey'; -$wgMinFraudTimeout = 1; -$wgDonationInterfaceMinFraudServers = array( "minfraud.wikimedia.org" ); - -// Don't connect to the queue. -$wgDonationInterfaceEnableQueue = false; - -// still can't quite handle mindfraud by itself yet, so default like this. -// I will turn it on for individual tests in which I want to verify that it at -// least fails closed when enabled. -$wgDonationInterfaceEnableMinfraud = false; - -// ...but we want these. -$wgDonationInterfaceEnableFunctionsFilter = true; -$wgDonationInterfaceEnableReferrerFilter = true; -$wgDonationInterfaceEnableSourceFilter = true; ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) diff --git a/tests/includes/test_gateway/TestingGlobalCollectAdapter.php b/tests/includes/test_gateway/TestingGlobalCollectAdapter.php deleted file mode 100644 index d9c10ba..0000000 --- a/tests/includes/test_gateway/TestingGlobalCollectAdapter.php +++ /dev/null @@ -1,147 +0,0 @@ -<<<<<<< HEAD (33dd4a Disable Adyen JCB) -======= -<?php - -/** - * TestingGlobalCollectAdapter - * - * TODO: Add dependency injection to the base class so we don't have to repeat code here. - */ -class TestingGlobalCollectAdapter extends GlobalCollectAdapter { - - public $curled = array ( ); - - public $limbo_messages = array(); - - public $dummyGatewayResponseCode; - - /** - * Also set a useful MerchantID. - */ - public function __construct( $options = array ( ) ) { - if ( is_null( $options ) ) { - $options = array ( ); - } - - //I hate myself for this part, and so do you. - //Deliberately not fixing the actual problem for this patchset. - //@TODO: Change the way the constructor works in all adapter - //objects, such that the mess I am about to make is no longer - //necessary. A patchset may already be near-ready for this... - if ( array_key_exists( 'order_id_meta', $options ) ) { - $this->order_id_meta = $options['order_id_meta']; - unset( $options['order_id_meta'] ); - } - - $this->options = $options; - - parent::__construct( $this->options ); - } - - /** - * @TODO: Get rid of this and the override mechanism as soon as you - * refactor the constructor into something reasonable. - */ - public function defineOrderIDMeta() { - if ( isset( $this->order_id_meta ) ) { - return; - } - parent::defineOrderIDMeta(); - } - - // TODO: Store and test the actual messages. - public function setLimboMessage( $queue = 'pending' ) { - $this->limbo_messages[] = false; - } - - /** - * Stub out the limboStomp fn and record the calls - */ - public function deleteLimboMessage( $queue = 'pending' ) { - $this->limbo_messages[] = true; - } - - //@TODO: That minfraud jerk needs its own isolated tests. - function runAntifraudHooks() { - //now screw around with the batch settings to trick the fraud filters into triggering - $is_batch = $this->isBatchProcessor(); - $this->batch = true; - - parent::runAntifraudHooks(); - - $this->batch = $is_batch; - } - - /** - * Set the error code you want the dummy response to return - */ - public function setDummyGatewayResponseCode( $code ) { - $this->dummyGatewayResponseCode = $code; - } - - /** - * Set the error code you want the dummy response to return - */ - public function setDummyCurlResponseCode( $code ) { - $this->dummyCurlResponseCode = $code; - } - - protected function curl_transaction( $data ) { - $this->curled[] = $data; - return parent::curl_transaction( $data ); - } - - /** - * Load in some dummy response XML so we can test proper response processing - * @throws RuntimeException - */ - protected function curl_exec( $ch ) { - $code = ''; - if ( $this->dummyGatewayResponseCode ) { - if ( is_array( $this->dummyGatewayResponseCode ) ) { - $code = array_shift( $this->dummyGatewayResponseCode ); - } elseif ( is_callable( $this->dummyGatewayResponseCode ) ) { - $code = call_user_func( $this->dummyGatewayResponseCode, $this ); - } else { - $code = $this->dummyGatewayResponseCode; - } - } - if ( $code ) { - if ( $code === 'Exception' ) { - throw new RuntimeException('blah!'); - } - $code = '_' . $code; - } - - //could start stashing these in a further-down subdir if payment type starts getting in the way, - //but frankly I don't want to write tests that test our dummy responses. - $file_path = __DIR__ . '/../'; - $file_path .= 'Responses' . '/' . self::getIdentifier() . '/'; - $file_path .= $this->getCurrentTransaction() . $code . '.testresponse'; - - //these are all going to be short, so... - if ( file_exists( $file_path ) ) { - return file_get_contents( $file_path ); - } else { - echo "File $file_path does not exist.\n"; //<-That will deliberately break the test. - return false; - } - } - - /** - * Load in some dummy curl response info so we can test proper response processing - */ - protected function curl_getinfo( $ch, $opt = null ) { - $code = 200; //response OK - if ( property_exists( $this, 'dummyCurlResponseCode' ) ) { - $code = ( int ) $this->dummyCurlResponseCode; - } - - //put more here if it ever turns out that we care about it. - return array ( - 'http_code' => $code, - ); - } - -} ->>>>>>> BRANCH (acf7a3 Localisation updates from https://translatewiki.net.) -- To view, visit https://gerrit.wikimedia.org/r/300320 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4911b0ef2183d208f344336ef2b3387dbea44685 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <[email protected]> Gerrit-Reviewer: Ejegg <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
