Mwalker has submitted this change and it was merged.

Change subject: Fixing up some weirdness we were seeing around language 
selection
......................................................................


Fixing up some weirdness we were seeing around language selection

Change-Id: I242aae9992a0409adbe839b0cae8af53be5399a5
---
M gateway_common/DonationData.php
M globalcollect_gateway/forms/js/gc.js
M tests/Adapter/GatewayAdapterTestCase.php
M tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
M tests/DonationDataTestCase.php
M tests/DonationInterfaceTestCase.php
M tests/includes/test_gateway/test.adapter.php
7 files changed, 80 insertions(+), 20 deletions(-)

Approvals:
  Mwalker: Verified; Looks good to me, approved



diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php
index f3ec996..c66e369 100644
--- a/gateway_common/DonationData.php
+++ b/gateway_common/DonationData.php
@@ -774,17 +774,15 @@
        protected function setLanguage() {
                global $wgLang;
                $language = false;
-               
+
                if ( $this->isSomething( 'uselang' ) ) {
                        $language = $this->getVal( 'uselang' );
                } elseif ( $this->isSomething( 'language' ) ) {
                        $language = $this->getVal( 'language' );
                }
                
-               if ( $language == false
-                       || !Language::isValidBuiltInCode( 
$this->normalized['language'] ) )
-               {
-                       $language = $wgLang->getCode() ;
+               if ( $language == false || !Language::isValidBuiltInCode( 
$language ) ) {
+                       $language = $wgLang->getCode();
                }
                
                $this->setVal( 'language', $language );
diff --git a/globalcollect_gateway/forms/js/gc.js 
b/globalcollect_gateway/forms/js/gc.js
index 9bc2165..26785ca 100644
--- a/globalcollect_gateway/forms/js/gc.js
+++ b/globalcollect_gateway/forms/js/gc.js
@@ -3,10 +3,7 @@
        // Load wait spinner
        $( '#payment' ).append( '<br/><br/><br/><img alt="loading" 
src="'+mw.config.get( 'wgScriptPath' 
)+'/extensions/DonationInterface/gateway_forms/includes/loading-white.gif" />' 
);
        var language = 'en'; // default value is English
-       var matches = document.location.href.match(/uselang=(\w+)/i); // fine 
the real language
-       if ( matches && matches[1] ) {
-               language = matches[1];
-       }
+       language = $( "input[name='language']" ).val();
        
        var currencyField = document.getElementById( 'input_currency_code' );
        var currency_code = '';
diff --git a/tests/Adapter/GatewayAdapterTestCase.php 
b/tests/Adapter/GatewayAdapterTestCase.php
index e1088fd..99441c6 100644
--- a/tests/Adapter/GatewayAdapterTestCase.php
+++ b/tests/Adapter/GatewayAdapterTestCase.php
@@ -89,5 +89,22 @@
                //production adapters. 
                $this->assertInstanceOf( 'DonationData', 
$gateway->getDonationData() );
        }
+
+       public function testLanguageChange() {
+               $options = $this->getDonorTestData( 'US' );
+               $options['payment_method'] = 'cc';
+               $options['payment_submethod'] = 'visa';
+               $gateway = $this->getFreshGatewayObject( $options );
+
+               $this->assertEquals( $gateway->_getData_Staged( 'language' ), 
'en', "'US' donor's language was inproperly set. Should be 'en'" );
+               $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
+               //so we know it tried to screw with the session and such.
+
+               $options = $this->getDonorTestData( 'NO' );
+               $gateway = $this->getFreshGatewayObject( $options );
+               $this->assertEquals( $gateway->_getData_Staged( 'language' ), 
'no', "'NO' donor's language was inproperly set. Should be 'no'" );
+               $this->resetAllEnv();
+       }
+
 }
 
