Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/330733 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment 05c6cf9 Remove donationinterface-desc from extension.json aa270db Rename 'zip' to 'postal_code' Change-Id: I072225b0602fae6c6fbf1e63d24a31b70780949e --- D tests/phpunit/Adapter/Adyen/AdyenTest.php D tests/phpunit/Adapter/GatewayAdapterTest.php D tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php D tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php D tests/phpunit/DonationDataTest.php D tests/phpunit/DonationInterfaceTestCase.php D tests/phpunit/DonationQueueTest.php D tests/phpunit/GatewayPageTest.php D tests/phpunit/LoggingTest.php 9 files changed, 0 insertions(+), 2,994 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/33/330733/1 diff --git a/tests/phpunit/Adapter/Adyen/AdyenTest.php b/tests/phpunit/Adapter/Adyen/AdyenTest.php deleted file mode 100644 index c2763b2..0000000 --- a/tests/phpunit/Adapter/Adyen/AdyenTest.php +++ /dev/null @@ -1,157 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Adyen - */ -class DonationInterface_Adapter_Adyen_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 = 'TestingAdyenAdapter'; - } - - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgAdyenGatewayEnabled' => true, - ) ); - } - - /** - * 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 ); - - $gateway->do_transaction( 'donate' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $ret = $exposed->buildRequestParams(); - - $expected = array ( - 'allowedMethods' => 'card', - 'billingAddress.street' => $init['street'], - 'billingAddress.city' => $init['city'], - 'billingAddress.postalCode' => $init['postal_code'], - 'billingAddress.stateOrProvince' => $init['state'], - 'billingAddress.country' => $init['country'], - 'billingAddress.houseNumberOrName' => 'NA', - 'billingAddressType' => 2, - 'card.cardHolderName' => $init['fname'] . ' ' . $init['lname'], - 'currencyCode' => $init['currency_code'], - 'merchantAccount' => 'wikitest', - 'merchantReference' => $exposed->getData_Staged( 'order_id' ), - 'merchantSig' => $exposed->getData_Staged( 'hpp_signature' ), - 'paymentAmount' => ($init['amount']) * 100, -// 'sessionValidity' => '2014-03-09T19:41:50+00:00', //commenting out, because this is a problem. -// 'shipBeforeDate' => $exposed->getData_Staged( 'expiration' ), //this too. - 'skinCode' => 'testskin', - 'shopperLocale' => 'en_US', - 'shopperEmail' => 'nob...@wikimedia.org', - 'offset' => '52', //once we construct the FraudFiltersTestCase, it should land here. - ); - - //deal with problem keys. - //@TODO: Refactor gateway so these are more testable - $problems = array ( - 'sessionValidity', - 'shipBeforeDate', - ); - - foreach ( $problems as $oneproblem ) { - if ( isset( $ret[$oneproblem] ) ) { - unset( $ret[$oneproblem] ); - } - } - - $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); - } - - function testRiskScoreAddedToQueueMessage() { - $init = $this->getDonorTestData(); - $gateway = $this->getFreshGatewayObject( $init ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->risk_score = 57; - $message = $exposed->getStompTransaction(); - $this->assertEquals( 57, $message['risk_score'], 'Risk score was not correctly added to queue message.' ); - } - - /** - * Make sure language is staged correctly when qs param is uppercase - */ - function testLanguageCaseSensitivity() { - $init = $this->getDonorTestData(); - $init['language'] = 'FR'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'donate' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $ret = $exposed->buildRequestParams(); - - $expected = array ( - 'allowedMethods' => 'card', - 'billingAddress.street' => $init['street'], - 'billingAddress.city' => $init['city'], - 'billingAddress.postalCode' => $init['postal_code'], - 'billingAddress.stateOrProvince' => $init['state'], - 'billingAddress.country' => $init['country'], - 'billingAddress.houseNumberOrName' => 'NA', - 'billingAddressType' => 2, - 'card.cardHolderName' => $init['fname'] . ' ' . $init['lname'], - 'currencyCode' => $init['currency_code'], - 'merchantAccount' => 'wikitest', - 'merchantReference' => $exposed->getData_Staged( 'order_id' ), - 'merchantSig' => $exposed->getData_Staged( 'hpp_signature' ), - 'paymentAmount' => ($init['amount']) * 100, - 'skinCode' => 'testskin', - 'shopperLocale' => 'fr_US', - 'shopperEmail' => 'nob...@wikimedia.org', - 'offset' => '52', - ); - - //deal with problem keys. - //@TODO: Refactor gateway so these are more testable - $problems = array ( - 'sessionValidity', - 'shipBeforeDate', - ); - - foreach ( $problems as $oneproblem ) { - if ( isset( $ret[$oneproblem] ) ) { - unset( $ret[$oneproblem] ); - } - } - - $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); - } -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/Adapter/GatewayAdapterTest.php b/tests/phpunit/Adapter/GatewayAdapterTest.php deleted file mode 100644 index 65dfa27..0000000 --- a/tests/phpunit/Adapter/GatewayAdapterTest.php +++ /dev/null @@ -1,338 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * TODO: Test everything. - * Make sure all the basic functions in the gateway_adapter are tested here. - * Also, the filters 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 testPostalCodeStaging() { - $options = $this->getDonorTestData( 'BR' ); - unset( $options['postal_code'] ); - $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( 'postal_code' ), - '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 ); - $this->assertEquals( 'rapidFailError', ResultPages::getFailPage( $gateway ) ); - } - - 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 (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php deleted file mode 100644 index 207e04b..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectFormLoadTest.php +++ /dev/null @@ -1,274 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - */ -class GlobalCollectFormLoadTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $vmad_countries = array( 'US', ); - $vmaj_countries = array( - 'AD', 'AT', 'AU', 'BE', 'BH', 'DE', 'EC', 'ES', 'FI', 'FR', 'GB', - 'GF', 'GR', 'HK', 'IE', 'IT', 'JP', 'KR', 'LU', 'MY', 'NL', 'PR', - 'PT', 'SG', 'SI', 'SK', 'TH', 'TW', - ); - $vma_countries = array( - 'AE', 'AL', 'AN', 'AR', 'BG', 'CA', 'CH', 'CN', 'CR', 'CY', 'CZ', 'DK', - 'DZ', 'EE', 'EG', 'JO', 'KE', 'HR', 'HU', 'IL', 'KW', 'KZ', 'LB', 'LI', - 'LK', 'LT', 'LV', 'MA', 'MT', 'NO', 'NZ', 'OM', 'PK', 'PL', 'QA', 'RO', - 'RU', 'SA', 'SE', 'TN', 'TR', 'UA', - ); - $this->setMwGlobals( array( - 'wgGlobalCollectGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'discover' )), - 'countries' => array( - '+' => $vmad_countries, - ), - ), - 'cc-vmaj' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'jcb' )), - 'countries' => array( - '+' => $vmaj_countries, - ), - ), - 'cc-vma' => array( - 'gateway' => 'globalcollect', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex' )), - 'countries' => array( - // Array merge with cc-vmaj as fallback in case 'j' goes down - // Array merge with cc-vmad as fallback in case 'd' goes down - '+' => array_merge( - $vmaj_countries, - $vmad_countries, - $vma_countries - ), - ), - ), - 'rtbt-sofo' => array( - 'gateway' => 'globalcollect', - 'countries' => array( - '+' => array( 'AT', 'BE', 'CH', 'DE' ), - '-' => 'GB' - ), - 'currencies' => array( '+' => 'EUR' ), - 'payment_methods' => array('rtbt' => 'rtbt_sofortuberweisung'), - ), - ), - ) ); - } - - public function testGCFormLoad() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmad'; - - $assertNodes = array ( - 'submethod-mc' => array ( - 'nodename' => 'input' - ), - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'USD', $init['language'] . '_' . $init['country'] ) - ). - '\s*$/', - ), - 'state' => array ( - 'nodename' => 'select', - 'selected' => 'CA', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - function testGCFormLoad_FR() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'fname' => array ( - 'nodename' => 'input', - 'value' => 'Prénom', - ), - 'lname' => array ( - 'nodename' => 'input', - 'value' => 'Nom', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'FR', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Ensure that form loads for Italy - */ - public function testGlobalCollectFormLoad_IT() { - $init = $this->getDonorTestData( 'IT' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - '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( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Belgian form loads in all of that country's supported languages - * @dataProvider belgiumLanguageProvider - */ - public function testGlobalCollectFormLoad_BE( $language ) { - $init = $this->getDonorTestData( 'BE' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - $init['language'] = $language; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - '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( 'GlobalCollectGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Canadian CC form loads in English and French - * @dataProvider canadaLanguageProvider - */ - public function testGlobalCollectFormLoad_CA( $language ) { - $init = $this->getDonorTestData( 'CA' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vma'; - $init['language'] = $language; - $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', - ), - 'postal_code' => array ( - 'nodename' => 'input', - 'value' => $init['postal_code'], - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'CA', - ), - ); - - $this->verifyFormOutput( 'GlobalCollectGateway', $init, $assertNodes, true ); - } -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php deleted file mode 100644 index 95f0005..0000000 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php +++ /dev/null @@ -1,585 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - */ -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'] = 'innoc...@safedomain.org'; - - $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'] = 'innoc...@safedomain.org'; - - $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' ); - } - - /** - * Make sure we're incorporating GET_ORDERSTATUS AVS and CVV responses into - * fraud scores. - */ - function testGetOrderstatusPostProcessFraud() { - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableCustomFilters' => true, - 'wgGlobalCollectGatewayCustomFiltersFunctions' => array( - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - ) ); - - $init = $this->getDonorTestData(); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = 'innoc...@manichean.com'; - $init['contribution_tracking_id'] = mt_rand(); - $init['payment_method'] = 'cc'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'review', $action, - 'Orphan gateway should fraud fail on bad CVV and AVS' ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 40, $exposed->risk_score, - 'Risk score was incremented correctly.' ); - } - - /** - * 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'] = 'innoc...@safedomain.org'; - - $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' ); - } - - /** - * 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'] = 'innoc...@safedomain.org'; - // 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' => 'postal_code', - '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', - 'AVSRESULT' => 'avs_result', - 'CVVRESULT' => 'cvv_result', - ); - - $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!" ); - } - - /** - * 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'=>'faketyf...@gmail.com', - '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', - 'postal_code'=>'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'] = 'innoc...@clean.com'; - $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'] = 'innoc...@localhost.net'; - $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 (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/DonationDataTest.php b/tests/phpunit/DonationDataTest.php deleted file mode 100644 index 6a5e083..0000000 --- a/tests/phpunit/DonationDataTest.php +++ /dev/null @@ -1,410 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * @group Fundraising - * @group DonationInterface - * @group Splunge - * @group DonationData - */ -class DonationInterface_DonationDataTest 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 = '' ) { - $request = RequestContext::getMain()->getRequest(); - - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - - $this->testData = array( - 'amount' => '128.00', - 'appeal' => 'JimmyQuote', - 'email' => 'unitt...@example.com', - 'fname' => 'Testocres', - 'lname' => 'McTestingyou', - 'street' => '123 Fake Street', - 'city' => 'Springfield', - 'state' => 'US', - 'postal_code' => '99999', - 'country' => 'US', - 'card_num' => '42', - 'card_type' => 'visa', - 'expiration' => '1138', - 'cvv' => '665', - 'currency_code' => 'USD', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'numAttempt' => '5', - 'referrer' => 'http://www.testing.com/', - 'utm_source' => '..cc', - 'utm_medium' => 'large', - 'utm_campaign' => 'yes', - 'email-opt' => '', - 'test_string' => '', - 'wmf_token' => '113811', - 'contribution_tracking_id' => '', - 'data_hash' => '', - 'action' => '', - 'gateway' => 'DonationData', - 'owa_session' => '', - 'owa_ref' => 'http://localhost/importedTestData', - 'user_ip' => $request->getIP(), - 'server_ip' => $request->getIP(), - ); - - } - - - /** - * @covers DonationData::__construct - * @covers DonationData::getDataEscaped - * @covers DonationData::populateData - */ - public function testConstruct(){ - $context = RequestContext::getMain(); - $request = $context->getRequest(); - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ) ); //as if we were posted. - $returned = $ddObj->getDataEscaped(); - $expected = array( 'posted' => '', - 'amount' => '0.00', - 'appeal' => 'JimmyQuote', - 'country' => 'XX', - 'payment_method' => '', - 'referrer' => '', - 'utm_source' => '..', - 'language' => $context->getLanguage()->getCode(), - 'gateway' => 'globalcollect', - 'payment_submethod' => '', - 'recurring' => '', - 'user_ip' => $request->getIP(), - 'server_ip' => $request->getIP(), - ); - unset($returned['contribution_tracking_id']); - unset($returned['order_id']); - $this->assertEquals($expected, $returned, "Staged post data does not match expected (largely empty)."); - } - - /** - * Test construction with external data (for tests and possible batch operations) - */ - public function testConstructWithExternalData() { - $request = RequestContext::getMain()->getRequest(); - - $expected = array ( - 'amount' => '35.00', - 'appeal' => 'JimmyQuote', - 'contribution_tracking_id' => mt_rand(), - 'email' => 'testingd...@wikimedia.org', - 'fname' => 'Tester', - 'lname' => 'Testington', - 'street' => '548 Market St.', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postal_code' => '94104', - 'country' => 'US', - 'card_num' => '378282246310005', - 'card_type' => 'amex', - 'expiration' => '0415', - 'cvv' => '001', - 'currency_code' => 'USD', - 'payment_method' => 'cc', - 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar', - 'utm_source' => 'test_src..cc', - 'utm_medium' => 'test_medium', - 'utm_campaign' => 'test_campaign', - 'language' => 'en', - 'wmf_token' => '', - 'data_hash' => '', - 'action' => '', - 'gateway' => 'globalcollect', - 'owa_session' => '', - 'owa_ref' => 'http://localhost/defaultTestData', - 'street_supplemental' => '3rd floor', - 'payment_submethod' => 'amex', - 'issuer_id' => '', - 'utm_source_id' => '', - 'user_ip' => '12.12.12.12', - 'server_ip' => $request->getIP(), - 'recurring' => '', - ); - - $adapter = $this->getFreshGatewayObject( self::$initial_vars, array( 'batch_mode' => true ) ); - $ddObj = new DonationData( $adapter, $expected ); //external data - $returned = $ddObj->getDataEscaped(); - - - $this->assertNotNull( $returned['contribution_tracking_id'], 'There is no contribution tracking ID' ); - $this->assertNotEquals( $returned['contribution_tracking_id'], '', 'There is not a valid contribution tracking ID' ); - - unset($returned['order_id']); - - $this->assertEquals($expected, $returned, "Staged default test data does not match expected."); - } - - /** - * Test construction with data jammed in request. - */ - public function testConstructWithFauxRequest() { - $request = RequestContext::getMain()->getRequest(); - - $expected = array ( - 'amount' => '35.00', - 'appeal' => 'JimmyQuote', - 'email' => 'testingd...@wikimedia.org', - 'fname' => 'Tester', - 'lname' => 'Testington', - 'street' => '548 Market St.', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postal_code' => '94104', - 'country' => 'US', - 'card_num' => '378282246310005', - 'card_type' => 'amex', - 'expiration' => '0415', - 'cvv' => '001', - 'currency_code' => 'USD', - 'payment_method' => 'cc', - 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar', - 'utm_source' => 'test_src..cc', - 'utm_medium' => 'test_medium', - 'utm_campaign' => 'test_campaign', - 'language' => 'en', - 'gateway' => 'globalcollect', - 'owa_ref' => 'http://localhost/getTestData', - 'street_supplemental' => '3rd floor', - 'payment_submethod' => 'amex', - 'user_ip' => $request->getIP(), - 'server_ip' => $request->getIP(), - 'recurring' => '', - 'posted' => '', - ); - - RequestContext::getMain()->setRequest( new FauxRequest( $expected, false ) ); - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ) ); //Get all data from request - $returned = $ddObj->getDataEscaped(); - - $this->assertNotNull( $returned['contribution_tracking_id'], 'There is no contribution tracking ID' ); - $this->assertNotEquals( $returned['contribution_tracking_id'], '', 'There is not a valid contribution tracking ID' ); - - unset( $returned['order_id'] ); - unset( $returned['contribution_tracking_id'] ); - - $this->assertEquals( $expected, $returned, "Staged default test data does not match expected." ); - } - - /** - * Check that constructor outputs certain information to logs - */ - public function testDebugLog() { - $expected = array ( - 'payment_method' => 'cc', - 'utm_source' => 'test_src..cc', - 'utm_medium' => 'test_medium', - 'utm_campaign' => 'test_campaign', - 'payment_submethod' => 'amex', - 'currency_code' => 'USD', - ); - - $this->setUpRequest( $expected ); - - $ddObj = new DonationData( $this->getFreshGatewayObject( ) ); - $matches = $this->getLogMatches( LogLevel::DEBUG, '/setUtmSource: Payment method is cc, recurring = false, utm_source = cc$/' ); - $this->assertNotEmpty( $matches ); - $matches = $this->getLogMatches( LogLevel::DEBUG, "/Got currency from 'currency_code', now: USD$/" ); - $this->assertNotEmpty( $matches ); - } - - /** - * - */ - public function testRepopulate(){ - $expected = $this->testData; - - // Some changes from the default - $expected['recurring'] = ''; - $expected['language'] = RequestContext::getMain()->getLanguage()->getCode(); - $expected['gateway'] = 'globalcollect'; - - // Just unset a handful... doesn't matter what, really. - unset($expected['comment-option']); - unset($expected['email-opt']); - unset($expected['test_string']); - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $expected ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - //unset these, because they're always new - $unsettable = array( - 'order_id', - 'contribution_tracking_id' - ); - - foreach ( $unsettable as $thing ) { - unset( $returned[$thing] ); - unset( $expected[$thing] ); - } - - $this->assertEquals( $expected, $returned, "The forced test data did not populate as expected." ); - } - - /** - * - */ - public function testIsSomething(){ - $data = $this->testData; - unset( $data['postal_code'] ); - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $this->assertEquals($ddObj->isSomething('postal_code'), false, "Zip should currently be nothing."); - $this->assertEquals($ddObj->isSomething('lname'), true, "Lname should currently be something."); - } - - /** - * - */ - public function testSetNormalizedAmount_amtGiven() { - $data = $this->testData; - $data['amount'] = 'this is not a number'; - $data['amountGiven'] = 42.50; - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 42.50, $returned['amount'], "Amount was not properly reset" ); - $this->assertArrayNotHasKey( 'amountGiven', $returned, "amountGiven should have been removed from the data" ); - } - - /** - * - */ - public function testSetNormalizedAmount_amount() { - $data = $this->testData; - $data['amount'] = 88.15; - $data['amountGiven'] = 42.50; - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 88.15, $returned['amount'], "Amount was not properly reset" ); - $this->assertArrayNotHasKey( 'amountGiven', $returned, "amountGiven should have been removed from the data" ); - } - - /** - * - */ - public function testSetNormalizedAmount_negativeAmount() { - $data = $this->testData; - $data['amount'] = -1; - $data['amountOther'] = 3.25; - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals(3.25, $returned['amount'], "Amount was not properly reset"); - $this->assertArrayNotHasKey( 'amountOther', $returned, "amountOther should have been removed from the data"); - } - - /** - * - */ - public function testSetNormalizedAmount_noGoodAmount() { - $data = $this->testData; - $data['amount'] = 'splunge'; - $data['amountGiven'] = 'wombat'; - $data['amountOther'] = 'macedonia'; - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 'invalid', $returned['amount'], "Amount was not properly reset"); - $this->assertArrayNotHasKey( 'amountOther', $returned, "amountOther should have been removed from the data"); - $this->assertArrayNotHasKey( 'amountGiven', $returned, "amountGiven should have been removed from the data"); - } - - /** - * If the currency code is not three letters, we should try to guess it from - * the country code. - */ - public function testSetNormalizedCurrencyCode_BadData() { - $data = $this->testData; - // When missing or not a recognized currency code, we'll guess from the - // country - in this test data, US. - $data['currency_code'] = 'splunge'; - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 'USD', $returned['currency_code'], 'Currency code was not properly reset'); - } - - /** - * - */ - public function testSetNormalizedLanguage_uselang() { - $data = $this->testData; - unset( $data['uselang'] ); - unset( $data['language'] ); - - $data['uselang'] = 'no'; - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 'no', $returned['language'], "Language 'no' was normalized out of existance. Sad." ); - $this->assertArrayNotHasKey( 'uselang', $returned, "'uselang' should have been removed from the data" ); - } - - /** - * - */ - public function testSetNormalizedLanguage_language() { - $data = $this->testData; - unset( $data['uselang'] ); - unset( $data['language'] ); - - $data['language'] = 'no'; - - $ddObj = new DonationData( $this->getFreshGatewayObject( self::$initial_vars ), $data ); //change to test mode with explicit test data - $returned = $ddObj->getDataEscaped(); - $this->assertEquals( 'no', $returned['language'], "Language 'no' was normalized out of existance. Sad." ); - $this->assertArrayNotHasKey( 'uselang', $returned, "'uselang' should have been removed from the data" ); - } - - /** - * TODO: Make sure ALL these functions in DonationData are tested, either directly or through a calling function. - * I know that's more regression-ish, but I stand by it. :p - function setNormalizedOrderIDs(){ - function generateOrderId() { - public function sanitizeInput( &$value, $key, $flags=ENT_COMPAT, $double_encode=false ) { - function setGateway(){ - function doCacheStuff(){ - public function getEditToken( $salt = '' ) { - public static function generateToken( $salt = '' ) { - function matchEditToken( $val, $salt = '' ) { - function unsetEditToken() { - public function checkTokens() { - function wasPosted(){ - function setUtmSource() { - public function getOptOuts() { - public function getCleanTrackingData( $clean_optouts = false ) { - function saveContributionTracking() { - public static function insertContributionTracking( $tracking_data ) { - public function updateContributionTracking( $force = false ) { - - */ -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/DonationInterfaceTestCase.php b/tests/phpunit/DonationInterfaceTestCase.php deleted file mode 100644 index 5f19171..0000000 --- a/tests/phpunit/DonationInterfaceTestCase.php +++ /dev/null @@ -1,696 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; -use SmashPig\Core\Context; - -/** - * @group Fundraising - * @group QueueHandling - * @group ClassMethod - * @group ListenerAdapter - * - * @category UnitTesting - * @package Fundraising_QueueHandling - */ -abstract class DonationInterfaceTestCase extends MediaWikiTestCase { - - /** - * An array of the vars we expect to be set before people hit payments. - * @var array - */ - public static $initial_vars = array ( - 'ffname' => 'testytest', - 'referrer' => 'www.yourmom.com', //please don't go there. - 'currency_code' => 'USD', - ); - - /** - * This will be set by a test method with the adapter object. - * - * @var GatewayAdapter $gatewayAdapter - */ - protected $gatewayAdapter; - - /** - * @var TestingDonationLogger - */ - protected $testLogger; - protected $testAdapterClass = TESTS_ADAPTER_DEFAULT; - - /** - * @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 = '' ) { - - //Just in case you got here without running the configuration... - global $wgDonationInterfaceTestMode; - $wgDonationInterfaceTestMode = true; - - parent::__construct( $name, $data, $dataName ); - } - - protected function setUp() { - // TODO: Use SmashPig dependency injection instead. Also override - // SmashPig core logger. - $this->testLogger = new TestingDonationLogger(); - DonationLoggerFactory::$overrideLogger = $this->testLogger; - parent::setUp(); - } - - protected function tearDown() { - $this->resetAllEnv(); - DonationLoggerFactory::$overrideLogger = null; - parent::tearDown(); - } - - /** - * Set up a fake request with the given data. Returns the fake request. - * @param array $data - * @param array $session - * @return FauxRequest - */ - protected function setUpRequest( $data, $session = null ) { - RequestContext::resetMain(); - $request = new FauxRequest( $data, false, $session ); - RequestContext::getMain()->setRequest( $request ); - return $request; - } - - /** - * Set global language for the duration of the test - * - * @param string $language language code to force - */ - protected function setLanguage( $language ) { - RequestContext::getMain()->setLanguage( $language ); - // BackCompat - $this->setMwGlobals( 'wgLang', RequestContext::getMain()->getLanguage() ); - } - - /** - * buildRequestXmlForGlobalCollect - * - * @todo - * - there are many cases to this that need to be developed. - * - Do not consider this a complete test! - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - */ - public function buildRequestXmlForGlobalCollect( $optionsForTestData, $options ) { - - global $wgDonationInterfaceTest; - - $wgDonationInterfaceTest = true; - - $this->setUpRequest( $options ); - $this->gatewayAdapter = new TestingGlobalCollectAdapter(); - - $this->gatewayAdapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT'); - - $exposed = TestingAccessWrapper::newFromObject( $this->gatewayAdapter ); - $request = trim( $exposed->buildRequestXML() ); - - $this->setUpRequest( $options ); - $expected = $this->getExpectedXmlRequestForGlobalCollect( $optionsForTestData, $options ); - - $this->assertEquals( $expected, $request, 'The constructed XML for payment_method [' . $optionsForTestData['payment_method'] . '] and payment_submethod [' . $optionsForTestData['payment_submethod'] . '] does not match our expected request.' ); - } - - /** - * - * @param string $country The country we want the test user to be from. - * @return array Donor data to use - * @throws OutOfBoundsException when there is no data available for the requested country - */ - public static function getDonorTestData( $country = '' ) { - $donortestdata = array ( - 'US' => array ( //default - 'city' => 'San Francisco', - 'state' => 'CA', - 'postal_code' => '94105', - 'currency_code' => 'USD', - 'street' => '123 Fake Street', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - ), - 'ES' => array ( - 'city' => 'Barcelona', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Calle Fake', - 'fname' => 'Nombre', - 'lname' => 'Apellido', - 'amount' => '1.55', - 'language' => 'es', - ), - 'Catalonia' => array ( - 'city' => 'Barcelona', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Calle Fake', - 'fname' => 'Nombre', - 'lname' => 'Apellido', - 'amount' => '1.55', - 'language' => 'ca', - ), - 'NO' => array ( - 'city' => 'Oslo', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Fake Gate', - 'fname' => 'Fornavn', - 'lname' => 'Etternavn', - 'amount' => '1.55', - 'language' => 'no', - ), - 'FR' => array ( - 'city' => 'Versailles', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Rue Faux', - 'fname' => 'Prénom', - 'lname' => 'Nom', - 'amount' => '1.55', - 'language' => 'fr', - ), - // Fiji is configured as a snowflake to test special treatment for certain store IDs - 'FJ' => array ( - 'city' => 'Suva', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Fake Street', - 'fname' => 'FirstName', - 'lname' => 'LastName', - 'amount' => '1.55', - 'language' => 'en', - ), - 'NL' => array ( - 'city' => 'Amsterdam', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 nep straat', - 'fname' => 'Voornaam', - 'lname' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'BE' => array ( - 'city' => 'Antwerp', - 'state' => 'XX', - 'postal_code' => '0', - 'currency_code' => 'EUR', - 'street' => '123 nep straat', - 'fname' => 'Voornaam', - 'lname' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'IT' => array ( - 'city' => 'Torino', - 'state' => 'TO', - 'postal_code' => '10123', - 'currency_code' => 'EUR', - 'street' => 'Via Falso 123', - 'fname' => 'Nome', - 'lname' => 'Cognome', - 'amount' => '1.55', - 'language' => 'it', - ), - 'CA' => array ( - 'city' => 'Saskatoon', - 'state' => 'SK', - 'postal_code' => 'S7K 0J5', - 'currency_code' => 'CAD', - 'street' => '123 Fake Street', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - ), - 'BR' => array ( - 'currency_code' => 'BRL', - 'fiscal_number' => '00003456789', - 'payment_submethod' => 'test_bank', - 'fname' => 'Nome', - 'lname' => 'Apelido', - 'amount' => '100', - 'language' => 'pt', - 'email' => 'nob...@example.org' - ), - 'MX' => array ( - 'city' => 'Tuxtla Gutiérrez', - 'state' => 'CHP', - 'currency_code' => 'MXN', - 'street' => 'Calle Falso 123', - 'fname' => 'Nombre', - 'lname' => 'Apellido', - 'email' => 'pue...@unido.coop', - 'amount' => '155', - 'language' => 'es', - ), - ); - //default to US - if ( $country === '' ) { - $country = 'US'; - } - - if ( array_key_exists( $country, $donortestdata ) ) { - $donortestdata = array_merge( self::$initial_vars, $donortestdata[$country] ); - $donortestdata['country'] = $country; - return $donortestdata; - } - throw new OutOfBoundsException( __FUNCTION__ . ": No donor data for country '$country'" ); - } - - /** - * Supported languages for Belgium - */ - public function belgiumLanguageProvider() { - return array( - array( 'nl' ), - array( 'de' ), - array( 'fr' ), - ); - } - - /** - * Supported languages for Canada - */ - public function canadaLanguageProvider() { - return array( - array( 'en' ), - array( 'fr' ), - ); - } - - /** - * Transaction codes for GC and GC orphan adapters not to be retried - * on pain of $1000+ fines by MasterCard - */ - public function mcNoRetryCodeProvider() { - return array( - array( '430260' ), - array( '430306' ), - array( '430330' ), - array( '430354' ), - array( '430357' ), - ); - } - - public function benignNoRetryCodeProvider() { - return array( - array( '430285' ), - ); - } - - /** - * Get the expected XML request from GlobalCollect - * - * @param $optionsForTestData - * @param array $options - * @return string The expected XML request - */ - public function getExpectedXmlRequestForGlobalCollect( $optionsForTestData, $options = array() ) { - global $wgDonationInterfaceThankYouPage; - $request = RequestContext::getMain()->getRequest(); - - $orderId = $this->gatewayAdapter->getData_Unstaged_Escaped( 'order_id' ); - $exposed = TestingAccessWrapper::newFromObject( $this->gatewayAdapter ); - $merchantref = $exposed->getData_Staged( 'contribution_tracking_id' ); - //@TODO: WHY IN THE NAME OF ZARQUON are we building XML in a STRING format here?!?!?!!!1one1!?. Great galloping galumphing giraffes. - $expected = '<?xml version="1.0" encoding="UTF-8"?' . ">\n"; - $expected .= '<XML>'; - $expected .= '<REQUEST>'; - $expected .= '<ACTION>INSERT_ORDERWITHPAYMENT</ACTION>'; - $expected .= '<META><MERCHANTID>' . $exposed->account_config[ 'MerchantID' ] . '</MERCHANTID>'; - - if ( isset( $request ) ) { - $expected .= '<IPADDRESS>' . $request->getIP() . '</IPADDRESS>'; - } - - $expected .= '<VERSION>1.0</VERSION>'; - $expected .= '</META>'; - $expected .= '<PARAMS>'; - $expected .= '<ORDER>'; - $expected .= '<ORDERID>' . $orderId . '</ORDERID>'; - $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>'; - $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>'; - $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>'; - $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>'; - $expected .= '<MERCHANTREFERENCE>' . $merchantref . '</MERCHANTREFERENCE>'; - - if ( isset( $request ) ) { - $expected .= '<IPADDRESSCUSTOMER>' . $request->getIP() . '</IPADDRESSCUSTOMER>'; - } - - $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>'; - $expected .= '</ORDER>'; - $expected .= '<PAYMENT>'; - $expected .= '<PAYMENTPRODUCTID>' . $optionsForTestData['payment_product_id'] . '</PAYMENTPRODUCTID>'; - $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>'; - $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>'; - $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>'; - $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>'; - $expected .= '<HOSTEDINDICATOR>1</HOSTEDINDICATOR>'; - $expected .= "<RETURNURL>{$wgDonationInterfaceThankYouPage}/{$options['language']}?country={$options['country']}</RETURNURL>"; - $expected .= '<AUTHENTICATIONINDICATOR>0</AUTHENTICATIONINDICATOR>'; - $expected .= '<FIRSTNAME>' . $options['fname'] . '</FIRSTNAME>'; - $expected .= '<SURNAME>' . $options['lname'] . '</SURNAME>'; - $expected .= '<STREET>' . $options['street'] . '</STREET>'; - $expected .= '<CITY>' . $options['city'] . '</CITY>'; - $expected .= '<STATE>' . $options['state'] . '</STATE>'; - $expected .= '<ZIP>' . $options['postal_code'] . '</ZIP>'; - $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>'; - - // Set the issuer id if it is passed. - if ( isset( $optionsForTestData['descriptor'] ) ) { - $expected .= '<DESCRIPTOR>' . $optionsForTestData['descriptor'] . '</DESCRIPTOR>'; - } - - // Set the issuer id if it is passed. - if ( isset( $optionsForTestData['issuer_id'] ) ) { - $expected .= '<ISSUERID>' . $optionsForTestData['issuer_id'] . '</ISSUERID>'; - } - - - // If we're doing Direct Debit... - //@TODO: go ahead and split this out into a "Get the direct debit I_OWP XML block function" the second this gets even slightly annoying. - if ( $optionsForTestData['payment_method'] === 'dd' ) { - $expected .= '<ACCOUNTNAME>' . $optionsForTestData['account_name'] . '</ACCOUNTNAME>'; - $expected .= '<ACCOUNTNUMBER>' . $optionsForTestData['account_number'] . '</ACCOUNTNUMBER>'; - $expected .= '<BANKCODE>' . $optionsForTestData['bank_code'] . '</BANKCODE>'; - $expected .= '<BRANCHCODE>' . $optionsForTestData['branch_code'] . '</BRANCHCODE>'; - $expected .= '<BANKCHECKDIGIT>' . $optionsForTestData['bank_check_digit'] . '</BANKCHECKDIGIT>'; - $expected .= '<DATECOLLECT>' . gmdate( 'Ymd' ) . '</DATECOLLECT>'; //is this cheating? Probably. - $expected .= '<DIRECTDEBITTEXT>' . $optionsForTestData['direct_debit_text'] . '</DIRECTDEBITTEXT>'; - } - - $expected .= '</PAYMENT>'; - $expected .= '</PARAMS>'; - $expected .= '</REQUEST>'; - $expected .= '</XML>'; - - return $expected; - - } - - /** - * Get a fresh gateway object of the type specified in the variable - * $this->testAdapterClass. - * @param array $external_data If you want to shoehorn in some external - * data, do that here. - * @param array $setup_hacks An array of things that override stuff in - * the constructor of the gateway object that I can't get to without - * refactoring the whole thing. @TODO: Refactor the gateway adapter - * constructor. - * @return GatewayAdapter The new relevant gateway adapter object. - */ - function getFreshGatewayObject( $external_data = null, $setup_hacks = array() ) { - $p1 = null; - if ( !is_null( $external_data ) ) { - $p1 = array ( - 'external_data' => $external_data, - ); - } - - if ( $setup_hacks ) { - if ( !is_null( $p1 ) ) { - $p1 = array_merge( $p1, $setup_hacks ); - } else { - $p1 = $setup_hacks; - } - } - - $class = $this->testAdapterClass; - $gateway = new $class( $p1 ); - - $classReflection = new ReflectionClass( $gateway ); - - // FIXME: Find a more elegant way to hackity hacken hack. - // We want to override any define- functions with hacky values. - foreach ( $setup_hacks as $field => $value ) { - if ( property_exists( $class, $field ) ) { - $propertyReflection = $classReflection->getProperty( $field ); - $propertyReflection->setAccessible( true ); - $propertyReflection->setValue( $gateway, $value ); - } - } - - return $gateway; - } - - function resetAllEnv() { - $_SESSION = array ( ); - $_GET = array ( ); - $_POST = array ( ); - - $_SERVER = array ( ); - $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; - $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; - $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; - $_SERVER['SCRIPT_NAME'] = __FILE__; - - RequestContext::resetMain(); - - // Wipe out the $instance of these classes to make sure they're - // re-created with fresh gateway instances for the next test - $singleton_classes = array( - 'Gateway_Extras_ConversionLog', - 'Gateway_Extras_CustomFilters', - 'Gateway_Extras_CustomFilters_Functions', - 'Gateway_Extras_CustomFilters_IP_Velocity', - 'Gateway_Extras_CustomFilters_MinFraud', - 'Gateway_Extras_CustomFilters_Referrer', - 'Gateway_Extras_CustomFilters_Source', - 'Gateway_Extras_SessionVelocityFilter', - ); - foreach( $singleton_classes as $singleton_class ) { - $unwrapped = TestingAccessWrapper::newFromClass( $singleton_class ); - $unwrapped->instance = null; - } - // Reset SmashPig context - Context::set( null ); - } - - /** - * Instantiates the $special_page_class with supplied $initial_vars, - * yoinks the html output from the output buffer, loads that into a - * DomDocument and performs asserts on the results per the checks - * supplied in $perform_these_checks. - * Optional: Asserts that the gateway has logged nothing at ERROR level. - * - * @param string $special_page_class A testing descendant of GatewayPage - * @param array $initial_vars Array that will be loaded straight into a - * test version of the http request. - * @param array $perform_these_checks Array of checks to perform in the - * following format: - * $perform_these_checks[$element_id][$check_to_perform][$expected_result] - * So far, $check_to_perform can be either 'nodename' or 'innerhtml' - * @param boolean $fail_on_log_errors When true, this will fail the - * current test if there are entries in the gateway's error log. - * @param array $session pre-existing session data. - */ - function verifyFormOutput( $special_page_class, $initial_vars, $perform_these_checks, $fail_on_log_errors = false, $session = null ) { - // Nasty hack to clear output from any previous tests. - $mainContext = RequestContext::getMain(); - $newOutput = new OutputPage( $mainContext ); - $newRequest = new TestingRequest( $initial_vars, false, $session ); - $newTitle = Title::newFromText( 'nonsense is apparently fine' ); - $mainContext->setRequest( $newRequest ); - $mainContext->setOutput( $newOutput ); - $mainContext->setTitle( $newTitle ); - - $globals = array ( - 'wgTitle' => $newTitle, - 'wgOut' => $newOutput, - ); - - $this->setMwGlobals( $globals ); - - $this->setLanguage( $initial_vars['language'] ); - - ob_start(); - $formpage = new $special_page_class(); - $formpage->execute( NULL ); - $formpage->getOutput()->output(); - $form_html = ob_get_contents(); - ob_end_clean(); - - // In the event that something goes crazy, uncomment the next line for much easier local debugging - // file_put_contents( '/tmp/xmlout.txt', $form_html ); - - if ( $fail_on_log_errors ) { - $this->verifyNoLogErrors(); - } - - $dom_thingy = new DomDocument(); - //// DEBUGGING, foo - // if (property_exists($this, 'FOO')) { - // error_log(var_export($formpage->getRequest()->response()->getheader('Location'), true)); - // error_log(var_export($form_html, true)); - // } - - if ( $form_html ) { - // p.s. i'm SERIOUS about the character encoding. - $dom_thingy->loadHTML( '<?xml encoding="UTF-8">' . $form_html ); - $dom_thingy->encoding = 'UTF-8'; - } - - foreach ( $perform_these_checks as $id => $checks ) { - if ( $id == 'headers' ) { - foreach ( $checks as $name => $expected ) { - $actual = $formpage->getRequest()->response()->getheader( $name ); - $this->performCheck( $actual, $expected, "header '$name'"); - break; - } - continue; - } - unset( $perform_these_checks['headers'] ); - - $input_node = $dom_thingy->getElementById( $id ); - $this->assertNotNull( $input_node, "Couldn't find the '$id' element" ); - foreach ( $checks as $name => $expected ) { - switch ( $name ) { - case 'nodename': - $this->performCheck( $input_node->nodeName, $expected, "name of node with id '$id'"); - break; - case 'innerhtml': - $actual_html = self::getInnerHTML( $input_node ); - // Strip comments - $actual_html = preg_replace( '/<!--[^>]*-->/', '', $actual_html ); - $this->performCheck( $actual_html, $expected, "innerHTML of node '$id'"); - break; - case 'innerhtmlmatches': - $this->assertEquals( 1, preg_match( $expected, self::getInnerHTML( $input_node ) ), "Value of the node with id '$id' does not match pattern '$expected'. It has value " . self::getInnerHTML( $input_node ) ); - break; - case 'value': - $this->performCheck( $input_node->getAttribute('value'), $expected, "value of node with id '$id'"); - break; - case 'selected': - $selected = null; - if ( $input_node->nodeName === 'select' ) { - $options = $input_node->getElementsByTagName( 'option' ); - foreach ( $options as $option ) { - if ( $option->hasAttribute( 'selected' ) ) { - $selected = $option->getAttribute( 'value' ); - break; - } - } - $this->performCheck( $selected, $expected, "selected option value of node with id '$id'"); - } else { - $this->fail( "Attempted to test for selected value on non-select node, id '$id'" ); - } - break; - } - } - } - - // Are there untranslated boogers? - if ( preg_match_all( '/<[^<]+(>|>)/', $form_html, $matches ) ) { - $this->fail( 'Untranslated messages present: ' . implode( ', ', $matches[0] ) ); - } - } - - /** - * Performs some sort of assertion on a value. - * - * @param string $value the value to test - * @param string|callable $check - * if $check is callable, it is called with argument $value - * otherwise, $value is asserted to be equal to $check - * @param string $label identifies the value in assertion failures - * @return void - */ - function performCheck( $value, $check, $label = 'Tested value' ) { - if ( is_callable( $check ) ) { - $check( $value ); - return; - } - $this->assertEquals( $check, $value, "Expected $label to be $check, found $value instead."); - } - /** - * Asserts that there are no log entries of LOG_ERR or worse. - */ - function verifyNoLogErrors( ) { - $log = $this->testLogger->messages; - - $this->assertTrue( is_array( $log ), "Missing the test log" ); - - //for our purposes, an "error" is LOG_ERR or less. - $checklogs = array ( - LogLevel::ERROR => "Oops: We've got LOG_ERRors.", - LogLevel::CRITICAL => "Critical errors!", - LogLevel::ALERT => "Log Alerts!", - LogLevel::EMERGENCY => "Logs says the servers are actually on fire.", - ); - - $message = false; - foreach ( $checklogs as $level => $levelmessage ) { - if ( array_key_exists( $level, $log ) ) { - $message = $levelmessage . ' ' . print_r( $log[$level], true ) . "\n"; - } - } - - $this->assertFalse( $message, $message ); //ha - } - - /** - * Finds a relevant line/lines in a gateway's log array - * @param string $log_level One of the constants in \Psr\Log\LogLevel - * @param string $match A regex to match against the log lines. - * @return array All log lines that match $match. - */ - public function getLogMatches( $log_level, $match ) { - $log = $this->testLogger->messages; - if ( !array_key_exists( $log_level, $log ) ) { - return false; - } - $return = array ( ); - foreach ( $log[$log_level] as $line ) { - if ( preg_match( $match, $line ) ) { - $return[] = $line; - } - } - return $return; - } - - static function getInnerHTML( $node ) { - $innerHTML = ''; - $children = $node->childNodes; - foreach ( $children as $child ) { - $innerHTML .= $child->ownerDocument->saveXML( $child ); - } - return $innerHTML; - } -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/DonationQueueTest.php b/tests/phpunit/DonationQueueTest.php deleted file mode 100644 index ca4426e..0000000 --- a/tests/phpunit/DonationQueueTest.php +++ /dev/null @@ -1,159 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * @group DonationInterface - * @group QueueHandling - * - * @category UnitTesting - * @package Fundraising_QueueHandling - */ -class DonationQueueTest extends DonationInterfaceTestCase { - protected $transaction; - protected $queue_name; - protected $expected_message; - - public function setUp() { - parent::setUp(); - - $this->queue_name = 'test-' . mt_rand(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableQueue' => true, - 'wgDonationInterfaceDefaultQueueServer' => array( - 'type' => 'TestingQueue', - ), - 'wgDonationInterfaceQueues' => array( - $this->queue_name => array(), - ), - ) ); - - $this->transaction = array( - 'amount' => '1.24', - 'city' => 'Dunburger', - 'contribution_tracking_id' => mt_rand(), - // FIXME: err, we're cheating normalization here. - 'correlation-id' => 'testgateway-' . mt_rand(), - 'country' => 'US', - 'currency_code' => 'USD', - 'date' => time(), - 'email' => 'nob...@wikimedia.org', - 'fname' => 'Jen', - 'gateway_account' => 'default', - 'gateway' => 'testgateway', - 'gateway_txn_id' => mt_rand(), - 'order_id' => mt_rand(), - 'language' => 'en', - 'lname' => 'Russ', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceMessage', - 'response' => 'Gateway response something', - 'state' => 'AK', - 'street' => '1 Fake St.', - 'user_ip' => '127.0.0.1', - 'utm_source' => 'testing', - 'postal_code' => '12345', - ); - - $this->expected_message = array( - 'contribution_tracking_id' => $this->transaction['contribution_tracking_id'], - 'utm_source' => 'testing', - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - 'first_name' => 'Jen', - 'last_name' => 'Russ', - 'street_address' => '1 Fake St.', - 'city' => 'Dunburger', - 'state_province' => 'AK', - 'country' => 'US', - 'postal_code' => '12345', - 'gateway' => 'testgateway', - 'gateway_account' => 'default', - 'gateway_txn_id' => $this->transaction['gateway_txn_id'], - 'order_id' => $this->transaction['order_id'], - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'response' => 'Gateway response something', - 'currency' => 'USD', - 'fee' => '0', - 'gross' => '1.24', - 'user_ip' => '127.0.0.1', - 'date' => (int)$this->transaction['date'], - 'source_host' => WmfFramework::getHostname(), - 'source_name' => 'DonationInterface', - 'source_run_id' => getmypid(), - 'source_type' => 'payments', - 'source_version' => DonationQueue::getVersionStamp(), - ); - } - - public function tearDown() { - // Clear static variables. - TestingQueue::clearAll(); - - parent::tearDown(); - } - - public function testPushMessage() { - DonationQueue::instance()->push( $this->transaction, $this->queue_name ); - - $this->assertEquals( $this->expected_message, - DonationQueue::instance()->pop( $this->queue_name ) ); - } - - /** - * After pushing 2, pop should return the first. - */ - public function testIsFifoQueue() { - DonationQueue::instance()->push( $this->transaction, $this->queue_name ); - - $transaction2 = $this->transaction; - $transaction2['correlation-id'] = mt_rand(); - - $this->assertEquals( $this->expected_message, - DonationQueue::instance()->pop( $this->queue_name ) ); - } - - public function testSetMessage() { - DonationQueue::instance()->set( $this->transaction['correlation-id'], - $this->transaction, $this->queue_name ); - - $this->assertEquals( $this->expected_message, - DonationQueue::instance()->get( - $this->transaction['correlation-id'], $this->queue_name ) ); - } - - public function testDeleteMessage() { - DonationQueue::instance()->set( $this->transaction['correlation-id'], - $this->transaction, $this->queue_name ); - $this->assertEquals( $this->expected_message, - DonationQueue::instance()->get( - $this->transaction['correlation-id'], $this->queue_name ) ); - - DonationQueue::instance()->delete( - $this->transaction['correlation-id'], $this->queue_name ); - - $this->assertNull( - DonationQueue::instance()->get( - $this->transaction['correlation-id'], $this->queue_name ) ); - } -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/GatewayPageTest.php b/tests/phpunit/GatewayPageTest.php deleted file mode 100644 index 68a80f0..0000000 --- a/tests/phpunit/GatewayPageTest.php +++ /dev/null @@ -1,212 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * @group Fundraising - * @group DonationInterface - * @group GatewayPage - */ -class GatewayPageTest extends DonationInterfaceTestCase { - - /** - * @var GatewayPage - */ - protected $page; - /** - * @var GatewayAdapter - */ - protected $adapter; - - public function setUp() { - $this->page = new TestingGatewayPage(); - // put these here so tests can override them - TestingGenericAdapter::$fakeGlobals = array ( 'FallbackCurrency' => 'USD' ); - TestingGenericAdapter::$acceptedCurrencies[] = 'USD'; - TestingGenericAdapter::$fakeIdentifier = 'globalcollect'; - $this->setMwGlobals( array( - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'paypal' => array( - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - ), - ), - ) ); - parent::setUp(); - } - - protected function setUpAdapter( $extra = array() ) { - $externalData = array_merge( - array( - 'amount' => '200', - 'currency_code' => 'BBD', - 'contribution_tracking_id' => mt_rand( 10000, 10000000 ), - ), - $extra - ); - $this->adapter = new TestingGenericAdapter( array( - 'external_data' => $externalData, - ) ); - $this->page->adapter = $this->adapter; - } - - public function tearDown() { - TestingGenericAdapter::$acceptedCurrencies = array(); - TestingGenericAdapter::$fakeGlobals = array(); - TestingGenericAdapter::$fakeIdentifier = false; - parent::tearDown(); - } - - public function testFallbackWithNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - $this->setUpAdapter(); - - $this->page->validateForm(); - - $this->assertTrue( $this->adapter->validatedOK() ); - - $manualErrors = $this->adapter->getManualErrors(); - $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'USD' )->text(); - $this->assertEquals( $msg, $manualErrors['general'] ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testFallbackIntermediateConversion() { - TestingGenericAdapter::$fakeGlobals['FallbackCurrency'] = 'OMR'; - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - TestingGenericAdapter::$acceptedCurrencies[] = 'OMR'; - $this->setUpAdapter(); - - $this->page->validateForm(); - - $manualErrors = $this->adapter->getManualErrors(); - $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'OMR' )->text(); - $this->assertEquals( $msg, $manualErrors['general'] ); - $this->assertEquals( 38, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'OMR', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testFallbackWithoutNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter(); - - $this->page->validateForm(); - - $this->assertTrue( $this->adapter->validatedOK() ); - - $manualErrors = $this->adapter->getManualErrors(); - $this->assertEquals( null, $manualErrors['general'] ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testFallbackAlwaysNotifiesIfOtherErrors() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter( array( 'email' => 'notanemail' ) ); - - $this->page->validateForm(); - - $manualErrors = $this->adapter->getManualErrors(); - $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'USD' )->text(); - $this->assertEquals( $msg, $manualErrors['general'] ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testNoFallbackForSupportedCurrency() { - TestingGenericAdapter::$acceptedCurrencies[] = 'BBD'; - $this->setUpAdapter(); - - $this->page->validateForm(); - - $manualErrors = $this->adapter->getManualErrors(); - $this->assertEquals( null, $manualErrors['general'] ); - $this->assertEquals( 200, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'BBD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - public function testFallbackByCountry() { - // With 'FallbackCurrencyByCountry', we need to return a single supported currency - TestingGenericAdapter::$acceptedCurrencies = array( 'USD' ); - TestingGenericAdapter::$fakeGlobals = array( - 'FallbackCurrency' => false, - 'FallbackCurrencyByCountry' => true, - ); - $this->setUpAdapter(); - $this->adapter->addRequestData( array( - 'country' => 'US', - ) ); - - $this->page->validateForm(); - - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); - } - - /** - * Before redirecting a user to the processor, we should log all of their - * details at info level - */ - function testLogDetailsOnRedirect() { - $init = $this->getDonorTestData(); - $session = array( 'Donor' => $init ); - - $this->verifyFormOutput( 'PaypalLegacyGateway', $init, array(), false, $session ); - - $logged = $this->getLogMatches( LogLevel::INFO, '/^Redirecting for transaction: /' ); - $this->assertEquals( 1, count( $logged ), 'Should have logged details once' ); - preg_match( '/Redirecting for transaction: (.*)$/', $logged[0], $matches ); - $detailString = $matches[1]; - $expected = array( - 'currency_code' => 'USD', - 'payment_submethod' => '', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - 'country' => 'US', - 'payment_method' => 'paypal', - 'user_ip' => '127.0.0.1', - 'recurring' => '', - 'utm_source' => '..paypal', - 'gateway' => 'paypal', - 'gateway_account' => 'testing', - 'gateway_txn_id' => false, - 'response' => false, - 'street' => '123 Fake Street', - 'city' => 'San Francisco', - 'state' => 'CA', - 'postal_code' => '94105', - 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceMessage', - ); - $actual = json_decode( $detailString, true ); - // TODO: when tests use PHPUnit 4.4 - // $this->assertArraySubset( $expected, $actual, false, 'Logged the wrong stuff' ); - $expected['order_id'] = $actual['contribution_tracking_id']; - unset( $actual['contribution_tracking_id'] ); - unset( $actual['correlation-id'] ); - unset( $actual['date'] ); - $this->assertEquals( $expected, $actual, 'Logged the wrong stuff!' ); - } -} ->>>>>>> BRANCH (aa270d Rename 'zip' to 'postal_code') diff --git a/tests/phpunit/LoggingTest.php b/tests/phpunit/LoggingTest.php deleted file mode 100644 index dbb3e57..0000000 --- a/tests/phpunit/LoggingTest.php +++ /dev/null @@ -1,163 +0,0 @@ -<<<<<<< HEAD (5edaa1 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * - * @group Fundraising - * @group DonationInterface - */ -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'] = 'innoc...@manichean.com'; - $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' => 'innoc...@manichean.com', - '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', - 'postal_code' => '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'] = 'innoc...@manichean.com'; - $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' => 'innoc...@manichean.com', - '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', - 'postal_code' => '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 (aa270d Rename 'zip' to 'postal_code') -- To view, visit https://gerrit.wikimedia.org/r/330733 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I072225b0602fae6c6fbf1e63d24a31b70780949e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits