Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/205304
Change subject: Merge master into deployment ...................................................................... Merge master into deployment - e952b1696e73f4f0d787ef243fcc6dab20d2a2c5 Localisation updates from https://translatewiki.net. + cecd25acbc4a2252d54e15bedab7de1055b5b56e Clarify some 'object's in PHPdoc strings + fdb0e49f6d3c52cabff1a62ad6ee0352a20e6577 Simplify communication_type nonsense + 27cd4f2ecaf737aaf5aad959557f1e50b50d7087 Add skeleton of Astropay gateway + 40da0c3be50a17675918c017d61be55708965049 Localisation updates from https://translatewiki.net. + 342540d1d0c9a4bc0fc7768d68e85cd86b32aa9c Use curl_setopt_array instead of a loop + 33e7c5959af3a1a402bcb94416c1d3cf30b46da1 Update required version of Monolog to 1.12.0 + 5286123f15c9ecbec74d59919290d16791a8dae7 Fix content-type for non-XML POSTs - cfa87f291a7f3430fefee3d10c79e8f3cfd9691f Localisation updates from https://translatewiki.net. + cb0a079f6f3427674dbc470de68ecb666e0d6cd8 Fix unstaging issue - ff330d39ea438aa0b174bb51f0c189c7a4279d1e Change recurring info text for new legal requirements + 037208c0fdfb8ab430516d27190c748455ce034b Localisation updates from https://translatewiki.net. + 15e562bac2369c08a9d53ad3fc9246b9bcb4f0f8 Localisation updates from https://translatewiki.net. + d061034c93cd97c36187be7c5dcc57758e83ec73 Localisation updates from https://translatewiki.net. + 23cfb0d82e9a422461b1fbaa3e7ee613eaaa75f0 Localisation updates from https://translatewiki.net. + 65a6cf8c773ada9e525ac7dd80cb755fb061648a Localisation updates from https://translatewiki.net. + 9f6501fe0363a97aabe48a391665f651c4a8cf40 Implement a Handlebars form renderer + eddffceb08613d9df967e0924aa80ff6bd9b7923 Document Handlebars rendering class + a658465c77b80181843183a34ac5e400c689f39e Tests for the Handlebars form renderer + 55365157d549421aafe407754664b6d55f6ff599 Localisation updates from https://translatewiki.net. + c01931c78bca921d7d977d7464fa2893af91762d Localisation updates from https://translatewiki.net. + 442003ba92e1a5e3f916ca037283dfcd40e91f16 Localisation updates from https://translatewiki.net. + 222fe62ea5958c8218c1e8aa069e5fa9b07772be Use transaction-specific URLs for Astropay + 3dc64ef5df68da715e359acd0ec1b6821ca1b5f5 Sign Astropay transactions + 5daae632b996b4d1c47c42a03927db08348c20b7 Parse JSON responses, get Astropay status and errors + 35528e80a0eb4448361a9699686d09f4e0de82f9 Redirect to Astropay on successful NewInvoice + ef5faea488da5b21836a3cc7132546e12d5de01d Change English error messages + 3cd38258731873e56921334eeef67b49c1eb1c12 Fail on any unrecognized CVV return codes + bbf3d5cdf45adbe5034ced0340d08f01018f8146 Localisation updates from https://translatewiki.net. + 7ccfd2c5d5f57c1e14e9268418c185b5323f067f Correcting s/handlebars/mustache/ + a88e7293ecf7528309b40f5e9477f8730e0321e3 Localisation updates from https://translatewiki.net. + e86e4d5d149fa70aa466d67a5c8a832ad601f044 Localisation updates from https://translatewiki.net. Change-Id: If957354df55ce0b3d204a4d8d1e527b868efd006 --- M DonationInterface.php M astropay_gateway/i18n/zh-hans.json D tests/Adapter/Astropay/AstropayTest.php D tests/Adapter/GlobalCollect/GlobalCollectTest.php D tests/DonationInterfaceTestCase.php D tests/HandlebarsFormTest.php D tests/TestConfiguration.php D tests/data/mustache/currency.mustache D tests/data/mustache/empty.mustache D tests/data/mustache/foo.mustache D tests/includes/Responses/astropay/NewInvoice.testresponse D tests/includes/Responses/astropay/NewInvoice_1.testresponse D tests/includes/Responses/globalcollect/GET_ORDERSTATUS_800.testresponse D tests/includes/test_gateway/TestingAstropayAdapter.php D tests/includes/test_gateway/TestingGenericAdapter.php 15 files changed, 0 insertions(+), 1,877 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/04/205304/1 diff --git a/DonationInterface.php b/DonationInterface.php index f976f65..83a8f82 100644 --- a/DonationInterface.php +++ b/DonationInterface.php @@ -1067,38 +1067,6 @@ if ($optionalParts['Stomp'] === true){ require_once( $donationinterface_dir . 'activemq_stomp/activemq_stomp.php' ); $wgAutoloadClasses['Stomp'] = $donationinterface_dir . 'activemq_stomp/Stomp.php'; -<<<<<<< HEAD (b4626c Update vendor submodule) -======= -} - -function efDonationInterfaceUnitTests( &$files ) { - global $wgAutoloadClasses; - - $testDir = __DIR__ . '/tests/'; - - $files[] = $testDir . 'AllTests.php'; - - $wgAutoloadClasses['DonationInterfaceTestCase'] = $testDir . 'DonationInterfaceTestCase.php'; - - $wgAutoloadClasses['TestingAdyenAdapter'] = $testDir . 'includes/test_gateway/TestingAdyenAdapter.php'; - $wgAutoloadClasses['TestingAmazonAdapter'] = $testDir . 'includes/test_gateway/TestingAmazonAdapter.php'; - $wgAutoloadClasses['TestingAstropayAdapter'] = $testDir . 'includes/test_gateway/TestingAstropayAdapter.php'; - $wgAutoloadClasses['TestingAmazonGateway'] = $testDir . 'includes/test_page/TestingAmazonGateway.php'; - $wgAutoloadClasses['TestingDonationLogger'] = $testDir . 'includes/TestingDonationLogger.php'; - $wgAutoloadClasses['TestingGatewayPage'] = $testDir . 'includes/TestingGatewayPage.php'; - $wgAutoloadClasses['TestingGenericAdapter'] = $testDir . 'includes/test_gateway/TestingGenericAdapter.php'; - $wgAutoloadClasses['TestingGlobalCollectAdapter'] = $testDir . 'includes/test_gateway/TestingGlobalCollectAdapter.php'; - $wgAutoloadClasses['TestingGlobalCollectGateway'] = $testDir . 'includes/test_page/TestingGlobalCollectGateway.php'; - $wgAutoloadClasses['TestingGlobalCollectOrphanAdapter'] = $testDir . 'includes/test_gateway/TestingGlobalCollectOrphanAdapter.php'; - $wgAutoloadClasses['TestingPaypalAdapter'] = $testDir . 'includes/test_gateway/TestingPaypalAdapter.php'; - $wgAutoloadClasses['TestingWorldPayAdapter'] = $testDir . 'includes/test_gateway/TestingWorldPayAdapter.php'; - $wgAutoloadClasses['TestingWorldPayGateway'] = $testDir . 'includes/test_page/TestingWorldPayGateway.php'; - - $wgAutoloadClasses['TestingLanguage'] = $testDir . 'includes/test_language/test.language.php'; - $wgAutoloadClasses['TestingRequest'] = $testDir . 'includes/test_request/test.request.php'; - - return true; ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") } unset( $optionalParts ); diff --git a/astropay_gateway/i18n/zh-hans.json b/astropay_gateway/i18n/zh-hans.json index 240da34..a8096e8 100644 --- a/astropay_gateway/i18n/zh-hans.json +++ b/astropay_gateway/i18n/zh-hans.json @@ -4,10 +4,6 @@ "Liuxinyu970226" ] }, -<<<<<<< HEAD (b4626c Update vendor submodule) - "astropaygateway": "现在就进行捐款", -======= "astropaygateway": "马上捐款", ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") "astropay_gateway-desc": "Astropay支付程序" } diff --git a/tests/Adapter/Astropay/AstropayTest.php b/tests/Adapter/Astropay/AstropayTest.php deleted file mode 100644 index d7e15c1..0000000 --- a/tests/Adapter/Astropay/AstropayTest.php +++ /dev/null @@ -1,153 +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; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Astropay - */ -class DonationInterface_Adapter_Astropay_AstropayTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingAstropayAdapter'; - } - - function tearDown() { - TestingAstropayAdapter::clearGlobalsCache(); - parent::tearDown(); - } - - /** - * Ensure we're setting the right url for each transaction - * @covers AstropayAdapter::getCurlBaseOpts - */ - function testCurlUrl() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setCurrentTransaction( 'NewInvoice' ); - - $result = $gateway->getCurlBaseOpts(); - - $this->assertEquals( - 'https://sandbox.astropay.example.com/api_curl/streamline/NewInvoice', - $result[CURLOPT_URL], - 'Not setting URL to transaction-specific value.' - ); - } - - /** - * Test the NewInvoice transaction is making a sane request and signing - * it correctly - */ - function testNewInvoiceRequest() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $_SESSION['Donor']['order_id'] = '123456789'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'NewInvoice' ); - parse_str( $gateway->curled[0], $actual ); - - $expected = array( - 'x_login' => 'createlogin', - 'x_trans_key' => 'createpass', - 'x_invoice' => '123456789', - 'x_amount' => '100.00', - 'x_currency' => 'BRL', - 'x_bank' => 'TE', - 'x_country' => 'BR', - 'x_description' => wfMessage( 'donate_interface-donation-description' )->inLanguage( $init['language'] )->text(), - 'x_iduser' => '08feb2d12771bbcfeb86', - 'x_cpf' => '00003456789', - 'x_name' => 'Nome Apelido', - 'x_email' => '[email protected]', - 'x_address' => 'Rua Falso 123', - 'x_zip' => '01110-111', - 'x_city' => 'São Paulo', - 'x_state' => 'SP', - 'control' => '5853FD808AA10839CB268ED2D1D6D4E8D8FECA88E4A8D66477369C0CA8AA4B42', - 'type' => 'json', - ); - $this->assertEquals( $expected, $actual, 'NewInvoice is not including the right parameters' ); - } - - /** - * When Astropay sends back valid JSON with status "0", we should set txn - * status to true and errors should be empty. - */ - function testStatusNoErrors() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'NewInvoice' ); - - $this->assertEquals( true, $gateway->getTransactionStatus(), - 'Transaction status should be true for code "0"' ); - - $this->assertEmpty( $gateway->getTransactionErrors(), - 'Transaction errors should be empty for code "0"' ); - } - - /** - * When Astropay sends back valid JSON with status "1", we should set txn - * status to false and error array to generic error and log a warning. - */ - function testStatusErrors() { - $init = $this->getDonorTestData( 'BR' ); - $this->setLanguage( $init['language'] ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '1' ); - - $gateway->do_transaction( 'NewInvoice' ); - - $this->assertEquals( false, $gateway->getTransactionStatus(), - 'Transaction status should be false for code "1"' ); - - $expected = array( - wfMessage( 'donate_interface-processing-error')->inLanguage( $init['language'] )->text() - ); - $this->assertEquals( $expected, $gateway->getTransactionErrors(), - 'Wrong error for code "1"' ); - $logged = $this->getLogMatches( LogLevel::WARNING, '/This error message should appear in the log.$/' ); - $this->assertNotEmpty( $logged ); - } - - /** - * do_transaction should set redirect key when we get a valid response. - */ - function testRedirectOnSuccess() { - $init = $this->getDonorTestData( 'BR' ); - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'NewInvoice' ); - - // from the test response - $expected = 'https://sandbox.astropaycard.com/go_to_bank?id=A5jvKfK1iHIRUTPXXt8lDFGaRRLzPgBg'; - $results = $gateway->getTransactionAllResults(); - $this->assertEquals( $expected, $results['redirect'], - 'do_transaction is not setting the right redirect' ); - } -} diff --git a/tests/Adapter/GlobalCollect/GlobalCollectTest.php b/tests/Adapter/GlobalCollect/GlobalCollectTest.php deleted file mode 100644 index e16cc7a..0000000 --- a/tests/Adapter/GlobalCollect/GlobalCollectTest.php +++ /dev/null @@ -1,525 +0,0 @@ -<<<<<<< HEAD (b4626c Update vendor submodule) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group GlobalCollect - */ -class DonationInterface_Adapter_GlobalCollect_GlobalCollectTest extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingGlobalCollectAdapter'; - } - - function tearDown() { - TestingGlobalCollectAdapter::clearGlobalsCache(); - parent::tearDown(); - } - - /** - * testnormalizeOrderID - * Non-exhaustive integration tests to verify that order_id - * normalization works as expected with different settings and - * conditions in theGlobalCollect adapter - * @covers GatewayAdapter::normalizeOrderID - */ - public function testNormalizeOrderID() { - $init = $this->initial_vars; - unset( $init['order_id'] ); - - //no order_id from anywhere, explicit no generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertFalse( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Deferred order_id generation may be broken.' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Self order_id generation may be broken.' ); - $this->assertInternalType( 'numeric', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is not numeric, which it should be for GlobalCollect' ); - - $_GET['order_id'] = '55555'; - $_SESSION['Donor']['order_id'] = '44444'; - - //conflicting order_id in $GET and $SESSION, default GC generation - $gateway = $this->getFreshGatewayObject( $init ); - $this->assertEquals( '55555', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is preferring session data over the $_GET. Session should be secondary.' ); - - //conflicting order_id in $GET and $SESSION, garbage data in $_GET, default GC generation - $_GET['order_id'] = 'nonsense!'; - $gateway = $this->getFreshGatewayObject( $init ); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not ignoring nonsensical order_id candidates' ); - - unset( $_GET['order_id'] ); - //order_id in $SESSION, default GC generation - $gateway = $this->getFreshGatewayObject( $init ); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not recognizing the session order_id' ); - - $_POST['order_id'] = '33333'; - //conflicting order_id in $_POST and $SESSION, default GC generation - $gateway = $this->getFreshGatewayObject( $init ); - $this->assertEquals( '33333', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is preferring session data over the $_POST. Session should be secondary.' ); - - $init['order_id'] = '22222'; - //conflicting order_id in init data, $_POST and $SESSION, explicit GC generation, batch mode - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE ), 'batch_mode' => TRUE, ) ); - $this->assertEquals( $init['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an extrenally provided order id is being honored in batch mode' ); - - //make sure that decimal numbers are rejected by GC. Should be a toss and regen - $init['order_id'] = '2143.0'; - unset( $_POST['order_id'] ); - unset( $_SESSION['Donor']['order_id'] ); - //conflicting order_id in init data, $_POST and $SESSION, explicit GC generation, batch mode - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE, 'disallow_decimals' => TRUE ), 'batch_mode' => TRUE, ) ); - $this->assertNotEquals( $init['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed assering that a decimal order_id was regenerated, when disallow_decimals is true' ); - } - - /** - * Non-exhaustive integration tests to verify that order_id, when in - * self-generation mode, won't regenerate until it is told to. - * @covers GatewayAdapter::normalizeOrderID - * @covers GatewayAdapter::regenerateOrderID - */ - function testStickyGeneratedOrderID() { - $init = $this->initial_vars; - unset( $init['order_id'] ); - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is null. The rest of this test is broken.' ); - $original_order_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); - - $gateway->normalizeOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has changed without explicit regeneration.' ); - - //this might look a bit strange, but we need to be able to generate valid order_ids without making them stick to anything. - $gateway->generateOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'function generateOrderID auto-changed the selected order ID. Not cool.' ); - - $gateway->regenerateOrderID(); - $this->assertNotEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has not changed, after explicit regeneration.' ); - } - - /** - * Integration test to verify that order_id can be retrieved from - * performing an INSERT_ORDERWITHPAYMENT. - */ - function testOrderIDRetrieval() { - $init = $this->getDonorTestData(); - unset( $init['order_id'] ); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - - //no order_id from anywhere, explicit generate - $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Ungenerated order_id is not null. The rest of this test is broken.' ); - - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'No order_id was retrieved from INSERT_ORDERWITHPAYMENT' ); - } - - /** - * Just run the GET_ORDERSTATUS transaction and make sure we load the data - */ - function testGetOrderStatus() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - - $data = $gateway->getTransactionData(); - - $this->assertEquals( 'N', $data['CVVRESULT'], 'CVV Result not loaded from XML response' ); - } - - /** - * Don't fraud-fail someone for bad CVV if GET_ORDERSTATUS - * comes back with STATUSID 25 and no CVVRESULT - * @group CvvResult - */ - function testConfirmCreditCardStatus25() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( 'CVVRESULT' => 'M' ), false ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '25' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $action = $gateway->getValidationAction(); - $this->assertEquals( 'process', $action, 'Gateway should not fraud fail on STATUSID 25' ); - } - - /** - * If CVVRESULT is unrecognized, fraud-fail and warn - * @group CvvResult - */ - function testConfirmCreditCardBadCVVResult() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( 'CVVRESULT' => ' ' ), false ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '800' ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - $result = $gateway->getCvvResult(); - $this->assertEquals( false, $result, 'Gateway should fraud fail if CVVRESULT is not mapped' ); - $matches = $this->getLogMatches( LogLevel::WARNING, "/Unrecognized cvv_result ' '$/" ); - $this->assertNotEmpty( $matches, 'Did not log expected warning on unmapped CVVRESULT' ); - } - - /** - * We should skip the API call if we're already suspicious - */ - function testGetOrderStatusSkipsIfFail() { - DonationInterface_FraudFiltersTest::setupFraudMaps(); - - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; //configured as a fraudy domain - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - - $data = $gateway->getTransactionData(); - - $this->assertEquals( null, $data['CVVRESULT'], 'preprocess should stop API call if fraud detected' ); - } - - /** - * Ensure the Confirm_CreditCard transaction prefers CVVRESULT from the XML - * over any value from the querystring - */ - function testConfirmCreditCardPrefersXmlCvv() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( 'CVVRESULT' => 'M' ), false ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'Confirm_CreditCard' ); - - $this->assertEquals( 'N', $gateway->getData_Unstaged_Escaped('cvv_result'), 'CVV Result not taken from XML response' ); - } - - /** - * If querystring and XML have different CVVRESULT, that's awfully fishy - */ - function testConfirmCreditCardFailsOnCvvResultConflict() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = '[email protected]'; - - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( 'CVVRESULT' => 'M' ), false ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - - $result = $gateway->do_transaction( 'Confirm_CreditCard' ); - - $this->assertFalse( $result['status'], 'Credit card should fail if querystring and XML have different CVVRESULT' ); - } - - /** - * testDefineVarMap - * - * This is tested with a bank transfer from Spain. - * - * @covers GlobalCollectAdapter::__construct - * @covers GlobalCollectAdapter::defineVarMap - */ - public function testDefineVarMap() { - - $gateway = $this->getFreshGatewayObject( $this->initial_vars ); - - $var_map = array( - 'ORDERID' => 'order_id', - 'AMOUNT' => 'amount', - 'CURRENCYCODE' => 'currency_code', - 'LANGUAGECODE' => 'language', - 'COUNTRYCODE' => 'country', - 'MERCHANTREFERENCE' => 'contribution_tracking_id', - 'RETURNURL' => 'returnto', - 'IPADDRESS' => 'server_ip', - 'ISSUERID' => 'issuer_id', - 'PAYMENTPRODUCTID' => 'payment_product', - 'CVV' => 'cvv', - 'EXPIRYDATE' => 'expiration', - 'CREDITCARDNUMBER' => 'card_num', - 'FIRSTNAME' => 'fname', - 'SURNAME' => 'lname', - 'STREET' => 'street', - 'CITY' => 'city', - 'STATE' => 'state', - 'ZIP' => 'zip', - 'EMAIL' => 'email', - 'ACCOUNTHOLDER' => 'account_holder', - 'ACCOUNTNAME' => 'account_name', - 'ACCOUNTNUMBER' => 'account_number', - 'ADDRESSLINE1E' => 'address_line_1e', - 'ADDRESSLINE2' => 'address_line_2', - 'ADDRESSLINE3' => 'address_line_3', - 'ADDRESSLINE4' => 'address_line_4', - 'ATTEMPTID' => 'attempt_id', - 'AUTHORISATIONID' => 'authorization_id', - 'BANKACCOUNTNUMBER' => 'bank_account_number', - 'BANKAGENZIA' => 'bank_agenzia', - 'BANKCHECKDIGIT' => 'bank_check_digit', - 'BANKCODE' => 'bank_code', - 'BANKFILIALE' => 'bank_filiale', - 'BANKNAME' => 'bank_name', - 'BRANCHCODE' => 'branch_code', - 'COUNTRYCODEBANK' => 'country_code_bank', - 'COUNTRYDESCRIPTION' => 'country_description', - 'CUSTOMERBANKCITY' => 'customer_bank_city', - 'CUSTOMERBANKSTREET' => 'customer_bank_street', - 'CUSTOMERBANKNUMBER' => 'customer_bank_number', - 'CUSTOMERBANKZIP' => 'customer_bank_zip', - 'DATECOLLECT' => 'date_collect', - 'DESCRIPTOR' => 'descriptor', - 'DIRECTDEBITTEXT' => 'direct_debit_text', - 'DOMICILIO' => 'domicilio', - 'EFFORTID' => 'effort_id', - 'IBAN' => 'iban', - 'IPADDRESSCUSTOMER' => 'user_ip', - 'PAYMENTREFERENCE' => 'payment_reference', - 'PROVINCIA' => 'provincia', - 'SPECIALID' => 'special_id', - 'SWIFTCODE' => 'swift_code', - 'TRANSACTIONTYPE' => 'transaction_type', - 'FISCALNUMBER' => 'fiscal_number', - ); - - $this->assertEquals( $var_map, $gateway->getVarMap() ); - } - - public function testLanguageStaging() { - $options = $this->getDonorTestData( 'NO' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $gateway->_stageData(); - - $this->assertEquals( $gateway->_getData_Staged( 'language' ), 'no', "'NO' donor's language was inproperly set. Should be 'no'" ); - } - - public function testLanguageFallbackStaging() { - $options = $this->getDonorTestData( 'Catalonia' ); - $options['payment_method'] = 'cc'; - $options['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $options ); - - $gateway->_stageData(); - - // Requesting the fallback language from the gateway. - $this->assertEquals( 'en', $gateway->_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'. - $gateway->_stageData(); - - $ctid = mt_rand(); - - $gateway->addResponseData( array( - 'contribution_tracking_id' => $ctid . '.1', - ) ); - - // Desired vars were written into normalized data. - $this->assertEquals( $ctid, $gateway->getDonationData()->getVal_Escaped( 'contribution_tracking_id' ) ); - - // Language was not overwritten. - $this->assertEquals( 'ca', $gateway->getDonationData()->getVal_Escaped( 'language' ) ); - } - - /** - * Tests to make sure that certain error codes returned from GC will or - * will not create payments error loglines. - */ - function testCCLogsOnGatewayError() { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - - //this should not throw any payments errors: Just an invalid card. - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '430285' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $this->verifyNoLogErrors(); - - //Now test one we want to throw a payments error - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '21000050' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $loglines = $this->getLogMatches( LogLevel::ERROR, '/Investigation required!/' ); - $this->assertNotEmpty( $loglines, 'GC Error 21000050 is not generating the expected payments log error' ); - - //Reset logs - $this->testLogger->messages = array(); - - //Most irritating version of 20001000 - They failed to enter an expiration date on GC's form. This should log some specific info, but not an error. - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '20001000-expiry' ); - $gateway->do_transaction( 'GET_ORDERSTATUS' ); - $this->verifyNoLogErrors(); - $loglines = $this->getLogMatches( LogLevel::INFO, '/processResponse:.*EXPIRYDATE/' ); - $this->assertNotEmpty( $loglines, 'GC Error 20001000-expiry is not generating the expected payments log line' ); - } - - /** - * Tests to make sure that certain error codes returned from GC will - * trigger order cancellation, even if retryable errors also exist. - * @dataProvider mcNoRetryCodeProvider - */ - public function testNoMastercardFinesForRepeatOnBadCodes( $code ) { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - //Make it not look like an orphan - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ), false ) ); - - //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!" ); - $this->assertEquals( 1, count( $gateway->limbo_stomps ), "Gateway sent no limbostomps for code $code! Should have sent an antimessage!" ); - $this->assertEquals( true, $gateway->limbo_stomps[0], "Gateway sent wrong stomp message for code $code! Should have sent an antimessage!" ); - } - - /** - * 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->setMwGlobals( 'wgRequest', - new FauxRequest( array( - 'action'=>'donate', - 'amount'=>'3.00', - 'card_type'=>'amex', - 'city'=>'Hollywood', - 'contribution_tracking_id'=>'22901382', - 'country'=>'US', - 'currency_code'=>'USD', - 'emailAdd'=>'[email protected]', - 'fname'=>'Fakety', - 'format'=>'json', - 'gateway'=>'globalcollect', - 'language'=>'en', - 'lname'=>'Fake', - 'payment_method'=>'cc', - 'referrer'=>'http://en.wikipedia.org/wiki/Main_Page', - 'state'=>'MA', - 'street'=>'99 Fake St', - 'utm_campaign'=>'C14_en5C_dec_dsk_FR', - 'utm_medium'=>'sitenotice', - 'utm_source'=>'B14_120921_5C_lg_fnt_sans.no-LP.cc', - 'zip'=>'90210' - ), false ) ); - - $gateway = new TestingGlobalCollectAdapter( array( 'api_request' => 'true' ) ); - $gateway->setDummyGatewayResponseCode( 'Exception' ); - try { - $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - } - catch ( Exception $e ) { - // totally expected this - } - $first = $gateway->curled[0]; - //simulate another request coming in before we get anything back from GC - $anotherGateway = new TestingGlobalCollectAdapter( array( 'api_request' => 'true' ) ); - $anotherGateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - $second = $anotherGateway->curled[0]; - $this->assertFalse( $first == $second, 'Two calls to the api did the same thing'); - } - - /** - * Tests to see that we don't claim we're going to retry when we aren't - * going to. For GC, we really only want to retry on code 300620 - * @dataProvider benignNoRetryCodeProvider - */ - public function testNoClaimRetryOnBoringCodes( $code ) { - $init = $this->getDonorTestData( 'US' ); - unset( $init['order_id'] ); - $init['ffname'] = 'cc-vmad'; - //Make it not look like an orphan - $this->setMwGlobals( 'wgRequest', - new FauxRequest( array( - 'CVVRESULT' => 'M', - 'AVSRESULT' => '0' - ), false ) ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); - $start_id = $gateway->_getData_Staged( 'order_id' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $finish_id = $gateway->_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 "); - } -} ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") diff --git a/tests/DonationInterfaceTestCase.php b/tests/DonationInterfaceTestCase.php deleted file mode 100644 index f7815cf..0000000 --- a/tests/DonationInterfaceTestCase.php +++ /dev/null @@ -1,649 +0,0 @@ -<<<<<<< HEAD (b4626c Update vendor submodule) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * @group Fundraising - * @group QueueHandling - * @group ClassMethod - * @group ListenerAdapter - * - * @category UnitTesting - * @package Fundraising_QueueHandling - */ -abstract class DonationInterfaceTestCase extends MediaWikiTestCase { - protected $backupGlobalsBlacklist = array( - 'wgHooks', - ); - - /** - * Returns an array of the vars we expect to be set before people hit payments. - * @var array - */ - public $initial_vars = array ( - 'ffname' => 'testytest', - 'referrer' => 'www.yourmom.com', //please don't go there. - 'currency_code' => 'USD', - ); - - /** - * This will be set by a test method with the adapter object. - * - * @var GatewayAdapter $gatewayAdapter - */ - protected $gatewayAdapter; - - /** - * @var TestingDonationLogger - */ - protected $testLogger; - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - - //Just in case you got here without running the configuration... - global $wgDonationInterfaceTestMode; - $wgDonationInterfaceTestMode = true; - - $adapterclass = TESTS_ADAPTER_DEFAULT; - $this->testAdapterClass = $adapterclass; - - parent::__construct( $name, $data, $dataName ); - } - - protected function setUp() { - $this->testLogger = new TestingDonationLogger(); - DonationLoggerFactory::$overrideLogger = $this->testLogger; - parent::setUp(); - } - - protected function tearDown() { - $this->resetAllEnv(); - DonationLoggerFactory::$overrideLogger = null; - parent::tearDown(); - } - - /** - * 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->gatewayAdapter = $this->getFreshGatewayObject( $options ); - - $this->gatewayAdapter->setCurrentTransaction('INSERT_ORDERWITHPAYMENT'); - - $request = trim( $this->gatewayAdapter->_buildRequestXML() ); - - $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 MWException when there is no data available for the requested country - */ - public function getDonorTestData( $country = '' ) { - $donortestdata = array ( - 'US' => array ( //default - 'city' => 'San Francisco', - 'state' => 'CA', - 'zip' => '94105', - 'currency_code' => 'USD', - 'street' => '123 Fake Street', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - ), - 'ES' => array ( - 'city' => 'Barcelona', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Calle Fake', - 'fname' => 'Nombre', - 'lname' => 'Apellido', - 'amount' => '1.55', - 'language' => 'es', - ), - 'Catalonia' => array ( - 'city' => 'Barcelona', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Calle Fake', - 'fname' => 'Nombre', - 'lname' => 'Apellido', - 'amount' => '1.55', - 'language' => 'ca', - ), - 'NO' => array ( - 'city' => 'Oslo', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Fake Gate', - 'fname' => 'Fornavn', - 'lname' => 'Etternavn', - 'amount' => '1.55', - 'language' => 'no', - ), - 'FR' => array ( - 'city' => 'Versailles', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Rue Faux', - 'fname' => 'Prénom', - 'lname' => 'Nom', - 'amount' => '1.55', - 'language' => 'fr', - ), - // Fiji is configured as a snowflake to test special treatment for certain store IDs - 'FJ' => array ( - 'city' => 'Suva', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 Fake Street', - 'fname' => 'FirstName', - 'lname' => 'LastName', - 'amount' => '1.55', - 'language' => 'en', - ), - 'NL' => array ( - 'city' => 'Amsterdam', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 nep straat', - 'fname' => 'Voornaam', - 'lname' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'BE' => array ( - 'city' => 'Antwerp', - 'state' => 'XX', - 'zip' => '0', - 'currency_code' => 'EUR', - 'street' => '123 nep straat', - 'fname' => 'Voornaam', - 'lname' => 'Achternaam', - 'amount' => '1.55', - 'language' => 'nl', - ), - 'IT' => array ( - 'city' => 'Torino', - 'state' => 'TO', - 'zip' => '10123', - 'currency_code' => 'EUR', - 'street' => 'Via Falso 123', - 'fname' => 'Nome', - 'lname' => 'Cognome', - 'amount' => '1.55', - 'language' => 'it', - ), - 'CA' => array ( - 'city' => 'Saskatoon', - 'state' => 'SK', - 'zip' => 'S7K 0J5', - 'currency_code' => 'CAD', - 'street' => '123 Fake Street', - 'fname' => 'Firstname', - 'lname' => 'Surname', - 'amount' => '1.55', - 'language' => 'en', - ), - 'BR' => array ( - 'city' => 'São Paulo', - 'state' => 'SP', - 'zip' => '01110-111', - 'currency_code' => 'BRL', - 'fiscal_number' => '00003456789', - 'bank_code' => 'TE', - 'street' => 'Rua Falso 123', - 'fname' => 'Nome', - 'lname' => 'Apelido', - 'amount' => '100', - 'language' => 'pt', - ), - ); - //default to US - if ( $country === '' ) { - $country = 'US'; - } - - if ( array_key_exists( $country, $donortestdata ) ) { - $donortestdata = array_merge( $this->initial_vars, $donortestdata[$country] ); - $donortestdata['country'] = $country; - return $donortestdata; - } - throw new MWException( __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 $wgRequest, $wgServer, $wgArticlePath, $wgDonationInterfaceThankYouPage; - - $orderId = $this->gatewayAdapter->getData_Unstaged_Escaped( 'order_id' ); - $merchantref = $this->gatewayAdapter->_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>' . $this->gatewayAdapter->getGlobal( 'MerchantID' ) . '</MERCHANTID>'; - - if ( isset( $wgRequest ) ) { - $expected .= '<IPADDRESS>' . $wgRequest->getIP() . '</IPADDRESS>'; - } - - $expected .= '<VERSION>1.0</VERSION>'; - $expected .= '</META>'; - $expected .= '<PARAMS>'; - $expected .= '<ORDER>'; - $expected .= '<ORDERID>' . $orderId . '</ORDERID>'; - $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>'; - $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>'; - $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>'; - $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>'; - $expected .= '<MERCHANTREFERENCE>' . $merchantref . '</MERCHANTREFERENCE>'; - - if ( isset( $wgRequest ) ) { - $expected .= '<IPADDRESSCUSTOMER>' . $wgRequest->getIP() . '</IPADDRESSCUSTOMER>'; - } - - $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>'; - $expected .= '</ORDER>'; - $expected .= '<PAYMENT>'; - $expected .= '<PAYMENTPRODUCTID>' . $optionsForTestData['payment_product_id'] . '</PAYMENTPRODUCTID>'; - $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>'; - $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>'; - $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>'; - $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>'; - $expected .= '<HOSTEDINDICATOR>1</HOSTEDINDICATOR>'; - $expected .= '<RETURNURL>' . $wgDonationInterfaceThankYouPage . '/' . $options['language'] . '</RETURNURL>'; - $expected .= '<AUTHENTICATIONINDICATOR>0</AUTHENTICATIONINDICATOR>'; - $expected .= '<FIRSTNAME>' . $options['fname'] . '</FIRSTNAME>'; - $expected .= '<SURNAME>' . $options['lname'] . '</SURNAME>'; - $expected .= '<STREET>' . $options['street'] . '</STREET>'; - $expected .= '<CITY>' . $options['city'] . '</CITY>'; - $expected .= '<STATE>' . $options['state'] . '</STATE>'; - $expected .= '<ZIP>' . $options['zip'] . '</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 .= '<DATECOLLECT>' . gmdate( 'Ymd' ) . '</DATECOLLECT>'; //is this cheating? Probably. - $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 .= '<DIRECTDEBITTEXT>' . $optionsForTestData['direct_debit_text'] . '</DIRECTDEBITTEXT>'; - } - - $expected .= '</PAYMENT>'; - $expected .= '</PARAMS>'; - $expected .= '</REQUEST>'; - $expected .= '</XML>'; - - return $expected; - - } - - /** - * Get a fresh gateway object of the type specified in the variable - * $this->testAdapterClass. - * @param array $external_data If you want to shoehorn in some external - * data, do that here. - * @param array $setup_hacks An array of things that override stuff in - * the constructor of the gateway object that I can't get to without - * refactoring the whole thing. @TODO: Refactor the gateway adapter - * constructor. - * @return GatewayAdapter The new relevant gateway adapter object. - */ - function getFreshGatewayObject( $external_data = null, $setup_hacks = array() ) { - $p1 = null; - if ( !is_null( $external_data ) ) { - $p1 = array ( - 'external_data' => $external_data, - ); - } - - if ( $setup_hacks ) { - if ( !is_null( $p1 ) ) { - $p1 = array_merge( $p1, $setup_hacks ); - } else { - $p1 = $setup_hacks; - } - } - - $class = $this->testAdapterClass; - $gateway = new $class( $p1 ); - - // 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 ) { - $gateway->$field = $value; - } - - return $gateway; - } - - function resetAllEnv() { - $_SESSION = array ( ); - $_GET = array ( ); - $_POST = array ( ); - - $_SERVER = array ( ); - $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; - $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; - $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; - $_SERVER['SCRIPT_NAME'] = __FILE__; - } - - /** - * 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 class $special_page_class A testing descendant of GatewayPage - * @param array $initial_vars Array that will be loaded straight into a - * test version of $wgRequest. - * @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. - */ - function verifyFormOutput( $special_page_class, $initial_vars, $perform_these_checks, $fail_on_log_errors = false ) { - // Nasty hack to clear output from any previous tests. - $mainContext = RequestContext::getMain(); - $newOutput = new OutputPage( $mainContext ); - $newRequest = new TestingRequest( $initial_vars, false ); - $mainContext->setRequest( $newRequest ); - $mainContext->setOutput( $newOutput ); - - $globals = array ( - 'wgRequest' => $newRequest, - 'wgTitle' => Title::newFromText( 'nonsense is apparently fine' ), - 'wgOut' => $newOutput, - ); - - $this->setMwGlobals( $globals ); - - $this->setLanguage( $initial_vars['language'] ); - - ob_start(); - $formpage = new $special_page_class(); - $formpage->execute( NULL ); - $formpage->getOutput()->output(); - $form_html = ob_get_contents(); - ob_end_clean(); - - // In the event that something goes crazy, uncomment the next line for much easier local debugging - // file_put_contents( '/tmp/xmlout.txt', $form_html ); - - if ( $fail_on_log_errors ) { - $this->verifyNoLogErrors(); - } - - $dom_thingy = new DomDocument(); - //// DEBUGGING, foo - // if (property_exists($this, 'FOO')) { - // error_log(var_export($formpage->getRequest()->response()->getheader('Location'), true)); - // error_log(var_export($form_html, true)); - // } - - if ( $form_html ) { - // p.s. i'm SERIOUS about the character encoding. - $dom_thingy->loadHTML( '<?xml encoding="UTF-8">' . $form_html ); - $dom_thingy->encoding = 'UTF-8'; - } - - foreach ( $perform_these_checks as $id => $checks ) { - if ( $id == 'headers' ) { - foreach ( $checks as $name => $expected ) { - $actual = $formpage->getRequest()->response()->getheader( $name ); - $this->performCheck( $actual, $expected, "header '$name'"); - break; - } - continue; - } - unset( $perform_these_checks['headers'] ); - - $input_node = $dom_thingy->getElementById( $id ); - $this->assertNotNull( $input_node, "Couldn't find the '$id' element" ); - foreach ( $checks as $name => $expected ) { - switch ( $name ) { - case 'nodename': - $this->performCheck( $input_node->nodeName, $expected, "name of node with id '$id'"); - break; - case 'innerhtml': - $actual_html = self::getInnerHTML( $input_node ); - // Strip comments - $actual_html = preg_replace( '/<!--[^>]*-->/', '', $actual_html ); - $this->performCheck( $actual_html, $expected, "innerHTML of node '$id'"); - break; - case 'innerhtmlmatches': - $this->assertEquals( 1, preg_match( $expected, self::getInnerHTML( $input_node ) ), "Value of the node with id '$id' does not match pattern '$expected'. It has value " . self::getInnerHTML( $input_node ) ); - break; - case 'value': - $this->performCheck( $input_node->getAttribute('value'), $expected, "value of node with id '$id'"); - break; - case 'selected': - $selected = null; - if ( $input_node->nodeName === 'select' ) { - $options = $input_node->getElementsByTagName( 'option' ); - foreach ( $options as $option ) { - if ( $option->hasAttribute( 'selected' ) ) { - $selected = $option->getAttribute( 'value' ); - break; - } - } - $this->performCheck( $selected, $expected, "selected option value of node with id '$id'"); - } else { - $this->fail( "Attempted to test for selected value on non-select node, id '$id'" ); - } - break; - } - } - } - - // Are there untranslated boogers? - if ( preg_match_all( '/<[^<]+(>|>)/', $form_html, $matches ) ) { - $this->fail( 'Untranslated messages present: ' . implode( ', ', $matches[0] ) ); - } - - //because do_transaction is totally expected to leave session artifacts... -// $wgRequest = new FauxRequest(); - } - - /** - * Performs some sort of assertion on a value. - * - * @param string $value the value to test - * @param string|callable $check - * if $check is callable, it is called with argument $value - * otherwise, $value is asserted to be equal to $check - * @param string $label identifies the value in assertion failures - * @return void - */ - function performCheck( $value, $check, $label = 'Tested value' ) { - if ( is_callable( $check ) ) { - $check( $value ); - return; - } - $this->assertEquals( $check, $value, "Expected $label to be $check, found $value instead."); - } - /** - * Asserts that there are no log entries of LOG_ERR or worse. - */ - function verifyNoLogErrors( ) { - $log = $this->testLogger->messages; - - $this->assertTrue( is_array( $log ), "Missing the test log" ); - - //for our purposes, an "error" is LOG_ERR or less. - $checklogs = array ( - LogLevel::ERROR => "Oops: We've got LOG_ERRors.", - LogLevel::CRITICAL => "Critical errors!", - LogLevel::ALERT => "Log Alerts!", - LogLevel::EMERGENCY => "Logs says the servers are actually on fire.", - ); - - $message = false; - foreach ( $checklogs as $level => $levelmessage ) { - if ( array_key_exists( $level, $log ) ) { - $message = $levelmessage . ' ' . print_r( $log[$level], true ) . "\n"; - } - } - - $this->assertFalse( $message, $message ); //ha - } - - /** - * Finds a relevant line/lines in a gateway's log array - * @param string $log_level One of the constants in \Psr\Log\LogLevel - * @param string $match A regex to match against the log lines. - * @return array All log lines that match $match. - */ - public function getLogMatches( $log_level, $match ) { - $log = $this->testLogger->messages; - if ( !array_key_exists( $log_level, $log ) ) { - return false; - } - $return = array ( ); - foreach ( $log[$log_level] as $line ) { - if ( preg_match( $match, $line ) ) { - $return[] = $line; - } - } - return $return; - } - - /** - * Set global language for the duration of the test - * - * @param string $language language code to force - */ - protected function setLanguage( $language ) { - $newLang = new TestingLanguage(); - //this should be more robust, but... might have to work for now. - $newLang->forceLang( $language ); - - $this->setMwGlobals( array ( - 'wgLang' => $newLang, - ) ); - } - - static function getInnerHTML( $node ) { - $innerHTML = ''; - $children = $node->childNodes; - foreach ( $children as $child ) { - $innerHTML .= $child->ownerDocument->saveXML( $child ); - } - return $innerHTML; - } -} ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") diff --git a/tests/HandlebarsFormTest.php b/tests/HandlebarsFormTest.php deleted file mode 100644 index 691c2a2..0000000 --- a/tests/HandlebarsFormTest.php +++ /dev/null @@ -1,75 +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 GatewayPage - */ -class MustacheFormTest extends DonationInterfaceTestCase { - protected $form; - protected $adapter; - - public function setUp() { - $this->adapter = new TestingGenericAdapter(); - $this->adapter->addRequestData( array( - 'amount' => '12', - 'currency_code' => 'EUR' - ) ); - - parent::setUp(); - } - - public function formCases() { - return array( - array( 'empty', '/^$/' ), - array( 'foo', '/FOO/' ), - array( 'currency', '/EUR/' ), - ); - } - - /** - * Render a few simple Mustache files and match the output - * - * @dataProvider formCases - */ - public function testRendering( $name, $regexp ) { - $this->setMwGlobals( array( - 'wgDonationInterfaceTemplate' => __DIR__ . "/data/mustache/{$name}.mustache", - ) ); - $this->form = new Gateway_Form_Mustache( $this->adapter ); - $html = $this->form->getForm(); - - $this->assertRegExp( $regexp, $html ); - } - - /** - * @expectedException Exception - * @expectedExceptionMessage Template file unavailable - */ - public function testNoTemplateFile() { - $this->setMwGlobals( array( - 'wgDonationInterfaceTemplate' => __DIR__ . "/data/mustache/DONOTCREATE.mustache", - ) ); - $this->form = new Gateway_Form_Mustache( $this->adapter ); - // Suppress the error cos: we know. - $html = @$this->form->getForm(); - - $this->fail( 'I\'m not dead yet!' ); - } -} diff --git a/tests/TestConfiguration.php b/tests/TestConfiguration.php deleted file mode 100644 index 8de0e9e..0000000 --- a/tests/TestConfiguration.php +++ /dev/null @@ -1,181 +0,0 @@ -<<<<<<< HEAD (b4626c Update vendor submodule) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This file contains custom options and constants for test configuration. - */ - -/** - * TESTS_MESSAGE_NOT_IMPLEMENTED - * - * Message for code that has not been implemented. - */ -define( 'TESTS_MESSAGE_NOT_IMPLEMENTED', 'Not implemented yet!' ); - -/** - * TESTS_HOSTNAME - * - * The hostname for the system - */ -define( 'TESTS_HOSTNAME', 'localhost' ); - -/** - * TESTS_EMAIL - * - * An email address to use in case test send mail - */ -define( 'TESTS_EMAIL', '[email protected]' ); - -/** - * TESTS_GATEWAY_DEFAULT - * - * This is the default gateway that will be used to implement unit tests. - */ -define( 'TESTS_GATEWAY_DEFAULT', 'GlobalCollectGateway' ); - -/** - * TESTS_ADAPTER_DEFAULT - * - * This is the default adapter that will be used to implement unit tests. - */ -define( 'TESTS_ADAPTER_DEFAULT', 'TestingGlobalCollectAdapter' ); - -global $wgDonationInterfaceTestMode, - $wgDonationInterfaceMerchantID, - $wgDonationInterfaceAllowedHtmlForms, - $wgDonationInterfaceThankYouPage, - $wgGlobalCollectGatewayAccountInfo, - $wgPaypalGatewayAccountInfo, - $wgPaypalGatewayReturnURL, - $wgAmazonGatewayReturnURL, - $wgAmazonGatewayAccountInfo, - $wgAdyenGatewayBaseURL, - $wgAdyenGatewayAccountInfo, - $wgAstropayGatewayURL, - $wgAstropayGatewayTestingURL, - $wgAstropayGatewayAccountInfo, - $wgWorldPayGatewayAccountInfo, - $wgWorldPayGatewayURL, - $wgMinFraudLicenseKey, - $wgMinFraudTimeout, - $wgDonationInterfaceMinFraudServers, - $wgDonationInterfaceEnableMinfraud, - $wgDonationInterfaceEnableFunctionsFilter, - $wgDonationInterfaceEnableReferrerFilter, - $wgDonationInterfaceEnableSourceFilter; - -/** - * Make sure the test setup is used, else we'll have the wrong classes. - */ -/** DonationInterface General Settings **/ -$wgDonationInterfaceTestMode = true; -$wgDonationInterfaceMerchantID = 'test'; - -$wgDonationInterfaceAllowedHtmlForms = array( - 'test' => array( - ), -); - -$wgDonationInterfaceThankYouPage = 'https://wikimediafoundation.org/wiki/Thank_You'; - - -/** GlobalCollect **/ -$wgGlobalCollectGatewayAccountInfo = array ( ); -$wgGlobalCollectGatewayAccountInfo['test'] = array ( - 'MerchantID' => 'test', -); - - -/** Paypal **/ -$wgPaypalGatewayAccountInfo = array ( ); -$wgPaypalGatewayAccountInfo['testing'] = array ( - 'AccountEmail' => '[email protected]', -); -$wgPaypalGatewayReturnURL = 'http://donate.wikimedia.org'; //whatever, doesn't matter. - - -/** Amazon **/ -$wgAmazonGatewayReturnURL = 'https://payments.wikimedia.org/index.php/Special:AmazonGateway'; -$wgAmazonGatewayAccountInfo['test'] = array ( - 'AccessKey' => 'testkey', - 'SecretKey' => 'testsecret', - 'PaymentsAccountID' => 'testaccountid', - 'IpnOverride' => 'https://test.wikimedia.org/amazon', -); - -/** Adyen **/ -$wgAdyenGatewayBaseURL = 'https://testorwhatever.adyen.com'; -$wgAdyenGatewayAccountInfo['test'] = array ( - 'AccountName' => 'wikitest', - 'SharedSecret' => 'long-cat-is-long', - 'SkinCode' => 'testskin', -); - -/** Astropay **/ -$wgAstropayGatewayURL = 'https://astropay.example.com/'; -$wgAstropayGatewayTestingURL = 'https://sandbox.astropay.example.com/'; -$wgAstropayGatewayAccountInfo['test'] = array ( - 'Create' => array( - 'Login' => 'createlogin', - 'Password' => 'createpass', - ), - 'Status' => array( - 'Login' => 'statuslogin', - 'Password' => 'statuspass', - ), - 'SecretKey' => 'NanananananananananananananananaBatman', -); - -/** WorldPay **/ -$wgWorldPayGatewayAccountInfo['test'] = array ( - 'Username' => 'testname', - 'Password' => 'testpass', - 'MerchantId' => '123456', - 'Test' => true, - 'TokenizingMerchantID' => '123456', - 'StoreIDs' => array ( - '*/FJ/EUR' => array( 123456, 'fj_store_id' ), - '*/*/EUR' => array( 123456, 'eur_store_id' ), - '*/*/USD' => array( 123456, 'usd_store_id' ), - ), - 'MerchantIDs' => array( - 123456 => array( - 'Username' => 'testname2', - 'Password' => 'testpass2', - ), - ), - // Test special treatment - allow 'fail' CVV and missing AVS nodes - 'SpecialSnowflakeStoreIDs' => array( - 'fj_store_id', - ), -); -$wgWorldPayGatewayURL = 'https://test.worldpay.com'; - -$wgMinFraudLicenseKey = 'testkey'; -$wgMinFraudTimeout = 1; -$wgDonationInterfaceMinFraudServers = array ( "minfraud.wikimedia.org" ); - -//still can't quite handle mindfraud by itself yet, so default like this. -//I will turn it on for individual tests in which I want to verify that it at -//least fails closed when enabled. -$wgDonationInterfaceEnableMinfraud = false; - -//...but we want these. -$wgDonationInterfaceEnableFunctionsFilter = true; -$wgDonationInterfaceEnableReferrerFilter = true; -$wgDonationInterfaceEnableSourceFilter = true; ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") diff --git a/tests/data/mustache/currency.mustache b/tests/data/mustache/currency.mustache deleted file mode 100644 index cb58a8a..0000000 --- a/tests/data/mustache/currency.mustache +++ /dev/null @@ -1 +0,0 @@ -{{ currency_code }} diff --git a/tests/data/mustache/empty.mustache b/tests/data/mustache/empty.mustache deleted file mode 100644 index e69de29..0000000 --- a/tests/data/mustache/empty.mustache +++ /dev/null diff --git a/tests/data/mustache/foo.mustache b/tests/data/mustache/foo.mustache deleted file mode 100644 index b7d6715..0000000 --- a/tests/data/mustache/foo.mustache +++ /dev/null @@ -1 +0,0 @@ -FOO diff --git a/tests/includes/Responses/astropay/NewInvoice.testresponse b/tests/includes/Responses/astropay/NewInvoice.testresponse deleted file mode 100644 index bd8a369..0000000 --- a/tests/includes/Responses/astropay/NewInvoice.testresponse +++ /dev/null @@ -1,10 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 106 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"0","link":"https:\/\/sandbox.astropaycard.com\/go_to_bank?id=A5jvKfK1iHIRUTPXXt8lDFGaRRLzPgBg"} - diff --git a/tests/includes/Responses/astropay/NewInvoice_1.testresponse b/tests/includes/Responses/astropay/NewInvoice_1.testresponse deleted file mode 100644 index 0274011..0000000 --- a/tests/includes/Responses/astropay/NewInvoice_1.testresponse +++ /dev/null @@ -1,10 +0,0 @@ -HTTP/1.1 200 OK -Server: nginx/1.7.9 -Date: Wed, 08 Apr 2015 00:19:52 GMT -Content-Type: application/json; charset=UTF-8 -Content-Length: 106 -Connection: keep-alive -X-Powered-By: PHP/5.3.27 - -{"status":"1","desc":"This error message should appear in the log."} - diff --git a/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_800.testresponse b/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_800.testresponse deleted file mode 100644 index 72f0695..0000000 --- a/tests/includes/Responses/globalcollect/GET_ORDERSTATUS_800.testresponse +++ /dev/null @@ -1,41 +0,0 @@ -<XML> - <REQUEST> - <ACTION>GET_ORDERSTATUS</ACTION> - <META> - <MERCHANTID>1</MERCHANTID> - <IPADDRESS>123.123.123.123</IPADDRESS> - <VERSION>2.0</VERSION> - <REQUESTIPADDRESS>123.123.123.123</REQUESTIPADDRESS> - </META> - <PARAMS> - <ORDER> - <ORDERID>9998890004</ORDERID> - </ORDER> - </PARAMS> - <RESPONSE> - <RESULT>OK</RESULT> - <META> - <REQUESTID>245</REQUESTID> - <RESPONSEDATETIME>20100419133351</RESPONSEDATETIME> - </META> - <STATUS> - <PAYMENTMETHODID>1</PAYMENTMETHODID> - <STATUSID>800</STATUSID> - <CURRENCYCODE>EUR</CURRENCYCODE> - <FRAUDRESULT>N</FRAUDRESULT> - <EFFORTID>1</EFFORTID> - <CREDITCARDNUMBER>************7977</CREDITCARDNUMBER> - <AUTHORISATIONCODE>654321</AUTHORISATIONCODE> - <PAYMENTREFERENCE>900100000010</PAYMENTREFERENCE> - <ATTEMPTID>2</ATTEMPTID> - <MERCHANTID>1</MERCHANTID> - <AMOUNT>2345</AMOUNT> - <STATUSDATE>20100419132926</STATUSDATE> - <PAYMENTPRODUCTID>1</PAYMENTPRODUCTID> - <CVVRESULT> </CVVRESULT> - <ORDERID>9998890004</ORDERID> - <EXPIRYDATE>1210</EXPIRYDATE> - </STATUS> - </RESPONSE> - </REQUEST> -</XML> diff --git a/tests/includes/test_gateway/TestingAstropayAdapter.php b/tests/includes/test_gateway/TestingAstropayAdapter.php deleted file mode 100644 index 54ba9eb..0000000 --- a/tests/includes/test_gateway/TestingAstropayAdapter.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/** - * TestingAstropayAdapter - * - * TODO: Add dependency injection to the base class so we don't have to repeat - * code (or this comment) here. - */ -class TestingAstropayAdapter extends AstropayAdapter { - - public $curled = array(); - - /** - * Clear the static globals cache. - */ - public static function clearGlobalsCache() { - self::$globalsCache = array(); - } - - /** - * Set the error code you want the dummy response to return - */ - public function setDummyGatewayResponseCode( $code ) { - $this->dummyGatewayResponseCode = $code; - } - - /** - * Set the error code you want the dummy response to return - */ - public function setDummyCurlResponseCode( $code ) { - $this->dummyCurlResponseCode = $code; - } - - protected function curl_transaction( $data ) { - $this->curled[] = $data; - return parent::curl_transaction( $data ); - } - - /** - * Load in some dummy response JSON so we can test proper response processing - */ - protected function curl_exec( $ch ) { - $code = ''; - if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) { - $code = '_' . $this->dummyGatewayResponseCode; - if ( $this->dummyGatewayResponseCode === 'Exception' ) { - throw new Exception( 'blah!' ); - } - } - - //could start stashing these in a further-down subdir if payment type starts getting in the way, - //but frankly I don't want to write tests that test our dummy responses. - $file_path = dirname( __FILE__ ) - . '/../Responses/' - . self::getIdentifier() - . '/' - . $this->getCurrentTransaction() - . $code - . '.testresponse'; - - //these are all going to be short, so... - if ( file_exists( $file_path ) ) { - return file_get_contents( $file_path ); - } else { - throw new Exception( "File $file_path does not exist.\n" ); - } - } - - /** - * Load in some dummy curl response info so we can test proper response processing - */ - protected function curl_getinfo( $ch, $opt = null ) { - $code = 200; //response OK - if ( property_exists( $this, 'dummyCurlResponseCode' ) ) { - $code = ( int ) $this->dummyCurlResponseCode; - } - - //put more here if it ever turns out that we care about it. - return array ( - 'http_code' => $code, - ); - } -} diff --git a/tests/includes/test_gateway/TestingGenericAdapter.php b/tests/includes/test_gateway/TestingGenericAdapter.php deleted file mode 100644 index f27ca7c..0000000 --- a/tests/includes/test_gateway/TestingGenericAdapter.php +++ /dev/null @@ -1,112 +0,0 @@ -<<<<<<< HEAD (b4626c Update vendor submodule) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * A really dumb adapter. - */ -class TestingGenericAdapter extends GatewayAdapter { - - /** - * A list of fake errors that is returned each time revalidate() is called. - */ - public $errorsForRevalidate = array(); - - public $revalidateCount = 0; - public static $fakeGlobals = array(); - - public static $acceptedCurrencies = array(); - - public function getCommunicationType() { - return 'xml'; - } - - public function revalidate($check_not_empty = array()) { - if ( $this->errorsForRevalidate ) { - $fakeErrors = $this->errorsForRevalidate[$this->revalidateCount]; - if ( $fakeErrors !== null ) { - $this->revalidateCount++; - $this->setValidationErrors( $fakeErrors ); - return empty( $fakeErrors ); - } - } - return parent::revalidate($check_not_empty); - } - - public function normalizeOrderID( $override = null, $dataObj = null ) { - return '12345'; - } - - public static function getGlobal( $name ) { - if ( array_key_exists( $name, TestingGenericAdapter::$fakeGlobals ) ) { - return TestingGenericAdapter::$fakeGlobals[$name]; - } - return parent::getGlobal( $name ); - } - - public function defineAccountInfo() { - } - - public function defineDataConstraints() { - } - - public function defineErrorMap() { - } - - public function defineOrderIDMeta() { - } - - public function definePaymentMethods() { - } - - public function defineReturnValueMap() { - } - - public function defineStagedVars() { - } - - public function defineTransactions() { - } - - public function defineVarMap() { - } - - public function getResponseData($response) { - } - - public function getResponseErrors($response) { - } - - public function getResponseStatus($response) { - } - - public function processResponse($response, &$retryVars = null) { - } - - public function setGatewayDefaults() { - } - - public static function getCurrencies() { - return TestingGenericAdapter::$acceptedCurrencies; - } - - public function doPayment() { - } -} ->>>>>>> BRANCH (025d1c Merge "Correcting s/handlebars/mustache/") -- To view, visit https://gerrit.wikimedia.org/r/205304 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If957354df55ce0b3d204a4d8d1e527b868efd006 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Awight <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
