Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/362231 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment 9f3e5234 Localisation updates from https://translatewiki.net. e33da29e Localisation updates from https://translatewiki.net. 2fef3053 Localisation updates from https://translatewiki.net. 454c93bd Localisation updates from https://translatewiki.net. afa082a3 Localisation updates from https://translatewiki.net. e6583072 Localisation updates from https://translatewiki.net. 4ad43bec Localisation updates from https://translatewiki.net. b40761d8 Localisation updates from https://translatewiki.net. 91e68fcb Add missing MXN to national currencies list 816267c9 Localisation updates from https://translatewiki.net. 4608b6cb API: Split description messages into summary + additional text b59da31b Localisation updates from https://translatewiki.net. 11710766 Localisation updates from https://translatewiki.net. 19ba3a5a Localisation updates from https://translatewiki.net. 907f4a1d Localisation updates from https://translatewiki.net. 5881436c Delete some unused vars 36f66ae0 Get rid of the rest of the !important modifiers in forms.css 62532af4 Stop masking possible test failure 6d1081a7 Add API test for Amazon bd91024c Consolidate queue message generation. 5bc6b4d2 Get rid of some more php-message-class, WmfFramework::getHostname 6f61d4c8 Guard against missing params in PP-EC return URL 9c673a49 Localisation updates from https://translatewiki.net. 602c836b Revert "Localisation updates from https://translatewiki.net." ad7937f6 Localisation updates from https://translatewiki.net. 7043c54d Use short array syntax in alias file 0bb0c742 Localisation updates from https://translatewiki.net. 4ee900d4 Localisation updates from https://translatewiki.net. Change-Id: Ib652463c4d6b37ebc9a738298950c2f0112091da --- D tests/phpunit/Adapter/Adyen/AdyenTest.php D tests/phpunit/Adapter/Amazon/AmazonApiTest.php D tests/phpunit/Adapter/Amazon/AmazonTest.php D tests/phpunit/Adapter/PayPal/PayPalExpressTest.php D tests/phpunit/DonationQueueTest.php D tests/phpunit/GatewayPageTest.php D tests/phpunit/LoggingTest.php 7 files changed, 0 insertions(+), 1,304 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/31/362231/1 diff --git a/tests/phpunit/Adapter/Adyen/AdyenTest.php b/tests/phpunit/Adapter/Adyen/AdyenTest.php deleted file mode 100644 index 5697312..0000000 --- a/tests/phpunit/Adapter/Adyen/AdyenTest.php +++ /dev/null @@ -1,209 +0,0 @@ -<<<<<<< HEAD (c615ad 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 Wikimedia\TestingAccessWrapper; - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Adyen - */ -class DonationInterface_Adapter_Adyen_Test extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingAdyenAdapter'; - } - - public function setUp() { - parent::setUp(); - DonationInterface::initializeSmashPig( 'adyen' ); - - $this->setMwGlobals( array( - 'wgAdyenGatewayEnabled' => true, - ) ); - } - - /** - * Integration test to verify that the donate transaction works as expected when all necessary data is present. - */ - function testDoTransactionDonate() { - $init = $this->getDonorTestData(); - $init['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'donate' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $ret = $exposed->buildRequestParams(); - - $expected = array ( - 'allowedMethods' => 'card', - 'billingAddress.street' => $init['street_address'], - 'billingAddress.city' => $init['city'], - 'billingAddress.postalCode' => $init['postal_code'], - 'billingAddress.stateOrProvince' => $init['state_province'], - 'billingAddress.country' => $init['country'], - 'billingAddress.houseNumberOrName' => 'NA', - 'billingAddressType' => 2, - 'card.cardHolderName' => $init['first_name'] . ' ' . $init['last_name'], - 'currencyCode' => $init['currency'], - 'merchantAccount' => 'wikitest', - 'merchantReference' => $exposed->getData_Staged( 'order_id' ), - 'merchantSig' => $exposed->getData_Staged( 'hpp_signature' ), - 'paymentAmount' => ($init['amount']) * 100, -// 'sessionValidity' => '2014-03-09T19:41:50+00:00', //commenting out, because this is a problem. -// 'shipBeforeDate' => $exposed->getData_Staged( 'expiration' ), //this too. - 'skinCode' => 'testskin', - 'shopperLocale' => 'en_US', - 'shopperEmail' => 'nob...@wikimedia.org', - 'offset' => '52', //once we construct the FraudFiltersTestCase, it should land here. - ); - - //deal with problem keys. - //@TODO: Refactor gateway so these are more testable - $problems = array ( - 'sessionValidity', - 'shipBeforeDate', - ); - - foreach ( $problems as $oneproblem ) { - if ( isset( $ret[$oneproblem] ) ) { - unset( $ret[$oneproblem] ); - } - } - - $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); - } - - function testRiskScoreAddedToQueueMessage() { - $init = $this->getDonorTestData(); - $init['payment_submethod'] = 'visa'; - $gateway = $this->getFreshGatewayObject( $init ); - - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $exposed->risk_score = 57; - $message = $exposed->getQueueDonationMessage(); - $this->assertEquals( 57, $message['risk_score'], 'Risk score was not correctly added to queue message.' ); - } - - /** - * Make sure language is staged correctly when qs param is uppercase - */ - function testLanguageCaseSensitivity() { - $init = $this->getDonorTestData(); - $init['payment_submethod'] = 'visa'; - $init['language'] = 'FR'; - $gateway = $this->getFreshGatewayObject( $init ); - - $gateway->do_transaction( 'donate' ); - $exposed = TestingAccessWrapper::newFromObject( $gateway ); - $ret = $exposed->buildRequestParams(); - - $expected = array ( - 'allowedMethods' => 'card', - 'billingAddress.street' => $init['street_address'], - 'billingAddress.city' => $init['city'], - 'billingAddress.postalCode' => $init['postal_code'], - 'billingAddress.stateOrProvince' => $init['state_province'], - 'billingAddress.country' => $init['country'], - 'billingAddress.houseNumberOrName' => 'NA', - 'billingAddressType' => 2, - 'card.cardHolderName' => $init['first_name'] . ' ' . $init['last_name'], - 'currencyCode' => $init['currency'], - 'merchantAccount' => 'wikitest', - 'merchantReference' => $exposed->getData_Staged( 'order_id' ), - 'merchantSig' => $exposed->getData_Staged( 'hpp_signature' ), - 'paymentAmount' => ($init['amount']) * 100, - 'skinCode' => 'testskin', - 'shopperLocale' => 'fr_US', - 'shopperEmail' => 'nob...@wikimedia.org', - 'offset' => '52', - ); - - //deal with problem keys. - //@TODO: Refactor gateway so these are more testable - $problems = array ( - 'sessionValidity', - 'shipBeforeDate', - ); - - foreach ( $problems as $oneproblem ) { - if ( isset( $ret[$oneproblem] ) ) { - unset( $ret[$oneproblem] ); - } - } - - $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); - } - - public function testDonorReturnSuccess() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['language'] = 'FR'; - $init['order_id'] = '55555'; - $session['Donor'] = $init; - $this->setUpRequest( $init, $session ); - $gateway = $this->getFreshGatewayObject( array() ); - $result = $gateway->processDonorReturn( array( - 'authResult' => 'AUTHORISED', - 'merchantReference' => '55555.0', - 'merchantSig' => 'o1QTd6X/PYrOgLPoSheamR3osAksh6oTaSytsCcJsFA=', - 'paymentMethod' => 'visa', - 'pspReference' => '123987612346789', - 'shopperLocale' => 'fr_FR', - 'skinCode' => 'testskin', - 'title' => 'Special:AdyenGatewayResult' - ) ); - $this->assertFalse( $result->isFailed() ); - $this->assertEmpty( $result->getErrors() ); - // TODO inspect the queue message - } - - public function testDonorReturnFailure() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['language'] = 'FR'; - $init['order_id'] = '55555'; - $session['Donor'] = $init; - $this->setUpRequest( $init, $session ); - $gateway = $this->getFreshGatewayObject( array() ); - $result = $gateway->processDonorReturn( array( - 'authResult' => 'REFUSED', - 'merchantReference' => '55555.0', - 'merchantSig' => 'EVqAiz4nZ8XQ9Wfbm9bOQYaKPV22qdY+/6va7zAo580=', - 'paymentMethod' => 'visa', - 'pspReference' => '123987612346789', - 'shopperLocale' => 'fr_FR', - 'skinCode' => 'testskin', - 'title' => 'Special:AdyenGatewayResult' - ) ); - $this->assertTrue( $result->isFailed() ); - } -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php deleted file mode 100644 index 04ca56b..0000000 --- a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -/** - * @group Amazon - * @group medium - */ -class AmazonApiTest extends ApiTestCase { - public function setUp() { - parent::setUp(); - TestingAmazonAdapter::$mockClient = new MockAmazonClient(); - $this->setMwGlobals( array( - 'wgDonationInterfaceEnableQueue' => true, - 'wgDonationInterfaceDefaultQueueServer' => array( - 'type' => 'TestingQueue', - ), - ) ); - } - - public function tearDown() { - TestingAmazonAdapter::$mockClient = null; - parent::tearDown(); - } - - public function testDoPaymentSuccess() { - $params = array( - 'amount' => '1.55', - 'currency' => 'USD', - 'recurring' => '0', - 'wmf_token' => 'e601502632e5e51dc2a17a0045162272+\\', - 'orderReferenceId' => mt_rand( 0, 10000000 ), - 'action' => 'di_amazon_bill', - ); - $session = array( - 'Donor' => array( - 'amount' => '1.55', - 'currency' => 'USD', - 'recurring' => '0', - 'contribution_tracking_id' => mt_rand( 0, 10000000 ), - 'country' => 'US', - ), - 'amazonEditToken' => 'kjaskdjahsdkjsad', - ); - $apiResult = $this->doApiRequest( $params, $session ); - $redirect = $apiResult[0]['redirect']; - $this->assertEquals( 'https://wikimediafoundation.org/wiki/Thank_You/en?country=US', $redirect ); - $mockClient = TestingAmazonAdapter::$mockClient; - $setOrderReferenceDetailsArgs = $mockClient->calls['setOrderReferenceDetails'][0]; - $oid = $session['Donor']['contribution_tracking_id'] . '-0'; - $this->assertEquals( $oid, $setOrderReferenceDetailsArgs['seller_order_id'], 'Did not set order id on order reference' ); - $this->assertEquals( $params['amount'], $setOrderReferenceDetailsArgs['amount'], 'Did not set amount on order reference' ); - - $this->assertEquals( $params['currency'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->assertEquals( 'S01-0391295-0674065-C095112', $message['gateway_txn_id'], 'Queue message has wrong txn ID' ); - } -} diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php b/tests/phpunit/Adapter/Amazon/AmazonTest.php deleted file mode 100644 index 2e47bad..0000000 --- a/tests/phpunit/Adapter/Amazon/AmazonTest.php +++ /dev/null @@ -1,295 +0,0 @@ -<<<<<<< HEAD (c615ad Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group Amazon - */ -class DonationInterface_Adapter_Amazon_Test extends DonationInterfaceTestCase { - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - public function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingAmazonAdapter'; - } - - public function setUp() { - parent::setUp(); - DonationInterface::initializeSmashPig( 'amazon' ); - - TestingAmazonAdapter::$mockClient = new MockAmazonClient(); - - $this->setMwGlobals( array( - 'wgAmazonGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'amazon' => array( - 'gateway' => 'amazon', - 'payment_methods' => array('amazon' => 'ALL'), - 'redirect', - ), - 'amazon-recurring' => array( - 'gateway' => 'amazon', - 'payment_methods' => array('amazon' => 'ALL'), - 'redirect', - 'recurring', - ), - ), - ) ); - } - - public function tearDown() { - TestingAmazonAdapter::$fakeGlobals = array(); - parent::tearDown(); - } - - /** - * Integration test to verify that the Amazon gateway converts Canadian - * dollars before redirecting - * - * FIXME: Merge with currency fallback tests? - * - * @dataProvider canadaLanguageProvider - */ - function testCanadianDollarConversion( $language ) { - $init = $this->getDonorTestData( 'CA' ); - unset( $init['order_id'] ); - $init['payment_method'] = 'amazon'; - $init['ffname'] = 'amazon'; - $init['language'] = $language; - $rates = CurrencyRates::getCurrencyRates(); - $cadRate = $rates['CAD']; - - $expectedAmount = floor( $init['amount'] / $cadRate ); - - TestingAmazonAdapter::$fakeGlobals = array( - 'FallbackCurrency' => 'USD', - 'NotifyOnConvert' => true, - ); - - $expectedNotification = wfMessage( - 'donate_interface-fallback-currency-notice', - 'USD' - )->inLanguage( $language )->text(); - - $locale = $init['language'] . '_' . $init['country']; - $expectedDisplayAmount = Amount::format( $expectedAmount, 'USD', $locale ); - - $that = $this; //needed for PHP pre-5.4 - $convertTest = function( $amountString ) use ( $expectedDisplayAmount, $that ) { - $that->assertEquals( $expectedDisplayAmount, trim( $amountString ), 'Displaying wrong amount' ); - }; - - $assertNodes = array( - 'selected-amount' => array( 'innerhtml' => $convertTest ), - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$expectedNotification.*/" - ) - ); - $this->verifyFormOutput( 'AmazonGateway', $init, $assertNodes, false ); - } - - /** - * Integration test to verify that the Amazon gateway shows an error message when validation fails. - */ - function testShowFormOnError() { - $init = $this->getDonorTestData(); - $init['OTT'] = 'SALT123456789'; - $init['amount'] = '-100.00'; - $init['ffname'] = 'amazon'; - $session = array( 'Donor' => $init ); - $errorMessage = wfMessage( 'donate_interface-error-msg-invalid-amount' )->text(); - $assertNodes = array( - 'mw-content-text' => array( - 'innerhtmlmatches' => "/.*$errorMessage.*/" - ) - ); - - $this->verifyFormOutput( 'AmazonGateway', $init, $assertNodes, false, $session ); - } - - /** - * Check that the adapter makes the correct calls for successful donations - */ - function testDoPaymentSuccess() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - $this->assertFalse( $result->isFailed(), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'first_name' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'last_name' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); - $mockClient = TestingAmazonAdapter::$mockClient; - $setOrderReferenceDetailsArgs = $mockClient->calls['setOrderReferenceDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $this->assertEquals( $oid, $setOrderReferenceDetailsArgs['seller_order_id'], 'Did not set order id on order reference' ); - $this->assertEquals( $init['amount'], $setOrderReferenceDetailsArgs['amount'], 'Did not set amount on order reference' ); - - $this->assertEquals( $init['currency'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->assertEquals( 'S01-0391295-0674065-C095112', $message['gateway_txn_id'], 'Queue message has wrong txn ID' ); - } - - /** - * Check that declined authorization is reflected in the result's errors - */ - function testDoPaymentDeclined() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'InvalidPaymentMethod'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->getRefresh(), 'Result should be a refresh on error' ); - $errors = $result->getErrors(); - $this->assertEquals( - 'InvalidPaymentMethod', - $errors[0]->getErrorCode(), - 'InvalidPaymentMethod error should be set' - ); - } - - /** - * This apparently indicates a shady enough txn that we should turn them away - */ - function testFailOnAmazonRejected() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'AmazonRejected'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - // Could assert something about errors after rebasing onto master - // $errors = $result->getErrors(); - // $this->assertTrue( isset( $errors['AmazonRejected'] ), 'AmazonRejected error should be set' ); - } - - /** - * When the transaction times out, just gotta fail it till we work out an - * asynchronous authorization flow - */ - function testTransactionTimedOut() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->returns['authorize'][] = 'TransactionTimedOut'; - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $this->assertTrue( $result->isFailed(), 'Result should be failed' ); - } - - /** - * When the SDK throws an exceptions, we should handle it. - */ - function testClientException() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['order_reference_id'] = mt_rand( 0, 10000000 ); // provided by client-side widget IRL - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $mockClient = TestingAmazonAdapter::$mockClient; - $mockClient->exceptions['authorize'][] = new Exception( 'Test' ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - - $errors = $result->getErrors(); - - $this->assertEquals( - ResponseCodes::NO_RESPONSE, - $errors[0]->getErrorCode(), - 'NO_RESPONSE error should be set' - ); - } - - /** - * Check the adapter makes the correct calls for successful monthly donations - */ - function testDoRecurringPaymentSuccess() { - $init = $this->getDonorTestData( 'US' ); - $init['amount'] = '10.00'; - $init['recurring'] = '1'; - $init['subscr_id'] = 'C01-9650293-7351908'; - // We don't get any profile data up front - unset( $init['email'] ); - unset( $init['first_name'] ); - unset( $init['last_name'] ); - - $gateway = $this->getFreshGatewayObject( $init ); - $result = $gateway->doPayment(); - // FIXME: PaymentResult->isFailed returns null for false - $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'first_name' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'last_name' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); - $mockClient = TestingAmazonAdapter::$mockClient; - $setBillingAgreementDetailsArgs = $mockClient->calls['setBillingAgreementDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $this->assertEquals( $oid, $setBillingAgreementDetailsArgs['seller_billing_agreement_id'], 'Did not set order id on billing agreement' ); - $authorizeOnBillingAgreementDetailsArgs = $mockClient->calls['authorizeOnBillingAgreement'][0]; - $this->assertEquals( $init['amount'], $authorizeOnBillingAgreementDetailsArgs['authorization_amount'], 'Did not authorize correct amount' ); - $this->assertEquals( $init['currency'], $authorizeOnBillingAgreementDetailsArgs['currency_code'], 'Did not authorize correct currency code' ); - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->assertEquals( 'S01-5318994-6362993-C004044', $message['gateway_txn_id'], 'Queue message has wrong txn ID' ); - $this->assertEquals( $init['subscr_id'], $message['subscr_id'], 'Queue message has wrong subscription ID' ); - } -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php deleted file mode 100644 index 8eaff91..0000000 --- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php +++ /dev/null @@ -1,245 +0,0 @@ -<<<<<<< HEAD (c615ad Merge branch 'master' into deployment) -======= -<?php -/** - * 'TIMESTAMP=2016%2d05%2d02T19%3a58%3a19Z&CORRELATIONID=b33e6ff7eba&ACK=Failure&VERSION=0%2e000000&BUILD=21669447&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call&L_SEVERITYCODE0=Error' - * - * TOKEN=EC%2d1YM52022PV490383V&PHONENUM=408%2d123%2d4567&BILLINGAGREEMENTACCEPTEDSTATUS=0&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2016%2d05%2d03T19%3a57%3a56Z&CORRELATIONID=c3811aeb1e7f5&ACK=Success&VERSION=124&BUILD=21669447&EMAIL=fr%2dtech%2bdonor%40wikimedia%2eorg&PAYERID=FLJLQ2GV38E4Y&PAYERSTATUS=verified&FIRSTNAME=f&LASTNAME=doner&COUNTRYCODE=US&ADDRESSSTATUS=Confirmed&CURRENCYCODE=JPY&AMT=500&ITEMAMT=500&SHIPPINGAMT=0&HANDLINGAMT=0&TAXAMT=0&CUSTOM=4116&DESC=Donation%20to%20the%20Wikimedia%20Foundation&INVNUM=4116&INSURANCEAMT=0&SHIPDISCAMT=0&INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_CURRENCYCODE=JPY&PAYMENTREQUEST_0_AMT=500&PAYMENTREQUEST_0_ITEMAMT=500&PAYMENTREQUEST_0_SHIPPINGAMT=0&PAYMENTREQUEST_0_HANDLINGAMT=0&PAYMENTREQUEST_0_TAXAMT=0&PAYMENTREQUEST_0_CUSTOM=4116&PAYMENTREQUEST_0_DESC=Donation%20to%20the%20Wikimedia%20Foundation&PAYMENTREQUEST_0_INVNUM=4116&PAYMENTREQUEST_0_INSURANCEAMT=0&PAYMENTREQUEST_0_SHIPDISCAMT=0&PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=fr%2dtech%2dfacilitator%40wikimedia%2eorg&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&PAYMENTREQUESTINFO_0_ERRORCODE=0 - * - * TIMESTAMP=2016%2d05%2d03T21%3a43%3a20Z&CORRELATIONID=f624ed5aa5db0&ACK=Failure&VERSION=124&BUILD=21669447&L_ERRORCODE0=10412&L_SHORTMESSAGE0=Duplicate%20invoice&L_LONGMESSAGE0=Payment%20has%20already%20been%20made%20for%20this%20InvoiceID%2e&L_SEVERITYCODE0=Error - */ - -/** - * - * @group Fundraising - * @group DonationInterface - * @group PayPal - */ -class DonationInterface_Adapter_PayPal_Express_Test extends DonationInterfaceTestCase { - - protected $testAdapterClass = 'TestingPaypalExpressAdapter'; - - public function setUp() { - parent::setUp(); - DonationInterface::initializeSmashPig( 'paypal' ); - $this->setMwGlobals( array( - 'wgDonationInterfaceCancelPage' => 'https://example.com/tryAgain.php', - 'wgPaypalExpressGatewayEnabled' => true, - 'wgDonationInterfaceThankYouPage' => 'https://example.org/wiki/Thank_You', - ) ); - } - - protected 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] ); - } - } - - function testPaymentSetup() { - $init = array( - 'amount' => 1.55, - 'currency' => 'USD', - 'payment_method' => 'paypal', - 'utm_source' => 'CD1234_FR', - 'utm_medium' => 'sitenotice', - 'country' => 'US', - 'contribution_tracking_id' => strval( mt_rand() ), - 'language' => 'fr', - ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); - $result = $gateway->doPayment(); - $gateway->logPending(); // GatewayPage calls this for redirects - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8US12345X1234567U', - $result->getRedirect(), - 'Wrong redirect for PayPal EC payment setup' - ); - $message = DonationQueue::instance()->pop( 'pending' ); - $this->assertNotEmpty( $message, 'Missing pending message' ); - $this->unsetVariableFields( $message ); - $expected = array( - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => null, - 'language' => 'fr', - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'utm_source' => 'CD1234_FR..paypal', - 'currency' => 'USD', - 'email' => '', - 'gross' => '1.55', - 'recurring' => '', - 'response' => false, - 'utm_medium' => 'sitenotice', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'gateway_session_id' => 'EC-8US12345X1234567U', - 'user_ip' => '127.0.0.1', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - ); - $this->assertEquals( - $expected, - $message, - 'PayPal EC setup sending wrong pending message' - ); - } - - /** - * Check that the adapter makes the correct calls for successful donations - * and sends a good queue message. - */ - function testProcessDonorReturn() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); - $gateway->processDonorReturn( array( - 'token' => 'EC%2d4V987654XA123456V', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - 'gateway_session_id' => 'EC-4V987654XA123456V', - 'language' => 'en', - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'response' => false, - 'user_ip' => '127.0.0.1', - 'utm_source' => '..paypal', - 'city' => 'San Francisco', - 'currency' => 'USD', - 'email' => 'do...@generous.net', - 'first_name' => 'Fezziwig', - 'gross' => '1.55', - 'last_name' => 'Fowl', - 'recurring' => '', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'postal_code' => '94105', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - ); - $this->assertEquals( $expected, $message ); - - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending extra messages to donations queue!' - ); - } - - public function testProcessDonorReturnRecurring() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['recurring'] = '1'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'Recurring-OK' ); - $gateway->processDonorReturn( array( - 'token' => 'EC%2d4V987654XA123456V', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNotNull( $message, 'Not sending a message to the donations queue' ); - $this->unsetVariableFields( $message ); - $expected = array ( - 'contribution_tracking_id' => $init['contribution_tracking_id'], - 'country' => 'US', - 'fee' => '0', - 'gateway' => 'paypal_ec', - 'gateway_txn_id' => '5EJ123456T987654S', - 'gateway_session_id' => 'EC-4V987654XA123456V', - 'language' => 'en', - 'order_id' => $init['contribution_tracking_id'] . '.0', - 'payment_method' => 'paypal', - 'payment_submethod' => '', - 'response' => false, - 'user_ip' => '127.0.0.1', - 'utm_source' => '..rpaypal', - 'city' => 'San Francisco', - 'currency' => 'USD', - 'email' => 'do...@generous.net', - 'first_name' => 'Fezziwig', - 'gross' => '1.55', - 'last_name' => 'Fowl', - 'recurring' => '1', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'postal_code' => '94105', - 'source_name' => 'DonationInterface', - 'source_type' => 'payments', - 'subscr_id' => 'I-88J1M3DLSF0', - ); - $this->assertEquals( $expected, $message ); - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending extra messages to donations queue!' - ); - } - - /** - * Check that we send the donor back to paypal to try a different source - */ - function testProcessDonorReturnPaymentRetry() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); - $result = $gateway->processDonorReturn( array( - 'token' => 'EC%2d2D123456D9876543U', - 'PayerID' => 'ASDASD' - ) ); - - $message = DonationQueue::instance()->pop( 'donations' ); - $this->assertNull( $message, 'Should not queue a message' ); - $this->assertFalse( $result->isFailed() ); - $redirect = $result->getRedirect(); - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2D123456D9876543U', - $redirect - ); - } - - public function testProcessDonorReturnRecurringRetry() { - $init = $this->getDonorTestData( 'US' ); - $init['contribution_tracking_id'] = '45931210'; - $init['recurring'] = '1'; - $this->setUpRequest( $init, array( 'Donor' => $init ) ); - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); - $result = $gateway->processDonorReturn( array( - 'token' => 'EC%2d2D123456D9876543U', - 'PayerID' => 'ASDASD' - ) ); - - $this->assertNull( - DonationQueue::instance()->pop( 'donations' ), - 'Sending a spurious message to the donations queue!' - ); - $this->assertFalse( $result->isFailed() ); - $redirect = $result->getRedirect(); - $this->assertEquals( - 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2D123456D9876543U', - $redirect - ); - } - -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) diff --git a/tests/phpunit/DonationQueueTest.php b/tests/phpunit/DonationQueueTest.php deleted file mode 100644 index 4ee6508..0000000 --- a/tests/phpunit/DonationQueueTest.php +++ /dev/null @@ -1,129 +0,0 @@ -<<<<<<< HEAD (c615ad Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/** - * @group DonationInterface - * @group QueueHandling - * - * @category UnitTesting - * @package Fundraising_QueueHandling - */ -class DonationQueueTest extends DonationInterfaceTestCase { - protected $transaction; - protected $queue_name; - protected $expected_message; - - public function setUp() { - parent::setUp(); - - DonationInterface::initializeSmashPig( 'default' ); - $this->queue_name = 'test-' . mt_rand(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceQueues' => array( - $this->queue_name => array(), - ), - ) ); - - $this->transaction = array( - 'gross' => '1.24', - 'fee' => '0', - 'city' => 'Dunburger', - 'contribution_tracking_id' => mt_rand(), - 'country' => 'US', - 'currency' => 'USD', - 'date' => time(), - 'email' => 'nob...@wikimedia.org', - 'first_name' => 'Jen', - 'gateway_account' => 'default', - 'gateway' => 'testgateway', - 'gateway_txn_id' => mt_rand(), - 'order_id' => mt_rand(), - 'language' => 'en', - 'last_name' => 'Russ', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'response' => 'Gateway response something', - 'state_province' => 'AK', - 'street_address' => '1 Fake St.', - 'user_ip' => '127.0.0.1', - 'utm_source' => 'testing', - 'postal_code' => '12345', - ); - - $this->expected_message = array( - 'contribution_tracking_id' => $this->transaction['contribution_tracking_id'], - 'utm_source' => 'testing', - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - 'first_name' => 'Jen', - 'last_name' => 'Russ', - 'street_address' => '1 Fake St.', - 'city' => 'Dunburger', - 'state_province' => 'AK', - 'country' => 'US', - 'postal_code' => '12345', - 'gateway' => 'testgateway', - 'gateway_account' => 'default', - 'gateway_txn_id' => $this->transaction['gateway_txn_id'], - 'order_id' => $this->transaction['order_id'], - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'response' => 'Gateway response something', - 'currency' => 'USD', - 'fee' => '0', - 'gross' => '1.24', - 'user_ip' => '127.0.0.1', - 'date' => (int)$this->transaction['date'], - 'source_host' => gethostname(), - 'source_name' => 'DonationInterface', - 'source_run_id' => getmypid(), - 'source_type' => 'payments', - 'source_version' => DonationQueue::getVersionStamp(), - ); - } - - public function testPushMessage() { - DonationQueue::instance()->push( $this->transaction, $this->queue_name ); - - $actual = DonationQueue::instance()->pop( $this->queue_name ); - unset( $actual['source_enqueued_time'] ); - - $this->assertEquals( $this->expected_message, $actual ); - } - - /** - * After pushing 2, pop should return the first. - */ - public function testIsFifoQueue() { - DonationQueue::instance()->push( $this->transaction, $this->queue_name ); - - $transaction2 = $this->transaction; - $transaction2['order_id'] = mt_rand(); - - DonationQueue::instance()->push( $transaction2, $this->queue_name ); - - $actual = DonationQueue::instance()->pop( $this->queue_name ); - unset( $actual['source_enqueued_time'] ); - - $this->assertEquals( $this->expected_message, $actual ); - } -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) diff --git a/tests/phpunit/GatewayPageTest.php b/tests/phpunit/GatewayPageTest.php deleted file mode 100644 index 0194f45..0000000 --- a/tests/phpunit/GatewayPageTest.php +++ /dev/null @@ -1,207 +0,0 @@ -<<<<<<< HEAD (c615ad Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * @group Fundraising - * @group DonationInterface - * @group GatewayPage - */ -class GatewayPageTest extends DonationInterfaceTestCase { - - /** - * @var GatewayPage - */ - protected $page; - /** - * @var GatewayAdapter - */ - protected $adapter; - - public function setUp() { - $this->page = new TestingGatewayPage(); - // put these here so tests can override them - TestingGenericAdapter::$fakeGlobals = array ( 'FallbackCurrency' => 'USD' ); - TestingGenericAdapter::$acceptedCurrencies[] = 'USD'; - TestingGenericAdapter::$fakeIdentifier = 'globalcollect'; - $this->setMwGlobals( array( - 'wgPaypalGatewayEnabled' => true, - 'wgDonationInterfaceAllowedHtmlForms' => array( - 'paypal' => array( - 'gateway' => 'paypal', - 'payment_methods' => array('paypal' => 'ALL'), - ), - ), - ) ); - parent::setUp(); - } - - protected function setUpAdapter( $extra = array() ) { - $externalData = array_merge( - array( - 'amount' => '200', - 'currency' => 'BBD', - 'contribution_tracking_id' => mt_rand( 10000, 10000000 ), - ), - $extra - ); - $this->adapter = new TestingGenericAdapter( array( - 'external_data' => $externalData, - ) ); - $this->page->adapter = $this->adapter; - } - - public function tearDown() { - TestingGenericAdapter::$acceptedCurrencies = array(); - TestingGenericAdapter::$fakeGlobals = array(); - TestingGenericAdapter::$fakeIdentifier = false; - parent::tearDown(); - } - - public function testCurrencyFallbackWithNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - $this->setUpAdapter(); - - $this->assertFalse( $this->adapter->validatedOK() ); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $this->assertEquals( $msgKey, $errors[0]->getMessageKey() ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - public function testCurrencyFallbackIntermediateConversion() { - TestingGenericAdapter::$fakeGlobals['FallbackCurrency'] = 'OMR'; - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = true; - TestingGenericAdapter::$acceptedCurrencies[] = 'OMR'; - // FIXME: Relies on app default exchange rate. Set explicitly instead. - $this->setUpAdapter(); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $this->assertEquals( $msgKey, $errors[0]->getMessageKey() ); - $this->assertEquals( 38, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'OMR', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - public function testCurrencyFallbackWithoutNotification() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter(); - - $this->assertTrue( $this->adapter->validatedOK() ); - - $errorState = $this->adapter->getErrorState(); - $this->assertFalse( $errorState->hasErrors() ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - public function testCurrencyFallbackAlwaysNotifiesIfOtherErrors() { - TestingGenericAdapter::$fakeGlobals['NotifyOnConvert'] = false; - $this->setUpAdapter( array( 'email' => 'notanemail' ) ); - - $errors = $this->adapter->getErrorState()->getErrors(); - $msgKey = 'donate_interface-fallback-currency-notice'; - $foundError = false; - foreach( $errors as $error ) { - if ( $error->getField() === 'currency' ) { - $this->assertEquals( $msgKey, $error->getMessageKey() ); - $foundError = true; - } - } - $this->assertTrue( $foundError ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - public function testNoFallbackForSupportedCurrency() { - TestingGenericAdapter::$acceptedCurrencies[] = 'BBD'; - $this->setUpAdapter(); - - $errorState = $this->adapter->getErrorState(); - $this->assertFalse( $errorState->hasErrors() ); - $this->assertEquals( 200, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'BBD', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - public function testCurrencyFallbackByCountry() { - // With 'FallbackCurrencyByCountry', we need to return a single supported currency - TestingGenericAdapter::$acceptedCurrencies = array( 'USD' ); - TestingGenericAdapter::$fakeGlobals = array( - 'FallbackCurrency' => false, - 'FallbackCurrencyByCountry' => true, - ); - $extra = array( - 'country' => 'US', - ); - $this->setUpAdapter( $extra ); - - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency' ) ); - } - - /** - * Before redirecting a user to the processor, we should log all of their - * details at info level - */ - function testLogDetailsOnRedirect() { - $init = $this->getDonorTestData(); - $session = array( 'Donor' => $init ); - - $this->verifyFormOutput( 'PaypalLegacyGateway', $init, array(), false, $session ); - - $logged = $this->getLogMatches( LogLevel::INFO, '/^Redirecting for transaction: /' ); - $this->assertEquals( 1, count( $logged ), 'Should have logged details once' ); - preg_match( '/Redirecting for transaction: (.*)$/', $logged[0], $matches ); - $detailString = $matches[1]; - $expected = array( - 'currency' => 'USD', - 'payment_submethod' => '', - 'first_name' => 'Firstname', - 'last_name' => 'Surname', - 'gross' => '1.55', - 'fee' => 0, - 'language' => 'en', - 'email' => 'nob...@wikimedia.org', - 'country' => 'US', - 'payment_method' => 'paypal', - 'user_ip' => '127.0.0.1', - 'recurring' => '', - 'utm_source' => '..paypal', - 'gateway' => 'paypal', - 'gateway_account' => 'testing', - 'gateway_txn_id' => false, - 'response' => false, - 'street_address' => '123 Fake Street', - 'city' => 'San Francisco', - 'state_province' => 'CA', - 'postal_code' => '94105', - ); - $actual = json_decode( $detailString, true ); - // TODO: when tests use PHPUnit 4.4 - // $this->assertArraySubset( $expected, $actual, false, 'Logged the wrong stuff' ); - $expected['order_id'] = $actual['contribution_tracking_id']; - unset( $actual['contribution_tracking_id'] ); - unset( $actual['date'] ); - $this->assertEquals( $expected, $actual, 'Logged the wrong stuff!' ); - } -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) diff --git a/tests/phpunit/LoggingTest.php b/tests/phpunit/LoggingTest.php deleted file mode 100644 index 506ef50..0000000 --- a/tests/phpunit/LoggingTest.php +++ /dev/null @@ -1,162 +0,0 @@ -<<<<<<< HEAD (c615ad Merge branch 'master' into deployment) -======= -<?php -/** - * Wikimedia Foundation - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -use Psr\Log\LogLevel; - -/** - * - * @group Fundraising - * @group DonationInterface - */ -class DonationInterface_LoggingTest extends DonationInterfaceTestCase { - public function setUp() { - parent::setUp(); - - $this->setMwGlobals( array( - 'wgDonationInterfaceLogCompleted' => true, - ) ); - } - - /** - * @param $name string The name of the test case - * @param $data array Any parameters read from a dataProvider - * @param $dataName string|int The name or index of the data set - */ - function __construct( $name = null, array $data = array(), $dataName = '' ) { - parent::__construct( $name, $data, $dataName ); - $this->testAdapterClass = 'TestingGlobalCollectAdapter'; - } - - /** - * Check that we can log completed transactions - */ - public function testLogCompleted() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['email'] = 'innoc...@manichean.com'; - $init['ffname'] = 'cc-vmad'; - unset( $init['order_id'] ); - - $expectedObject = array( - 'gross' => 23.45, - 'city' => 'San Francisco', - //'contribution_tracking_id' => '1', - 'fee' => 0, - 'country' => 'US', - 'currency' => 'EUR', - 'email' => 'innoc...@manichean.com', - 'first_name' => 'Firstname', - 'gateway' => 'globalcollect', - 'language' => 'en', - 'last_name' => 'Surname', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'recurring' => '', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'user_ip' => '127.0.0.1', - 'utm_source' => '..cc', - 'postal_code' => '94105', - 'response' => 'Original Response Status (pre-SET_PAYMENT): 200', - 'gateway_account' => 'test', - ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; - $matches = $this->getLogMatches( LogLevel::INFO, $preface_pattern ); - $this->assertTrue( $matches !== false, - 'Should log a completion message' ); - - $json = str_replace( GatewayAdapter::COMPLETED_PREFACE, '', $matches[0] ); - $actualObject = $this->stripRandomFields( json_decode( $json, true ) ); - $this->assertEquals( $expectedObject, $actualObject, - 'Completion message is as expected' ); - } - - /** - * Test robustness when passed a bad Unicode string. - */ - public function testBadUnicode() { - $init = $this->getDonorTestData(); - $init['payment_method'] = 'cc'; - $init['payment_submethod'] = 'visa'; - $init['amount'] = '23'; - // Fake name with a bad character encoding. - $init['first_name'] = 'Алексан�'; - $init['last_name'] = 'Гончар'; - $init['email'] = 'innoc...@manichean.com'; - $init['ffname'] = 'cc-vmad'; - $init['unusual_key'] = mt_rand(); - unset( $init['order_id'] ); - - $expectedObject = array( - 'gross' => 23.45, - 'fee' => 0, - 'city' => 'San Francisco', - 'country' => 'US', - 'currency' => 'EUR', - 'email' => 'innoc...@manichean.com', - 'first_name' => 'Алексанï', - 'gateway' => 'globalcollect', - 'language' => 'en', - 'last_name' => 'Гончар', - 'payment_method' => 'cc', - 'payment_submethod' => 'visa', - 'recurring' => '', - 'state_province' => 'CA', - 'street_address' => '123 Fake Street', - 'user_ip' => '127.0.0.1', - 'utm_source' => '..cc', - 'postal_code' => '94105', - 'response' => 'Original Response Status (pre-SET_PAYMENT): 200', - 'gateway_account' => 'test', - ); - - $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); - $gateway->do_transaction( 'Confirm_CreditCard' ); - $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; - $matches = $this->getLogMatches( LogLevel::INFO, $preface_pattern ); - $this->assertTrue( $matches !== false, - 'Should log a completion message' ); - - $json = str_replace( GatewayAdapter::COMPLETED_PREFACE, '', $matches[0] ); - $actualObject = $this->stripRandomFields( json_decode( $json, true ) ); - - $this->assertEquals( $expectedObject, $actualObject, - 'Completion message is as expected' ); - } - - protected function stripRandomFields( $data ) { - $toUnset = array( - 'contribution_tracking_id', - 'date', - 'gateway_txn_id', - 'order_id', - ); - array_map( function ( $key ) use ( &$data ) { - unset( $data[$key] ); - }, $toUnset ); - return $data; - } -} ->>>>>>> BRANCH (4ee900 Localisation updates from https://translatewiki.net.) -- To view, visit https://gerrit.wikimedia.org/r/362231 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib652463c4d6b37ebc9a738298950c2f0112091da Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: deployment Gerrit-Owner: Ejegg <ej...@ejegg.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits