jenkins-bot has submitted this change and it was merged.

Change subject: Prefer canonical parameter names in form chooser
......................................................................


Prefer canonical parameter names in form chooser

TODO: phase out the non-standard ones.

Bug: T130939
Change-Id: Ie42d2cdaae0354c91b65544f1ce9375180d14134
---
M special/GatewayFormChooser.php
M tests/FormChooserTest.php
2 files changed, 47 insertions(+), 8 deletions(-)

Approvals:
  AndyRussG: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/special/GatewayFormChooser.php b/special/GatewayFormChooser.php
index 25e936f..5512412 100644
--- a/special/GatewayFormChooser.php
+++ b/special/GatewayFormChooser.php
@@ -36,14 +36,30 @@
                        $this->getOutput()->redirect( 
Title::newFromText('Special:FundraiserMaintenance')->getFullURL(), '302' );
                        return;
                }
-               // Set the country parameter
-               $coerceNull = function( $val ) { return ( $val === '' ) ? null 
: $val; };
-               $country = $coerceNull( $this->getRequest()->getVal( 'country', 
null ) );
-               $currency = $coerceNull( $this->getRequest()->getVal( 
'currency', null ) );
-               $paymentMethod = $coerceNull( $this->getRequest()->getVal( 
'paymentmethod', null ) );
-               $paymentSubMethod = $coerceNull( $this->getRequest()->getVal( 
'submethod', null ) );
+
+               $request = $this->getRequest();
+               // Check multiple query string parameters, return the value of 
the
+               // first we find, or null if none have a value.
+               $getValForParams = function( $params ) use ( $request ) {
+                       $params = ( array ) $params;
+                       $val = null;
+                       do {
+                               $val = $request->getVal( array_shift( $params 
), null );
+                               if ( $val === '' ) {
+                                       $val = null;
+                               }
+                       } while ( $val === null && !empty( $params ) );
+                       return $val;
+               };
+
+               $country = $getValForParams( 'country' );
+               // Many banner links use non-standard names for the next three
+               // parameters. Prefer the standard names, but allow the old 
ones.
+               $currency = $getValForParams( array( 'currency_code', 
'currency' ) );
+               $paymentMethod = $getValForParams( array( 'payment_method', 
'paymentmethod' ) );
+               $paymentSubMethod = $getValForParams( array( 
'payment_submethod', 'submethod' ) );
+               $gateway = $getValForParams( 'gateway' );
                $recurring = $this->getRequest()->getVal( 'recurring', false );
-               $gateway = $coerceNull( $this->getRequest()->getVal( 'gateway', 
null ) );
 
                // FIXME: This is clearly going to go away before we deploy 
this bizniss.
                $testNewGetAll = $this->getRequest()->getVal( 'testGetAll', 
false );
diff --git a/tests/FormChooserTest.php b/tests/FormChooserTest.php
index a67d109..29acf6f 100644
--- a/tests/FormChooserTest.php
+++ b/tests/FormChooserTest.php
@@ -167,7 +167,6 @@
        }
 
        function testMaintenanceMode_Redirect() {
-               global $wgContributionTrackingFundraiserMaintenance;
 
                $this->setMwGlobals( array(
                        'wgContributionTrackingFundraiserMaintenance' => true,
@@ -184,6 +183,30 @@
                );
                $this->verifyFormOutput( 'GatewayFormChooser', $initial, 
$assertNodes, false );
        }
+
+       /**
+        * currency_code should take precedence over currency, payment_method
+        * over paymentmethod, etc.
+        */
+       function testPreferCanonicalParams() {
+               $self = $this; // someday, my upgrade will come
+               $assertNodes = array(
+                       'headers' => array(
+                               'Location' => function( $val ) use ( $self ) {
+                                       $qs = array();
+                                       parse_str( parse_url( $val, 
PHP_URL_QUERY ), $qs );
+                                       $self->assertEquals( 'paypal', 
$qs['ffname'], 'Wrong form' );
+                               }
+                       ),
+               );
+               $initial = array(
+                       'language' => 'en',
+                       'payment_method' => 'paypal',
+                       'paymentmethod' => 'amazon',
+                       'country' => 'US',
+               );
+               $this->verifyFormOutput( 'GatewayFormChooser', $initial, 
$assertNodes, false );
+       }
 }
 
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie42d2cdaae0354c91b65544f1ce9375180d14134
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to