Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373100 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment And update vendor 53b0ef87a Localisation updates from https://translatewiki.net. 0ba0c4e67 build: bump grunt-contrib-watch 2b6c9234f build: bump grunt and drop grunt-cli 8686ee8cd Update SmashPig library 43c1ed2bd Add Ingenico Connect gateway based on GlobalCollect 2e1cb0be8 Localisation updates from https://translatewiki.net. ee4526451 Localisation updates from https://translatewiki.net. 1e686b597 Remove obsolete selenium tests and WP responses. a257fa996 Localisation updates from https://translatewiki.net. ecfb91f09 Localisation updates from https://translatewiki.net. de827ca5d Localisation updates from https://translatewiki.net. 9977fc1cf Localisation updates from https://translatewiki.net. 686f4bdef Use json extension for .stylelintrc 13a5d2be0 Localisation updates from https://translatewiki.net. 8268f93fb PayPal dead sessions: show thank you page e38c59e46 Update SmashPig library Change-Id: Icb4fc61132a57692f2ede55983c5d3daeab0d183 --- D tests/phpunit/Adapter/Ingenico/IngenicoApiTest.php D tests/phpunit/Adapter/Ingenico/IngenicoFormLoadTest.php D tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php D tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php D tests/phpunit/Adapter/Ingenico/IngenicoTest.php D tests/phpunit/Adapter/Ingenico/RealTimeBankTransferIdealTest.php D tests/phpunit/Adapter/Ingenico/RecurringTest.php D tests/phpunit/Adapter/Ingenico/ResultSwitcherTest.php D tests/phpunit/BaseIngenicoTestCase.php D tests/phpunit/DonationInterfaceTestCase.php D tests/phpunit/TestConfiguration.php M vendor 12 files changed, 1 insertion(+), 2,895 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/00/373100/1 diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoApiTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoApiTest.php deleted file mode 100644 index 8a89e1e..0000000 --- a/tests/phpunit/Adapter/Ingenico/IngenicoApiTest.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -use SmashPig\Core\DataStores\QueueWrapper; -use SmashPig\CrmLink\Messages\SourceFields; -use SmashPig\Tests\TestingContext; -use SmashPig\Tests\TestingProviderConfiguration; - -/** - * @group Fundraising - * @group DonationInterface - * @group Ingenico - * @group IngenicoApi - * @group DonationInterfaceApi - * @group medium - */ - -class IngenicoApiTest extends DonationInterfaceApiTestCase { - - protected $hostedCheckoutProvider; - - protected $partialUrl; - - public function setUp() { - parent::setUp(); - $ctx = TestingContext::get(); - $globalConfig = $ctx->getGlobalConfiguration(); - - $providerConfig = TestingProviderConfiguration::createForProvider( - 'ingenico', $globalConfig - ); - $ctx->providerConfigurationOverride = $providerConfig; - - $this->hostedCheckoutProvider = $this->getMockBuilder( - 'SmashPig\PaymentProviders\Ingenico\HostedCheckoutProvider' - )->disableOriginalConstructor()->getMock(); - - $providerConfig->overrideObjectInstance( 'payment-provider/cc', $this->hostedCheckoutProvider ); - $this->partialUrl = 'poweredbyglobalcollect.com/pay8915-53ebca407e6b4a1dbd086aad4f10354d:' . - '8915-28e5b79c889641c8ba770f1ba576c1fe:9798f4c44ac6406e8288494332d1daa0'; - } - - public function testGoodSubmit() { - $init = DonationInterfaceTestCase::getDonorTestData(); - $init['email'] = '[email protected]'; - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['gateway'] = 'ingenico'; - $init['action'] = 'donate'; - - $this->hostedCheckoutProvider->expects( $this->once() ) - ->method( 'createHostedPayment' )->with( - $this->callback( function( $actual ) { - $hcsi = array( - 'locale' => 'en_US', - 'paymentProductFilters' => array( - 'restrictTo' => array( - 'products' => array( - 1 - ) - ) - ), - 'showResultPage' => 'false' - ); - $this->assertArraySubset( $hcsi, $actual['hostedCheckoutSpecificInput'] ); - $this->assertRegExp( - '/Special:IngenicoGatewayResult/', - $actual['hostedCheckoutSpecificInput']['returnUrl'] - ); - $order = array( - 'amountOfMoney' => array( - 'currencyCode' => 'USD', - 'amount' => 155 - ), - 'customer' => array( - 'billingAddress' => array( - 'countryCode' => 'US', - 'city' => 'San Francisco', - 'state' => 'CA', - 'zip' => '94105', - 'street' => '123 Fake Street' - ), - 'contactDetails' => array( - 'emailAddress' => '[email protected]' - ), - 'locale' => 'en_US', - 'personalInformation' => array( - 'name' => array( - 'firstName' => 'Firstname', - 'surname' => 'Surname' - ) - ) - ) - ); - $this->assertArraySubset( $order, $actual['order'] ); - $this->assertTrue( is_numeric( $actual['order']['references']['merchantReference'] ) ); - return true; - } ) - ) - ->willReturn( - array( - 'partialRedirectUrl' => $this->partialUrl, - 'hostedCheckoutId' => '8915-28e5b79c889641c8ba770f1ba576c1fe', - 'RETURNMAC' => 'f5b66cf9-c64c-4c8d-8171-b47205c89a56' - ) - ); - - $this->hostedCheckoutProvider->expects( $this->once() ) - ->method( 'getHostedPaymentUrl' )->with( - $this->equalTo( $this->partialUrl ) - )->willReturn( 'https://wmf-pay.' . $this->partialUrl ); - - $apiResult = $this->doApiRequest( $init ); - $result = $apiResult[0]['result']; - - $this->assertEquals( - 'https://wmf-pay.' . $this->partialUrl, - $result['formaction'], - 'Ingenico API not setting formaction' - ); - $this->assertTrue( $result['status'], 'Ingenico API result status should be true' ); - - $message = QueueWrapper::getQueue( 'pending' )->pop(); - $this->assertNotNull( $message, 'Not sending a message to the pending queue' ); - SourceFields::removeFromMessage( $message ); - $expected = array( - 'fee' => 0, - 'utm_source' => '..cc', - 'language' => 'en', - 'email' => '[email protected]', - 'first_name' => 'Firstname', - 'last_name' => 'Surname', - 'country' => 'US', - 'gateway' => 'ingenico', - 'recurring' => '', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'currency' => 'USD', - 'gross' => 1.55, - 'user_ip' => '127.0.0.1', - 'street_address' => '123 Fake Street', - 'city' => 'San Francisco', - 'state_province' => 'CA', - 'postal_code' => '94105', - 'gateway_session_id' => '8915-28e5b79c889641c8ba770f1ba576c1fe' - ); - $this->assertArraySubset( $expected, $message ); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoFormLoadTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoFormLoadTest.php deleted file mode 100644 index b73e122..0000000 --- a/tests/phpunit/Adapter/Ingenico/IngenicoFormLoadTest.php +++ /dev/null @@ -1,218 +0,0 @@ -<?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 Ingenico - */ -class IngenicoFormLoadTest extends BaseIngenicoTestCase { - - public function testIngenicoFormLoad() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmad'; - $init['gateway'] = 'ingenico'; - - $assertNodes = array ( - 'submethod-mc' => array ( - 'nodename' => 'input' - ), - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'USD', $init['language'] . '_' . $init['country'] ) - ). - '\s*$/', - ), - 'state_province' => array ( - 'nodename' => 'select', - 'selected' => 'CA', - ), - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } - - function testIngenicoFormLoad_FR() { - $init = $this->getDonorTestData( 'FR' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - $init['gateway'] = 'ingenico'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'value' => 'Prénom', - ), - 'last_name' => array ( - 'nodename' => 'input', - 'value' => 'Nom', - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'FR', - ), - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } - - /** - * Ensure that form loads for Italy - */ - public function testIngenicoFormLoad_IT() { - $init = $this->getDonorTestData( 'IT' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['ffname'] = 'cc-vmaj'; - $init['gateway'] = 'ingenico'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( 'it' )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( 'it' )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( 'it' )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'IT', - ), - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Belgian form loads in all of that country's supported languages - * @dataProvider belgiumLanguageProvider - */ - public function testIngenicoFormLoad_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; - $init['gateway'] = 'ingenico'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - Amount::format( 1.55, 'EUR', $init['language'] . '_' . $init['country'] ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( $language )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'BE', - ), - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } - - /** - * Make sure Canadian CC form loads in English and French - * @dataProvider canadaLanguageProvider - */ - public function testIngenicoFormLoad_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; - $init['gateway'] = 'ingenico'; - - $assertNodes = array ( - 'selected-amount' => array ( - 'nodename' => 'span', - 'innerhtmlmatches' => '/^\s*' . - str_replace( '$', '\$', - Amount::format( 1.55, 'CAD', $init['language'] . '_' . $init['country'] ) - ) . - '\s*$/', - ), - 'first_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-first_name')->inLanguage( $language )->text(), - ), - 'last_name' => array ( - 'nodename' => 'input', - 'placeholder' => wfMessage( 'donate_interface-donor-last_name')->inLanguage( $language )->text(), - ), - 'informationsharing' => array ( - 'nodename' => 'p', - 'innerhtml' => wfMessage( 'donate_interface-informationsharing', '.*' )->inLanguage( $language )->text(), - ), - 'state_province' => array ( - 'nodename' => 'select', - 'selected' => 'SK', - ), - 'postal_code' => array ( - 'nodename' => 'input', - 'value' => $init['postal_code'], - ), - 'country' => array ( - 'nodename' => 'input', - 'value' => 'CA', - ), - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php deleted file mode 100644 index 10042f7..0000000 --- a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php +++ /dev/null @@ -1,212 +0,0 @@ -<?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\DataStores\QueueWrapper; -use SmashPig\CrmLink\Messages\SourceFields; -use SmashPig\Tests\TestingContext; -use SmashPig\Tests\TestingProviderConfiguration; -use Wikimedia\TestingAccessWrapper; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Ingenico - * @group OrphanSlayer - */ -class DonationInterface_Adapter_Ingenico_Orphans_IngenicoTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - $this->markTestSkipped( 'Orphan adapter not yet implemented' ); - - TestingContext::get()->providerConfigurationOverride = - TestingProviderConfiguration::createForProvider( - 'ingenico', - $this->smashPigGlobalConfig - ); - - $this->setMwGlobals( array( - 'wgIngenicoGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'ingenico', - '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->dummy_utm_data = array ( - 'utm_source' => 'dummy_source', - 'utm_campaign' => 'dummy_campaign', - 'utm_medium' => 'dummy_medium', - 'date' => time(), - ); - } - - public function testConstructor() { - - $class = $this->testAdapterClass; - - $gateway = $this->getFreshGatewayObject(); - - $this->assertInstanceOf( $class, $gateway ); - - $this->verifyNoLogErrors(); - } - - - public function testBatchOrderID_generate() { - - //no data on construct, generate Order IDs - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Order_id generation may be broken.' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is not left as null, when generating our own' ); - - $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $data['order_id'] = '55555'; - - //now, add data and check that we didn't kill the oid. Still generating. - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '55555', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '444444'; - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '444444', 'loadDataAndReInit failed to stick OrderID' ); - - $this->verifyNoLogErrors(); - } - - public function testBatchOrderID_no_generate() { - - //no data on construct, do not generate Order IDs - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertFalse( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Deferred order_id generation may be broken.' ); - $this->assertEmpty( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); - - $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $data['order_id'] = '66666'; - - //now, add data and check that we didn't kill the oid. Still not generating - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '66666', 'loadDataAndReInit failed to stick OrderID' ); - - $data['order_id'] = '777777'; - $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '777777', 'loadDataAndReInit failed to stick OrderID on second batch item' ); - - $this->verifyNoLogErrors(); - } - - /** - * Tests to make sure that certain error codes returned from GC will - * trigger order cancellation, even if retryable errors also exist. - * @dataProvider mcNoRetryCodeProvider - */ - public function testNoMastercardFinesForRepeatOnBadCodes( $code ) { - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - - //Toxic card should not retry, even if there's an order id collision - $init = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = '[email protected]'; - $init['contribution_tracking_id'] = mt_rand(); - $gateway->loadDataAndReInit( $init ); - - $gateway->setDummyGatewayResponseCode( $code ); - $result = $gateway->do_transaction( 'Confirm_CreditCard' ); - $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! MasterCard could fine us a thousand bucks for that!" ); - $this->assertEquals( false, $result->getCommunicationStatus(), "Error code $code should mean status of do_transaction is false" ); - $errors = $result->getErrors(); - $this->assertFalse( empty( $errors ), 'Orphan adapter needs to see the errors to consider it rectified' ); - $finder = function( $error ) { - return $error->getErrorCode() == '1000001'; - }; - $this->assertNotEmpty( array_filter( $errors, $finder ), 'Orphan adapter needs error 1000001 to consider it rectified' ); - $loglines = $this->getLogMatches( LogLevel::INFO, "/Got error code $code, not retrying to avoid MasterCard fines./" ); - $this->assertNotEmpty( $loglines, "GC Error $code is not generating the expected payments log error" ); - } - - /** - * Make sure we're incorporating GET_ORDERSTATUS AVS and CVV responses into - * fraud scores. - */ - function testGetOrderstatusPostProcessFraud() { - $this->markTestSkipped( 'OrderStatus not yet implemented' ); - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableCustomFilters' => true, - 'wgIngenicoGatewayCustomFiltersFunctions' => array( - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - ) ); - $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - - $init = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = '[email protected]'; - $init['contribution_tracking_id'] = mt_rand(); - $init['payment_method'] = 'cc'; - - $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'review', $action, - 'Orphan gateway should fraud fail on bad CVV and AVS' ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $this->assertEquals( 40, $exposed->risk_score, - 'Risk score was incremented correctly.' ); - $message = QueueWrapper::getQueue( 'payments-antifraud' )->pop(); - SourceFields::removeFromMessage( $message ); - $expected = array( - 'validation_action' => 'review', - 'risk_score' => 40, - 'score_breakdown' => array( - // FIXME: need to enable utm / email / country checks ??? - 'initial' => 0, - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - 'user_ip' => null, // FIXME - 'gateway_txn_id' => '55555', - 'date' => $message['date'], - 'server' => gethostname(), - 'gateway' => 'ingenico', - 'contribution_tracking_id' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - 'order_id' => $gateway->getData_Unstaged_Escaped( 'order_id' ), - 'payment_method' => 'cc', - ); - $this->assertEquals( $expected, $message ); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php deleted file mode 100644 index 4926c49..0000000 --- a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php +++ /dev/null @@ -1,215 +0,0 @@ -<?php - -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -use SmashPig\Core\DataStores\PendingDatabase; - -/** - * @covers IngenicoOrphanRectifier - * - * @group Fundraising - * @group DonationInterface - * @group Ingenico - * @group OrphanSlayer - */ -class DonationInterface_Adapter_Ingenico_Orphan_Rectifier_Test - extends DonationInterfaceTestCase -{ - // TODO: Give vulgar names. - // FIXME: Is 25 the normal unauthorized status? Use the common one, whatever that is. - const STATUS_PENDING = 25; - const STATUS_PENDING_POKE = 600; - const STATUS_COMPLETE = 800; - - // Arbitrary configuration for testing time logic. - const TIME_BUFFER = 60; - const TARGET_EXECUTE_TIME = 1200; - - public $pendingDb; - - public function setUp() { - parent::setUp(); - $this->markTestSkipped( 'Orphan rectifier not yet implemented' ); - - $this->setMwGlobals( array( - 'wgDonationInterfaceOrphanCron' => array( - 'enable' => true, - 'target_execute_time' => self::TARGET_EXECUTE_TIME, - 'time_buffer' => self::TIME_BUFFER, - ), - 'wgIngenicoGatewayEnabled' => true, - 'wgDonationInterfaceGatewayAdapters' => array( - // We include the regular adapter in order to pass gateway validation D: - 'ingenico' => 'IngenicoOrphanAdapter', - 'ingenico_orphan' => 'IngenicoOrphanAdapter', - ), - ) ); - - - $this->pendingDb = PendingDatabase::get(); - - // Create the schema. - $this->pendingDb->createTable(); - } - - /** - * When leaving a message unprocessed and pending, don't try to process it - * again. - */ - public function testProcessOrphansStatusPending() { - $orphan_pending = $this->createOrphan(); - - $rectifier = new IngenicoOrphanRectifier(); - $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING ); - $rectifier->processOrphans(); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - 'ingenico', $orphan_pending['order_id'] ); - $this->assertNull( $fetched, - 'Message was popped.' ); - - $this->assertGatewayCallsExactly( array( - 'GET_ORDERSTATUS' - ) ); - } - - /** - * If a message is waiting for the API kiss of death, perform it. - */ - public function testProcessOrphansStatusPendingPoke() { - $orphan_pending_poke = $this->createOrphan(); - - $rectifier = new IngenicoOrphanRectifier(); - $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING_POKE ); - $rectifier->processOrphans(); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - 'ingenico', $orphan_pending_poke['order_id'] ); - $this->assertNull( $fetched, - 'Message was popped' ); - - $this->assertGatewayCallsExactly( array( - 'GET_ORDERSTATUS', - 'SET_PAYMENT', - ) ); - - // TODO: test that we sent a completion message - } - - /** - * Report a completed transaction. - */ - public function testProcessOrphansStatusComplete() { - - $orphan_complete = $this->createOrphan(); - - $rectifier = new IngenicoOrphanRectifier(); - $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_COMPLETE ); - $rectifier->processOrphans(); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - 'ingenico', $orphan_complete['order_id'] ); - $this->assertNull( $fetched, - 'Message was popped' ); - - $this->assertGatewayCallsExactly( array( - 'GET_ORDERSTATUS', - ) ); - - // TODO: test that we sent a completion message - } - - /** - * Don't process recent messages. - */ - public function testTooRecentMessage() { - $orphan_complete = $this->createOrphan( array( - 'date' => time() - self::TIME_BUFFER + 30, - ) ); - - $rectifier = new IngenicoOrphanRectifier(); - $this->gateway = $rectifier->getAdapter(); - $rectifier->processOrphans(); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - 'ingenico', $orphan_complete['order_id'] ); - $this->assertNotNull( $fetched, - 'Message was not popped' ); - - $this->assertGatewayCallsExactly( array() ); - - // TODO: Test that we: - // * Logged the "done with old messages" line. - } - - /** - * Create an orphaned tranaction and store it to the pending database. - * - * TODO: Reuse SmashPigBaseTest#createMessage - */ - public function createOrphan( $overrides = array() ) { - $uniq = mt_rand(); - $message = $overrides + array( - 'contribution_tracking_id' => $uniq, - 'first_name' => 'Flighty', - 'last_name' => 'Dono', - 'email' => '[email protected]', - 'gateway' => 'ingenico', - 'gateway_txn_id' => "txn-{$uniq}", - 'order_id' => "order-{$uniq}", - 'gateway_account' => 'default', - 'payment_method' => 'cc', - 'payment_submethod' => 'mc', - // Defaults to a magic 25 minutes ago, within the process window. - 'date' => time() - 25 * 60, - 'amount' => 123, - 'currency' => 'EUR', - ); - $this->pendingDb->storeMessage( $message ); - return $message; - } - - /** - * Assert whether we made exactly the expected gateway calls - * - * @param array $expected List of API action names, in the form they appear - * in the <ACTION> tag. - */ - protected function assertGatewayCallsExactly( $expected ) { - $expected_num_calls = count( $expected ); - $this->assertEquals( $expected_num_calls, count( $this->gateway->curled ), - "Ran exactly {$expected_num_calls} API calls" ); - foreach ( $expected as $index => $action ) { - $this->assertRegExp( '/\b' . $action . '\b/', $this->gateway->curled[$index], - "Call #" . ( $index + 1 ) . " was {$action}." ); - } - } - - /** - * Dump the entire database state, for debugging. - */ - protected function debugDbContents() { - $result = $this->pendingDb->getDatabase()->query( - "select * from pending" ); - $rows = $result->fetchAll( PDO::FETCH_ASSOC ); - var_export($rows); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoTest.php deleted file mode 100644 index 38fbf27..0000000 --- a/tests/phpunit/Adapter/Ingenico/IngenicoTest.php +++ /dev/null @@ -1,477 +0,0 @@ -<?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 Wikimedia\TestingAccessWrapper; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Ingenico - */ -class DonationInterface_Adapter_Ingenico_IngenicoTest extends BaseIngenicoTestCase { - - protected $partialUrl; - - protected $hostedCheckoutCreateResponse; - - public function setUp() { - parent::setUp(); - - $this->partialUrl = 'poweredbyglobalcollect.com/pay8915-53ebca407e6b4a1dbd086aad4f10354d:' . - '8915-28e5b79c889641c8ba770f1ba576c1fe:9798f4c44ac6406e8288494332d1daa0'; - - $this->hostedCheckoutCreateResponse = array( - 'partialRedirectUrl' => $this->partialUrl, - 'hostedCheckoutId' => '8915-28e5b79c889641c8ba770f1ba576c1fe', - 'RETURNMAC' => 'f5b66cf9-c64c-4c8d-8171-b47205c89a56' - ); - } - - /** - * 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 createHostedCheckout. - */ - function testGatewaySessionRetrieval() { - $init = $this->getDonorTestData(); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $this->hostedCheckoutProvider->expects( $this->once() ) - ->method( 'createHostedPayment' ) - ->willReturn( - $this->hostedCheckoutCreateResponse - ); - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->do_transaction( 'createHostedCheckout' ); - - $this->assertNotNull( - $gateway->getData_Unstaged_Escaped( 'gateway_session_id' ), - 'No gateway_session_id was retrieved from createHostedCheckout' - ); - } - - /** - * Just run the GET_ORDERSTATUS transaction and make sure we load the data - */ - function testGetOrderStatus() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - - $data = $gateway->getTransactionData(); - - $this->assertEquals( 'N', $data['CVVRESULT'], 'CVV Result not loaded from XML response' ); - } - - /** - * Don't fraud-fail someone for bad CVV if GET_ORDERSTATUS - * comes back with STATUSID 25 and no CVVRESULT - * @group CvvResult - */ - function testConfirmCreditCardStatus25() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '25' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'process', $action, 'Gateway should not fraud fail on STATUSID 25' ); - } - - /** - * Make sure we're incorporating GET_ORDERSTATUS AVS and CVV responses into - * fraud scores. - */ - function testGetOrderstatusPostProcessFraud() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableCustomFilters' => true, - 'wgIngenicoGatewayCustomFiltersFunctions' => array( - 'getCVVResult' => 10, - 'getAVSResult' => 30, - ), - ) ); - - $init = $this->getDonorTestData(); - $init['ffname'] = 'cc-vmad'; - $init['order_id'] = '55555'; - $init['email'] = '[email protected]'; - $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 testConfirmCreditCardPrefersApiCvv() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - - $this->assertEquals( 'N', $gateway->getData_Unstaged_Escaped('cvv_result'), 'CVV Result not taken from XML response' ); - } - - /** - * 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() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - // The values in session are not the values we originally used - // for createHostedCheckout - $init['amount'] = '12.50'; - $init['currency'] = 'USD'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $currency = $gateway->getData_Unstaged_Escaped( 'currency' ); - $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' ); - $this->assertEquals( '23.45', $amount, 'Not recording correct amount' ); - $this->assertEquals( 'EUR', $currency, 'Not recording correct currency' ); - } - - 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', "'NO' donor's language was improperly set. Should be 'no_NO'" ); - } - - public function testLanguageFallbackStaging() { - $this->markTestSkipped( 'Do we have to fall back with Connect?' ); - $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( 'contribution_tracking_id' ) ); - - // Language was not overwritten. - $this->assertEquals( 'ca', $exposed->dataObj->getVal( 'language' ) ); - } - - /** - * Tests to make sure that certain error codes returned from GC will or - * will not create payments error loglines. - */ - function testCCLogsOnGatewayError() { - $this->markTestSkipped( 'order status not implemented' ); - $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 ) { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $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'=>'USD', - 'email'=>'[email protected]', - 'first_name'=>'Fakety', - 'format'=>'json', - 'gateway'=>'ingenico', - 'language'=>'en', - 'last_name'=>'Fake', - 'payment_method'=>'cc', - 'referrer'=>'http://en.wikipedia.org/wiki/Main_Page', - 'state_province'=>'MA', - 'street_address'=>'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 IngenicoAdapter(); - $calls = []; - $this->hostedCheckoutProvider->expects( $this->exactly( 2 ) ) - ->method( 'createHostedPayment' ) - ->with( $this->callback( function( $arg ) use ( &$calls ) { - $calls[] = $arg; - if ( count( $calls ) === 2 ) { - $this->assertFalse( $calls[0] === $calls[1], 'Two calls to the api did the same thing' ); - } - return true; - } ) ) - ->will( $this->onConsecutiveCalls( - $this->throwException( new Exception( 'test' ) ), - $this->returnValue( $this->hostedCheckoutCreateResponse ) - ) ); - try { - $gateway->do_transaction( 'createHostedCheckout' ); - } - catch ( Exception $e ) { - // totally expected this - } - - //simulate another request coming in before we get anything back from GC - $anotherGateway = new IngenicoAdapter(); - $anotherGateway->do_transaction( 'createHostedCheckout' ); - - } - - /** - * 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 ) { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $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 recover from Ingenico-side timeouts. - */ - function testTimeoutRecover() { - $this->markTestSkipped( 'SetPayment not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['ffname'] = 'cc-vmad'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'SET_PAYMENT' ); - $loglines = $this->getLogMatches( LogLevel::INFO, '/Repeating transaction for timeout/' ); - $this->assertNotEmpty( $loglines, "Log does not say we retried for timeout." ); - } - - public function testDonorReturnSuccess() { - $this->markTestSkipped( 'SetPayment not implemented' ); - $init = $this->getDonorTestData( 'FR' ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['order_id'] = mt_rand(); - $session['Donor'] = $init; - $this->setUpRequest( $init, $session ); - $gateway = $this->getFreshGatewayObject( array() ); - $result = $gateway->processDonorReturn( array( - 'REF' => $init['order_id'], - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ) ); - $this->assertFalse( $result->isFailed() ); - $this->assertEmpty( $result->getErrors() ); - // TODO inspect the queue message - } - - public function testDonorReturnFailure() { - $this->markTestSkipped( 'OrderStatus not implemented' ); - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - $init['order_id'] = mt_rand(); - $session['Donor'] = $init; - $this->setUpRequest( $init, $session ); - $gateway = $this->getFreshGatewayObject( array() ); - $gateway->setDummyGatewayResponseCode( '430285' ); // invalid card - $result = $gateway->processDonorReturn( array( - 'REF' => $init['order_id'], - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ) ); - $this->assertTrue( $result->isFailed() ); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/RealTimeBankTransferIdealTest.php b/tests/phpunit/Adapter/Ingenico/RealTimeBankTransferIdealTest.php deleted file mode 100644 index 8caf7ac..0000000 --- a/tests/phpunit/Adapter/Ingenico/RealTimeBankTransferIdealTest.php +++ /dev/null @@ -1,378 +0,0 @@ -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use SmashPig\Tests\TestingContext; -use SmashPig\Tests\TestingProviderConfiguration; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Ingenico - * @group RealTimeBankTransfer - */ -class DonationInterface_Adapter_Ingenico_RealTimeBankTransferIdealTest extends BaseIngenicoTestCase { - /** - * @var PHPUnit_Framework_MockObject_MockObject - */ - protected $bankPaymentProvider; - - public function setUp() { - parent::setUp(); - $this->markTestSkipped( 'RTBT not implemented' ); - $config = TestingProviderConfiguration::createForProvider( - 'ingenico', - $this->smashPigGlobalConfig - ); - TestingContext::get()->providerConfigurationOverride = $config; - - $this->bankPaymentProvider = $this->getMockBuilder( - '\SmashPig\PaymentProviders\Ingenico\BankPaymentProvider' - )->disableOriginalConstructor()->getMock(); - - $config->overrideObjectInstance( 'payment-provider/rtbt', $this->bankPaymentProvider ); - - $this->bankPaymentProvider->method( 'getBankList' ) - ->willReturn( - array( - 'Test1234' => 'Test Bank 1234', - 'Test5678' => 'Test Bank 5678', - ) - ); - - $this->setMwGlobals( - array( - 'wgIngenicoGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'rtbt-ideal' => array( - 'gateway' => 'ingenico', - 'payment_methods' => array( 'rtbt' => 'rtbt_ideal' ), - 'countries' => array( '+' => 'NL' ), - 'currencies' => array( '+' => 'EUR' ), - ), - ), - ) - ); - } - - /** - * Test for ideal form loading - */ - public function testIngenicoFormLoad_rtbt_Ideal() { - $init = $this->getDonorTestData( 'NL' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'rtbt'; - $init['ffname'] = 'rtbt-ideal'; - - $assertNodes = array( - 'amount' => array( - 'nodename' => 'input', - 'value' => '1.55', - ), - 'currency' => array( - 'nodename' => 'select', - 'selected' => 'EUR', - ), - 'country' => array( - 'nodename' => 'input', - 'value' => 'NL', - ), - 'issuer_id' => array( - 'innerhtmlmatches' => '/Test Bank 1234/' - ) - ); - - $this->verifyFormOutput( 'IngenicoGateway', $init, $assertNodes, true ); - } - - /** - * testBuildRequestXmlWithIssuerId21 - * - * Rabobank: 21 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId21() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 21, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId31 - * - * ABN AMRO: 31 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId31() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 31, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId91 - * - * Rabobank: 21 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId91() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 21, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId161 - * - * Van Lanschot Bankiers: 161 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId161() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 161, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId511 - * - * Triodos Bank: 511 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId511() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 511, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId721 - * - * ING: 721 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId721() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 721, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId751 - * - * SNS Bank: 751 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId751() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 751, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId761 - * - * ASN Bank: 761 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId761() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 761, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - /** - * testBuildRequestXmlWithIssuerId771 - * - * RegioBank: 771 - * - * @covers GatewayAdapter::__construct - * @covers GatewayAdapter::setCurrentTransaction - * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped - */ - public function testBuildRequestXmlWithIssuerId771() { - - $optionsForTestData = array( - 'form_name' => 'TwoStepAmount', - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'payment_product_id' => 809, - 'issuer_id' => 771, - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - unset( $options['payment_product_id'] ); - - $this->buildRequestXmlForIngenico( $optionsForTestData, $options ); - } - - public function testFormAction() { - - $optionsForTestData = array( - 'payment_method' => 'rtbt', - 'payment_submethod' => 'rtbt_ideal', - 'issuer_id' => 771, - // Email is required for RTBT. - 'email' => '[email protected]', - ); - - //somewhere else? - $options = $this->getDonorTestData( 'ES' ); - $options = array_merge( $options, $optionsForTestData ); - - $this->gatewayAdapter = $this->getFreshGatewayObject( $options ); - - $this->assertTrue( $this->gatewayAdapter->validatedOK() ); - - $this->gatewayAdapter->do_transaction( "INSERT_ORDERWITHPAYMENT" ); - $action = $this->gatewayAdapter->getTransactionDataFormAction(); - $this->assertEquals( "url_placeholder", $action, "The formaction was not populated as expected (ideal)." ); - } - -} - diff --git a/tests/phpunit/Adapter/Ingenico/RecurringTest.php b/tests/phpunit/Adapter/Ingenico/RecurringTest.php deleted file mode 100644 index 20e2bf5..0000000 --- a/tests/phpunit/Adapter/Ingenico/RecurringTest.php +++ /dev/null @@ -1,135 +0,0 @@ -<?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 Ingenico - * @group Recurring - */ -class DonationInterface_Adapter_Ingenico_RecurringTest extends BaseIngenicoTestCase { - - public function setUp() { - parent::setUp(); - $this->markTestSkipped( 'Recurring not implemented' ); - } - - /** - * Can make a recurring payment - * - * @covers IngenicoAdapter::transactionRecurring_Charge - */ - public function testRecurringCharge() { - $init = array( - 'amount' => '2345', - 'effort_id' => 2, - 'order_id' => '9998890004', - 'currency' => 'EUR', - 'payment_product' => '', - ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( 'recurring-OK' ); - - $result = $gateway->do_transaction( 'Recurring_Charge' ); - - $this->assertTrue( $result->getCommunicationStatus() ); - $this->assertRegExp( '/SET_PAYMENT/', $result->getRawResponse() ); - } - - /** - * Can make a recurring payment - * - * @covers IngenicoAdapter::transactionRecurring_Charge - */ - public function testDeclinedRecurringCharge() { - $init = array( - 'amount' => '2345', - 'effort_id' => 2, - 'order_id' => '9998890004', - 'currency' => 'EUR', - 'payment_product' => '', - ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( 'recurring-declined' ); - - $result = $gateway->do_transaction( 'Recurring_Charge' ); - - $this->assertRegExp( - '/GET_ORDERSTATUS/', - $result->getRawResponse(), - 'Stopped after GET_ORDERSTATUS.' - ); - $this->assertEquals( - 2, - count( $gateway->curled ), - 'Expected 2 API calls' - ); - $this->assertEquals( FinalStatus::FAILED, $gateway->getFinalStatus() ); - } - - /** - * Throw errors if the payment is incomplete - * - * @covers IngenicoAdapter::transactionRecurring_Charge - */ - public function testRecurringTimeout() { - $init = array( - 'amount' => '2345', - 'effort_id' => 2, - 'order_id' => '9998890004', - 'currency' => 'EUR', - 'payment_product' => '', - ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( 'recurring-timeout' ); - - $result = $gateway->do_transaction( 'Recurring_Charge' ); - - $this->assertFalse( $result->getCommunicationStatus() ); - $this->assertRegExp( '/GET_ORDERSTATUS/', $result->getRawResponse() ); - // FIXME: This is a little funky--the transaction is actually pending-poke. - $this->assertEquals( FinalStatus::FAILED, $gateway->getFinalStatus() ); - } - - /** - * Can resume a recurring payment - * - * @covers IngenicoAdapter::transactionRecurring_Charge - */ - public function testRecurringResume() { - $init = array( - 'amount' => '2345', - 'effort_id' => 2, - 'order_id' => '9998890004', - 'currency' => 'EUR', - 'payment_product' => '', - ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->setDummyGatewayResponseCode( 'recurring-resume' ); - - $result = $gateway->do_transaction( 'Recurring_Charge' ); - - $this->assertTrue( $result->getCommunicationStatus() ); - $this->assertRegExp( '/SET_PAYMENT/', $result->getRawResponse() ); - } -} diff --git a/tests/phpunit/Adapter/Ingenico/ResultSwitcherTest.php b/tests/phpunit/Adapter/Ingenico/ResultSwitcherTest.php deleted file mode 100644 index 71072fd..0000000 --- a/tests/phpunit/Adapter/Ingenico/ResultSwitcherTest.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -/** - * @group Fundraising - * @group DonationInterface - * @group Ingenico - */ -class DonationInterface_Adapter_Ingenico_ResultSwitcherTest extends BaseIngenicoTestCase { - - /** - * Assuming we've popped out of the frame, does processing succeed? - */ - public function testResultSwitcherLiberatedSuccess() { - $this->markTestSkipped( 'ResultSwitcher not implemented' ); - $donorTestData = $this->getDonorTestData( 'FR' ); - $donorTestData['payment_method'] = 'cc'; - $donorTestData['payment_submethod'] = 'visa'; - $donorTestData['email'] = '[email protected]'; - $donorTestData['order_id'] = mt_rand(); - $session['Donor'] = $donorTestData; - // Mark the order as already popped out of the iframe - $session['order_status'][$donorTestData['order_id']] = 'liberated'; - $request = array( - 'REF' => $donorTestData['order_id'], - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0', - 'language' => 'fr', // FIXME: verifyFormOutput conflates request with other stuff - ); - $assertNodes = array( - 'headers' => array( - 'Location' => function( $location ) use ( $donorTestData ) { - // Do this after the real processing to avoid side effects - $gateway = $this->getFreshGatewayObject( $donorTestData ); - $url = ResultPages::getThankYouPage( $gateway ); - $this->assertEquals( $url, $location ); - } - ) - ); - - $this->verifyFormOutput( 'IngenicoGatewayResult', $request, $assertNodes, false, $session ); - // Make sure we logged the expected cURL attempts - $messages = $this->getLogMatches( 'info', '/Preparing to send GET_ORDERSTATUS transaction to Global Collect/' ); - $this->assertNotEmpty( $messages ); - $messages = $this->getLogMatches( 'info', '/Preparing to send SET_PAYMENT transaction to Global Collect/' ); - $this->assertNotEmpty( $messages ); - } -} diff --git a/tests/phpunit/BaseIngenicoTestCase.php b/tests/phpunit/BaseIngenicoTestCase.php deleted file mode 100644 index 53b0618..0000000 --- a/tests/phpunit/BaseIngenicoTestCase.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php - -use SmashPig\Core\Context; -use SmashPig\PaymentProviders\Ingenico\HostedCheckoutProvider; -use SmashPig\Tests\TestingContext; -use SmashPig\Tests\TestingProviderConfiguration; - -class BaseIngenicoTestCase extends DonationInterfaceTestCase { - - /** - * @var HostedCheckoutProvider - */ - protected $hostedCheckoutProvider; - - protected $testAdapterClass = 'IngenicoAdapter'; - - protected function setUp() { - parent::setUp(); - $providerConfig = $this->setSmashPigProvider( 'ingenico' ); - - $this->hostedCheckoutProvider = $this->getMockBuilder( - 'SmashPig\PaymentProviders\Ingenico\HostedCheckoutProvider' - )->disableOriginalConstructor()->getMock(); - - $providerConfig->overrideObjectInstance( - 'payment-provider/cc', - $this->hostedCheckoutProvider - ); - - $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( - 'wgIngenicoGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'cc-vmad' => array( - 'gateway' => 'ingenico', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'discover' )), - 'countries' => array( - '+' => $vmad_countries, - ), - ), - 'cc-vmaj' => array( - 'gateway' => 'ingenico', - 'payment_methods' => array('cc' => array( 'visa', 'mc', 'amex', 'jcb' )), - 'countries' => array( - '+' => $vmaj_countries, - ), - ), - 'cc-vma' => array( - 'gateway' => 'ingenico', - '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' => 'ingenico', - 'countries' => array( - '+' => array( 'AT', 'BE', 'CH', 'DE' ), - '-' => 'GB' - ), - 'currencies' => array( '+' => 'EUR' ), - 'payment_methods' => array('rtbt' => 'rtbt_sofortuberweisung'), - ), - ), - ) ); - } -} diff --git a/tests/phpunit/DonationInterfaceTestCase.php b/tests/phpunit/DonationInterfaceTestCase.php deleted file mode 100644 index c19b332..0000000 --- a/tests/phpunit/DonationInterfaceTestCase.php +++ /dev/null @@ -1,728 +0,0 @@ -<<<<<<< HEAD (215192 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; -use SmashPig\Tests\TestingContext; -use SmashPig\Tests\TestingGlobalConfiguration; -use SmashPig\Tests\TestingProviderConfiguration; -use Wikimedia\TestingAccessWrapper; - -/** - * @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' => 'USD', - ); - - /** - * This will be set by a test method with the adapter object. - * - * @var GatewayAdapter $gatewayAdapter - */ - protected $gatewayAdapter; - - protected $testAdapterClass = TESTS_ADAPTER_DEFAULT; - protected $smashPigGlobalConfig; - - /** - * @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 $wgDonationInterfaceTest; - $wgDonationInterfaceTest = true; - - parent::__construct( $name, $data, $dataName ); - } - - protected function setUp() { - // TODO: Use SmashPig dependency injection instead. Also override - // SmashPig core logger. - DonationLoggerFactory::$overrideLogger = new TestingDonationLogger(); - // Replace real SmashPig context with test version that lets us - // override provider configurations that may be set in code - $this->smashPigGlobalConfig = TestingGlobalConfiguration::create(); - TestingContext::init( $this->smashPigGlobalConfig ); - Context::get()->setSourceType( 'payments' ); - Context::get()->setSourceName( 'DonationInterface' ); - 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() ); - } - - /** - * @param string $provider - * @return TestingProviderConfiguration - */ - protected function setSmashPigProvider( $provider ) { - $providerConfig = TestingProviderConfiguration::createForProvider( - $provider, $this->smashPigGlobalConfig - ); - TestingContext::get()->providerConfigurationOverride = $providerConfig; - return $providerConfig; - } - - /** - * 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_province' => 'CA', - 'postal_code' => '94105', - 'currency' => 'USD', - 'street_address' => '123 Fake Street', - 'first_name' => 'Firstname', - 'last_name' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - 'email' => '[email protected]', - ), - 'ES' => array ( - 'city' => 'Barcelona', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 Calle Fake', - 'first_name' => 'Nombre', - 'last_name' => 'Apellido', - 'amount' => '1.55', - 'language' => 'es', - ), - 'Catalonia' => array ( - 'city' => 'Barcelona', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 Calle Fake', - 'first_name' => 'Nombre', - 'last_name' => 'Apellido', - 'amount' => '1.55', - 'language' => 'ca', - ), - 'NO' => array ( - 'city' => 'Oslo', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 Fake Gate', - 'first_name' => 'Fornavn', - 'last_name' => 'Etternavn', - 'amount' => '1.55', - 'language' => 'no', - ), - 'FR' => array ( - 'city' => 'Versailles', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 Rue Faux', - 'first_name' => 'Prénom', - 'last_name' => '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_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 Fake Street', - 'first_name' => 'FirstName', - 'last_name' => 'LastName', - 'amount' => '1.55', - 'language' => 'en', - ), - 'NL' => array ( - 'city' => 'Amsterdam', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 nep straat', - 'first_name' => 'Voornaam', - 'last_name' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'BE' => array ( - 'city' => 'Antwerp', - 'state_province' => 'XX', - 'postal_code' => '0', - 'currency' => 'EUR', - 'street_address' => '123 nep straat', - 'first_name' => 'Voornaam', - 'last_name' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'IT' => array ( - 'city' => 'Torino', - 'state_province' => 'TO', - 'postal_code' => '10123', - 'currency' => 'EUR', - 'street_address' => 'Via Falso 123', - 'first_name' => 'Nome', - 'last_name' => 'Cognome', - 'amount' => '1.55', - 'language' => 'it', - ), - 'CA' => array ( - 'city' => 'Saskatoon', - 'state_province' => 'SK', - 'postal_code' => 'S7K 0J5', - 'currency' => 'CAD', - 'street_address' => '123 Fake Street', - 'first_name' => 'Firstname', - 'last_name' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - ), - 'BR' => array ( - 'currency' => 'BRL', - 'fiscal_number' => '00003456789', - 'payment_submethod' => 'test_bank', - 'first_name' => 'Nome', - 'last_name' => 'Apelido', - 'amount' => '100', - 'language' => 'pt', - 'email' => '[email protected]' - ), - 'MX' => array ( - 'city' => 'Tuxtla Gutiérrez', - 'state_province' => 'CHP', - 'currency' => 'MXN', - 'street_address' => 'Calle Falso 123', - 'first_name' => 'Nombre', - 'last_name' => 'Apellido', - 'email' => '[email protected]', - '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'] . '</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'] . '</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['first_name'] . '</FIRSTNAME>'; - $expected .= '<SURNAME>' . $options['last_name'] . '</SURNAME>'; - $expected .= '<STREET>' . $options['street_address'] . '</STREET>'; - $expected .= '<CITY>' . $options['city'] . '</CITY>'; - $expected .= '<STATE>' . $options['state_province'] . '</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() ) { - $data = null; - if ( !is_null( $external_data ) ) { - $data = array ( - 'external_data' => $external_data, - ); - } - - if ( $setup_hacks ) { - if ( !is_null( $data ) ) { - $data = array_merge( $data, $setup_hacks ); - } else { - $data = $setup_hacks; - } - } - - $class = $this->testAdapterClass; - $gateway = new $class( $data ); - - $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() { - // TODO: reset PDO/sqlite queues - $_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 ); - // Clear out our HashBagOStuff, used for testing - wfGetMainCache()->clear(); - } - - /** - * 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 in html. Log entries: \n" . - print_r( DonationLoggerFactory::$overrideLogger->messages, true ) . "\n\nHTML:\n$form_html" ); - 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 = DonationLoggerFactory::$overrideLogger->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. - * FIXME: Or false. Return an empty array or throw an exception instead. - */ - public static function getLogMatches( $log_level, $match ) { - $log = DonationLoggerFactory::$overrideLogger->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; - } - - public static function unsetVariableFields( &$message ) { - $fields = array( - 'date', 'source_enqueued_time', 'source_host', 'source_run_id', 'source_version', 'gateway_account' - ); - foreach ( $fields as $field ) { - unset( $message[$field] ); - } - } -} ->>>>>>> BRANCH (e38c59 Update SmashPig library) diff --git a/tests/phpunit/TestConfiguration.php b/tests/phpunit/TestConfiguration.php deleted file mode 100644 index bd0dd54..0000000 --- a/tests/phpunit/TestConfiguration.php +++ /dev/null @@ -1,253 +0,0 @@ -<<<<<<< HEAD (215192 Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This file contains custom options and constants for test configuration. - */ - -/** - * TESTS_MESSAGE_NOT_IMPLEMENTED - * - * Message for code that has not been implemented. - */ -define( 'TESTS_MESSAGE_NOT_IMPLEMENTED', 'Not implemented yet!' ); - -/** - * TESTS_HOSTNAME - * - * The hostname for the system - */ -define( 'TESTS_HOSTNAME', 'localhost' ); - -/** - * TESTS_EMAIL - * - * An email address to use in case test send mail - */ -define( 'TESTS_EMAIL', '[email protected]' ); - -/** - * TESTS_GATEWAY_DEFAULT - * - * This is the default gateway that will be used to implement unit tests. - */ -define( 'TESTS_GATEWAY_DEFAULT', 'GlobalCollectGateway' ); - -/** - * TESTS_ADAPTER_DEFAULT - * - * This is the default adapter that will be used to implement unit tests. - */ -define( 'TESTS_ADAPTER_DEFAULT', 'TestingGlobalCollectAdapter' ); - -global $wgDonationInterfaceTest, - $wgDonationInterfaceMerchantID, - $wgDonationInterfaceGatewayAdapters, - $wgDonationInterfaceAllowedHtmlForms, - $wgDonationInterfaceThankYouPage, - $wgGlobalCollectGatewayAccountInfo, - $wgPaypalGatewayAccountInfo, - $wgPaypalGatewayReturnURL, - $wgPaypalExpressGatewayURL, - $wgPaypalExpressGatewayTestingURL, - $wgPaypalExpressGatewaySignatureURL, - $wgPaypalExpressGatewayAccountInfo, - $wgAmazonGatewayReturnURL, - $wgAmazonGatewayAccountInfo, - $wgAdyenGatewayURL, - $wgAdyenGatewayAccountInfo, - $wgAstroPayGatewayURL, - $wgAstroPayGatewayTestingURL, - $wgAstroPayGatewayAccountInfo, - $wgAstroPayGatewayFallbackCurrency, - $wgMinFraudLicenseKey, - $wgMinFraudTimeout, - $wgDonationInterfaceMinFraudServers, - $wgDonationInterfaceEnableMinfraud, - $wgDonationInterfaceEnableFunctionsFilter, - $wgDonationInterfaceEnableReferrerFilter, - $wgDonationInterfaceEnableSourceFilter, - $wgDonationInterfaceCustomFiltersActionRanges, - $wgDonationInterfaceCustomFiltersRefRules, - $wgDonationInterfaceCustomFiltersSrcRules, - $wgDonationInterfaceCustomFiltersFunctions, - $wgGlobalCollectGatewayCustomFiltersFunctions, - $wgIngenicoGatewayCustomFiltersFunctions, - $wgDonationInterfaceCountryMap, - $wgDonationInterfaceUtmCampaignMap, - $wgDonationInterfaceUtmSourceMap, - $wgDonationInterfaceUtmMediumMap, - $wgDonationInterfaceEmailDomainMap, - $wgMainCacheType; - -$wgMainCacheType = 'hash'; - -$wgDonationInterfaceGatewayAdapters = array( - 'globalcollect'=> 'TestingGlobalCollectAdapter', - 'ingenico' => 'IngenicoAdapter', - 'amazon'=> 'TestingAmazonAdapter', - 'adyen'=> 'TestingAdyenAdapter', - 'astropay'=> 'TestingAstroPayAdapter', - 'paypal_ec'=> 'TestingPaypalExpressAdapter', - 'paypal'=> 'TestingPaypalLegacyAdapter' -); -/** - * Make sure the test setup is used, else we'll have the wrong classes. - */ -/** DonationInterface General Settings **/ -$wgDonationInterfaceTest = true; -$wgDonationInterfaceMerchantID = 'test'; - -$wgDonationInterfaceThankYouPage = 'https://wikimediafoundation.org/wiki/Thank_You'; - - -/** GlobalCollect **/ -$wgGlobalCollectGatewayAccountInfo = array(); -$wgGlobalCollectGatewayAccountInfo['test'] = array( - 'MerchantID' => 'test', -); - -/** Paypal **/ -$wgPaypalGatewayAccountInfo = array(); -$wgPaypalGatewayAccountInfo['testing'] = array( - 'AccountEmail' => '[email protected]', -); -$wgPaypalGatewayReturnURL = 'http://donate.wikimedia.org'; // whatever, doesn't matter. - - -/** Paypal Express Checkout **/ -$wgPaypalExpressGatewayURL = 'https://api-3t.sandbox.paypal.com/nvp'; -$wgPaypalExpressGatewayTestingURL = 'https://api-3t.sandbox.paypal.com/nvp'; -$wgPaypalExpressGatewaySignatureURL = $wgPaypalExpressGatewayURL; -$wgPaypalExpressGatewayAccountInfo['test'] = array( - 'User' => '[email protected]', - 'Password' => '9876543210', - 'Signature' => 'ABCDEFGHIJKLMNOPQRSTUV-ZXCVBNMLKJHGFDSAPOIUYTREWQ', - 'RedirectURL' => 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=', -); - - -/** Amazon **/ -$wgAmazonGatewayReturnURL = 'https://payments.wikimedia.org/index.php/Special:AmazonGateway'; -$wgAmazonGatewayAccountInfo = array(); -$wgAmazonGatewayAccountInfo['test'] = array( - 'SellerID' => 'ABCDEFGHIJKL', - 'ClientID' => 'amzn1.application-oa2-client.1a2b3c4d5e', - 'ClientSecret' => '12432g134e3421a41234b1341c324123d', - 'MWSAccessKey' => 'N0NSENSEXYZ', - 'MWSSecretKey' => 'iuasd/2jhaslk2j49lkaALksdJLsJLas+', - 'Region' => 'us', - 'WidgetScriptURL' => - 'https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js', - 'ReturnURL' => "https://example.org/index.php/Special:AmazonGateway?debug=true", -); - -/** Adyen **/ -$wgAdyenGatewayURL = 'https://testorwhatever.adyen.com'; -$wgAdyenGatewayAccountInfo = array(); -$wgAdyenGatewayAccountInfo['test'] = array( - 'AccountName' => 'wikitest', - 'SharedSecret' => 'C7F1D9E29479CF18131063A742CD2703FB9D48BAB0160693045E3FB7B8508E59', - 'SkinCode' => 'testskin', -); - -/** AstroPay **/ -$wgAstroPayGatewayURL = 'https://astropay.example.com/'; -$wgAstroPayGatewayTestingURL = 'https://sandbox.astropay.example.com/'; -$wgAstroPayGatewayAccountInfo = array(); -$wgAstroPayGatewayAccountInfo['test'] = array( - 'Create' => array( - 'Login' => 'createlogin', - 'Password' => 'createpass', - ), - 'Status' => array( - 'Login' => 'statuslogin', - 'Password' => 'statuspass', - ), - 'SecretKey' => 'NanananananananananananananananaBatman', -); -$wgAstroPayGatewayFallbackCurrency = false; - -$wgMinFraudLicenseKey = 'testkey'; -$wgMinFraudTimeout = 1; -$wgDonationInterfaceMinFraudServers = array( "minfraud.wikimedia.org" ); - -// still can't quite handle minfraud by itself yet, so default like this. -// I will turn it on for individual tests in which I want to verify that it at -// least fails closed when enabled. -$wgDonationInterfaceEnableMinfraud = false; - -// ...but we want these. -$wgDonationInterfaceEnableFunctionsFilter = true; -$wgDonationInterfaceEnableReferrerFilter = true; -$wgDonationInterfaceEnableSourceFilter = true; - -$customFilters = array( - 'getScoreCountryMap' => 50, - 'getScoreUtmCampaignMap' => 50, - 'getScoreUtmSourceMap' => 15, - 'getScoreUtmMediumMap' => 15, - 'getScoreEmailDomainMap' => 75, -); - - -$wgDonationInterfaceCustomFiltersActionRanges = array ( - 'process' => array ( 0, 25 ), - 'review' => array ( 25, 50 ), - 'challenge' => array ( 50, 75 ), - 'reject' => array ( 75, 100 ), -); - -$wgDonationInterfaceCustomFiltersRefRules = array ( - '/donate-error/i' => 5, -); - -$wgDonationInterfaceCustomFiltersSrcRules = array ( '/wikimedia\.org/i' => 80 ); - -$wgDonationInterfaceCustomFiltersFunctions = $customFilters; - -$wgGlobalCollectGatewayCustomFiltersFunctions = array( - 'getCVVResult' => 20, - 'getAVSResult' => 25, -) + $customFilters; - -$wgIngenicoGatewayCustomFiltersFunctions = $wgGlobalCollectGatewayCustomFiltersFunctions; - -$wgDonationInterfaceCountryMap = array ( - 'US' => 40, - 'CA' => 15, - 'RU' => -4, -); - -$wgDonationInterfaceUtmCampaignMap = array ( - '/^(C14_)/' => 14, - '/^(spontaneous)/' => 5 -); - -$wgDonationInterfaceUtmSourceMap = array ( - '/somethingmedia/' => 70 -); - -$wgDonationInterfaceUtmMediumMap = array ( - '/somethingmedia/' => 80 -); - -$wgDonationInterfaceEmailDomainMap = array ( - 'wikimedia.org' => 42, - 'wikipedia.org' => 50, -); ->>>>>>> BRANCH (e38c59 Update SmashPig library) diff --git a/vendor b/vendor index dfd9802..f0d4a39 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit dfd9802fc4f493f3740a24150a45717c2d3f2032 +Subproject commit f0d4a39c11adb48e7a22362cf34ecb895a17bb1c -- To view, visit https://gerrit.wikimedia.org/r/373100 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icb4fc61132a57692f2ede55983c5d3daeab0d183 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
