Awight has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/342176 )

Change subject: [WIP] Play with stringification
......................................................................

[WIP] Play with stringification

Change-Id: Ida2727720bd27eb26d789b026d497cf158fe1540
---
M gateway_common/DonationData.php
M tests/phpunit/Adapter/Amazon/AmazonTest.php
M tests/phpunit/DonationDataTest.php
M tests/phpunit/DonationInterfaceTestCase.php
M tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
5 files changed, 30 insertions(+), 8 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/76/342176/1

diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php
index 35019fc..51fd091 100644
--- a/gateway_common/DonationData.php
+++ b/gateway_common/DonationData.php
@@ -253,7 +253,15 @@
         * @param string $val The value you'd like to assign to the key.
         */
        public function setVal( $key, $val ) {
-               $this->normalized[$key] = $val;
+               // Convert empty to null for consistency.
+               if ( $val === '' ) {
+                       $val = null;
+               }
+
+               $this->normalized[$key] = (string) $val;
+
+               // TODO: Set something dirty so that we're sure to normalize 
before
+               // pulling data.
        }
 
        /**
@@ -302,6 +310,15 @@
                // FIXME: there's a ghost invocation during DonationData 
construction.
                // This condition should actually be "did data come from 
anywhere?"
                if ( !empty( $this->normalized ) ) {
+                       // Cast all values to string.
+                       $toStringOrNull = function ( $value ) {
+                               if ( $value === null || $value === '' ) {
+                                       return null;
+                               }
+                               return (string) $value;
+                       };
+                       $this->normalized = array_map( $toStringOrNull, 
$this->normalized );
+
                        $updateCtRequired = 
$this->handleContributionTrackingID(); // Before Order ID
                        $this->setNormalizedOrderIDs();
                        $this->setReferrer();
diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonTest.php
index 8284d51..b7c2ef9 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonTest.php
@@ -65,6 +65,8 @@
         * Integration test to verify that the Amazon gateway converts Canadian
         * dollars before redirecting
         *
+        * FIXME: Merge with currency fallback tests?
+        *
         * @dataProvider canadaLanguageProvider
         */
        function testCanadianDollarConversion( $language ) {
diff --git a/tests/phpunit/DonationDataTest.php 
b/tests/phpunit/DonationDataTest.php
index 96b7cfc..1f69d2b 100644
--- a/tests/phpunit/DonationDataTest.php
+++ b/tests/phpunit/DonationDataTest.php
@@ -88,10 +88,12 @@
 
                $ddObj = new DonationData( $this->getFreshGatewayObject( 
self::$initial_vars ) ); //as if we were posted.
                $returned = $ddObj->getData();
-               $expected = array(  'posted' => '',
+               $expected = array(
                        'amount' => '0.00',
                        'appeal' => 'JimmyQuote',
                        'country' => 'XX',
+                       'currency_code' => '',
+                       'email' => '',
                        'payment_method' => '',
                        'referrer' => '',
                        'utm_source' => '..',
diff --git a/tests/phpunit/DonationInterfaceTestCase.php 
b/tests/phpunit/DonationInterfaceTestCase.php
index 9a33ce1..6f98a66 100644
--- a/tests/phpunit/DonationInterfaceTestCase.php
+++ b/tests/phpunit/DonationInterfaceTestCase.php
@@ -434,23 +434,23 @@
         * @return GatewayAdapter The new relevant gateway adapter object.
         */
        function getFreshGatewayObject( $external_data = null, $setup_hacks = 
array() ) {
-               $p1 = null;
+               $data = null;
                if ( !is_null( $external_data ) ) {
-                       $p1 = array (
+                       $data = array (
                                'external_data' => $external_data,
                        );
                }
 
                if ( $setup_hacks ) {
-                       if ( !is_null( $p1 ) ) {
-                               $p1 = array_merge( $p1, $setup_hacks );
+                       if ( !is_null( $data ) ) {
+                               $data = array_merge( $data, $setup_hacks );
                        } else {
-                               $p1 = $setup_hacks;
+                               $data = $setup_hacks;
                        }
                }
 
                $class = $this->testAdapterClass;
-               $gateway = new $class( $p1 );
+               $gateway = new $class( $data );
 
                $classReflection = new ReflectionClass( $gateway );
 
diff --git 
a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
index 728c435..c2e8c6c 100644
--- a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
@@ -98,6 +98,7 @@
                $file_path = __DIR__ . '/../';
                $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
                $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
+error_log($file_path);
 
                //these are all going to be short, so...
                if ( file_exists( $file_path ) ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/342176
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida2727720bd27eb26d789b026d497cf158fe1540
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to