diff --git a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php 
b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
index f2f5575..5382f17 100644
--- a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
+++ b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
@@ -14,8 +14,6 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
- * @since              r98249
- * @author             Jeremy Postlethwaite <jpostlethwa...@wikimedia.org>
  */
 
 /**
@@ -209,4 +207,16 @@
                $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'" );
+               $this->resetAllEnv();
+       }
+
 }
diff --git a/tests/DonationDataTestCase.php b/tests/DonationDataTestCase.php
index a575d94..13a1720 100644
--- a/tests/DonationDataTestCase.php
+++ b/tests/DonationDataTestCase.php
@@ -14,8 +14,6 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
- * @since              r98249
- * @author Katie Horn <kh...@wikimedia.org>
  */
 
 /**
@@ -27,7 +25,6 @@
  * @group Fundraising
  * @group DonationInterface
  * @group Splunge
- * @author Katie Horn <kh...@wikimedia.org>
  */
 class DonationInterface_DonationDataTestCase extends DonationInterfaceTestCase 
{
 
@@ -265,7 +262,6 @@
                $data = $this->testData;
                $data['amount'] = 'this is not a number';
                $data['amountGiven'] = 42.50;
-               //unset($data['zip']);
                $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
                $returned = $ddObj->getDataEscaped();
                $this->assertEquals( 42.50, $returned['amount'], "Amount was 
not properly reset" );
@@ -279,7 +275,6 @@
                $data = $this->testData;
                $data['amount'] = 88.15;
                $data['amountGiven'] = 42.50;
-               //unset($data['zip']);
                $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
                $returned = $ddObj->getDataEscaped();
                $this->assertEquals( 88.15, $returned['amount'], "Amount was 
not properly reset" );
@@ -293,7 +288,6 @@
                $data = $this->testData;
                $data['amount'] = -1;
                $data['amountOther'] = 3.25;
-               //unset($data['zip']);
                $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
                $returned = $ddObj->getDataEscaped();
                $this->assertEquals(3.25, $returned['amount'], "Amount was not 
properly reset");
@@ -308,7 +302,6 @@
                $data['amount'] = 'splunge';
                $data['amountGiven'] = 'wombat';
                $data['amountOther'] = 'macedonia';
-               //unset($data['zip']);
                $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
                $returned = $ddObj->getDataEscaped();
                $this->assertEquals( 'invalid', $returned['amount'], "Amount 
was not properly reset");
@@ -317,6 +310,38 @@
        }
 
        /**
+        *
+        */
+       public function testSetNormalizedLanguage_uselang() {
+               $data = $this->testData;
+               unset( $data['uselang'] );
+               unset( $data['language'] );
+
+               $data['uselang'] = 'no';
+
+               $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
+               $returned = $ddObj->getDataEscaped();
+               $this->assertEquals( 'no', $returned['language'], "Language 
'no' was normalized out of existance. Sad." );
+               $this->assertArrayNotHasKey( 'uselang', $returned, "'uselang' 
should have been removed from the data" );
+       }
+
+       /**
+        *
+        */
+       public function testSetNormalizedLanguage_language() {
+               $data = $this->testData;
+               unset( $data['uselang'] );
+               unset( $data['language'] );
+
+               $data['language'] = 'no';
+
+               $ddObj = new DonationData( $this->getFreshGatewayObject( 
$this->initial_vars ), true, $data ); //change to test mode with explicit test 
data
+               $returned = $ddObj->getDataEscaped();
+               $this->assertEquals( 'no', $returned['language'], "Language 
'no' was normalized out of existance. Sad." );
+               $this->assertArrayNotHasKey( 'uselang', $returned, "'uselang' 
should have been removed from the data" );
+       }
+
+       /**
         * TODO: Make sure ALL these functions in DonationData are tested, 
either directly or through a calling function.
         * I know that's more regression-ish, but I stand by it. :p
        function setNormalizedOrderIDs(){
diff --git a/tests/DonationInterfaceTestCase.php 
b/tests/DonationInterfaceTestCase.php
index febe6a2..d4d6c0b 100644
--- a/tests/DonationInterfaceTestCase.php
+++ b/tests/DonationInterfaceTestCase.php
@@ -14,8 +14,6 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
- * @since              r98249
- * @author             Jeremy Postlethwaite <jpostlethwa...@wikimedia.org>
  */
 
 require_once __DIR__ . '/TestConfiguration.php';
@@ -132,6 +130,17 @@
                                'amount' => '1.55',
                                'language' => 'es',
                        ),
+                       'NO' => array (
+                               'city' => 'Oslo',
+                               'state' => 'XX',
+                               'zip' => '0',
+                               'currency_code' => 'EUR',
+                               'street' => '123 Fake Gate',
+                               'fname' => 'Fornavn',
+                               'lname' => 'Etternavn',
+                               'amount' => '1.55',
+                               'language' => 'no',
+                       ),
                );
                //default to US
                if ( $country === '' ) {
diff --git a/tests/includes/test_gateway/test.adapter.php 
b/tests/includes/test_gateway/test.adapter.php
index 5662672..3a7f166 100644
--- a/tests/includes/test_gateway/test.adapter.php
+++ b/tests/includes/test_gateway/test.adapter.php
@@ -260,6 +260,10 @@
                return call_user_func_array( array ( $this, 'getData_Staged' ), 
func_get_args() );
        }
 
+       public function _stageData() {
+               $this->stageData();
+       }
+
        /**
         * @TODO: Get rid of this and the override mechanism as soon as you
         * refactor the constructor into something reasonable.

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I242aae9992a0409adbe839b0cae8af53be5399a5
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Katie Horn <kh...@wikimedia.org>
Gerrit-Reviewer: Adamw <awi...@wikimedia.org>
Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org>
Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org>
Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to