Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86790
Change subject: tests for the return_value_map
......................................................................
tests for the return_value_map
Change-Id: I4466622b4e671508716dc2dc7a491d47569fe65c
---
M DonationInterface.php
M tests/Adapter/GatewayAdapterTestCase.php
2 files changed, 42 insertions(+), 32 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/90/86790/1
diff --git a/DonationInterface.php b/DonationInterface.php
index 6ddbff8..c06e418 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -109,6 +109,10 @@
$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnLetter'] =
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter.php';
$wgAutoloadClasses['Gateway_Form_RapidHtml'] = $donationinterface_dir .
'gateway_forms/RapidHtml.php';
+if ( defined( 'MW_PHPUNIT_TEST' ) ) {
+ $wgAutoloadClasses['TestingGlobalCollectAdapter'] =
$donationinterface_dir . 'tests/includes/test_gateway/test.adapter.php';
+}
+
//GlobalCollect gateway classes
if ( $optionalParts['GlobalCollect'] === true ){
$wgDonationInterfaceClassMap['globalcollect'] = 'GlobalCollectAdapter';
diff --git a/tests/Adapter/GatewayAdapterTestCase.php
b/tests/Adapter/GatewayAdapterTestCase.php
index b406dc9..1bf25ad 100644
--- a/tests/Adapter/GatewayAdapterTestCase.php
+++ b/tests/Adapter/GatewayAdapterTestCase.php
@@ -41,6 +41,11 @@
* @group DonationInterface
*/
class DonationInterface_Adapter_GatewayAdapterTestCase extends
DonationInterfaceTestCase {
+ public function setUp() {
+ global $wgGlobalCollectGatewayTest;
+
+ $wgGlobalCollectGatewayTest = true;
+ }
/**
*
@@ -51,17 +56,6 @@
*/
public function testConstructor() {
- global $wgGlobalCollectGatewayTest;
-
- $wgGlobalCollectGatewayTest = true;
-
- $_SERVER = array();
-
- $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
- $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME;
- $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME;
- $_SERVER['REQUEST_URI'] =
'/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount';
-
$payment_product_id = 11;
$optionsForTestData = array(
@@ -72,11 +66,9 @@
$options = $this->getGatewayAdapterTestDataFromSpain(
$optionsForTestData );
- $testAdapter = TESTS_ADAPTER_DEFAULT;
-
- $gateway = new $testAdapter( $options );
+ $gateway = new TestingGlobalCollectAdapter( $options );
- $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway );
+ $this->assertNotNull( $gateway ); // ;)
}
/**
@@ -86,17 +78,6 @@
*/
public function testConstructorHasDonationData() {
- global $wgGlobalCollectGatewayTest;
-
- $wgGlobalCollectGatewayTest = true;
-
- $_SERVER = array();
-
- $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
- $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME;
- $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME;
- $_SERVER['REQUEST_URI'] =
'/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount';
-
$payment_product_id = 11;
$optionsForTestData = array(
@@ -107,16 +88,41 @@
$options = $this->getGatewayAdapterTestDataFromSpain(
$optionsForTestData );
- $testAdapter = TESTS_ADAPTER_DEFAULT;
-
- $adapter = new $testAdapter( $options );
-
- $this->assertInstanceOf( 'TestingGlobalCollectAdapter',
$adapter );
+ $adapter = new TestingGlobalCollectAdapter();
//please define this function only inside the
TESTS_ADAPTER_DEFAULT,
//which should be a test adapter object that descende from one
of the
//production adapters.
$this->assertInstanceOf( 'DonationData', $adapter->getDonationData() );
}
-}
+ public function testCodeRange() {
+ $adapter = new TestingGlobalCollectAdapter();
+
+ $transaction_type = 'transaction1';
+ $key = 'k';
+ $action1 = 'complete';
+ $action2 = 'pending';
+ $adapter->_addCodeRange( $transaction_type, $key, $action1, 0,
50 );
+ $adapter->_addCodeRange( $transaction_type, $key, $action2, 100
);
+
+ $this->assertEquals( $action1, $adapter->_findCodeAction(
$transaction_type, $key, 49 ) );
+ $this->assertEquals( $action1, $adapter->_findCodeAction(
$transaction_type, $key, 50 ) );
+ $this->assertEquals( $action2, $adapter->_findCodeAction(
$transaction_type, $key, 51 ) );
+ }
+
+ public function testCodeRangeSplit() {
+ $adapter = new TestingGlobalCollectAdapter();
+
+ $transaction_type = 'transaction1';
+ $key = 'k';
+ $action1 = 'complete';
+ $action2 = 'pending';
+ $adapter->_addCodeRange( $transaction_type, $key, $action1, 0,
50 );
+ $adapter->_addCodeRange( $transaction_type, $key, $action2, 25
);
+
+ $this->assertEquals( $action1, $adapter->_findCodeAction(
$transaction_type, $key, 24 ) );
+ $this->assertEquals( $action2, $adapter->_findCodeAction(
$transaction_type, $key, 25 ) );
+ $this->assertEquals( $action1, $adapter->_findCodeAction(
$transaction_type, $key, 26 ) );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/86790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4466622b4e671508716dc2dc7a491d47569fe65c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits