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

Change subject: Silently uppercase the first letter of a users name
......................................................................


Silently uppercase the first letter of a users name

Rewrite GoogleLogin::isValidUserName() to use User::newFromName with validity
check for a createable username (which takes care of all possible things).

Add some basic tests, but remember, that the main tests are run by MediaWiki 
core
in UserTest::testGetCanonicalName(), which is the base of the rewritten 
function.

Extra points:
 * Add right message for managegooglelogin

Bug: T107806
Change-Id: I49c5ba91dd2def979a25e1debc1369621c3d8043
---
M GoogleLogin.php
M i18n/en.json
M i18n/qqq.json
M includes/GoogleLogin.body.php
M includes/GoogleLogin.hooks.php
A tests/phpunit/GoogleLogin.bodyTest.php
6 files changed, 47 insertions(+), 10 deletions(-)

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



diff --git a/GoogleLogin.php b/GoogleLogin.php
index 68ecb46..07575a5 100644
--- a/GoogleLogin.php
+++ b/GoogleLogin.php
@@ -81,6 +81,7 @@
 $wgHooks['ListDefinedTags'][] = 'GoogleLoginHooks::onListDefinedAndActiveTags';
 $wgHooks['ChangeTagsListActive'][] = 
'GoogleLoginHooks::onListDefinedAndActiveTags';
 $wgHooks['LoginFormValidErrorMessages'][] = 
'GoogleLoginHooks::onLoginFormValidErrorMessages';
+$wgHooks['UnitTestsList'][] = 'GoogleLoginHooks::onUnitTestsList';
 
 // ResourceLoader modules
 // path template
diff --git a/i18n/en.json b/i18n/en.json
index 278bd41..2b5f055 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -69,5 +69,6 @@
        "googlelogin-prefs-status": "GoogleLogin status:",
        "tag-googlelogin": "[[Special:GoogleLogin|GoogleLogin]]",
        "tag-googlelogin-description": "Registrations with this tag were made 
with [[Special:GoogleLogin|GoogleLogin]]",
-       "action-managegooglelogin": "Manage GoogleLogin connections"
+       "action-managegooglelogin": "Manage GoogleLogin connections",
+       "right-managegooglelogin": "Able to add, remove and view GoogleLogin 
connections"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a575320..dc7ee67 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -73,5 +73,6 @@
        "googlelogin-prefs-status": "Name of the Line in Special:Preferences 
identifying GoogleLoign status (linked or not linked).",
        "tag-googlelogin": "Tag in [[Special:RecentChanges]] for user account 
creations made with GoogleLogin.\n\nSee also:\n* 
{{msg-mw|Tag-googlelogin-description}}",
        "tag-googlelogin-description": "Short description, that account 
creations with this tag are made with GoogleLogin.",
-       "action-managegooglelogin": "Message key for user right 
\"managegooglelogin\""
+       "action-managegooglelogin": "Message key for user right 
\"managegooglelogin\"",
+       "right-managegooglelogin": "Description of user right to view, edit and 
remove Google Login connections.\n\n{{Doc-right|mf-uploadbutton}}"
 }
diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php
index 3e072b8..b9e6a62 100644
--- a/includes/GoogleLogin.body.php
+++ b/includes/GoogleLogin.body.php
@@ -227,20 +227,16 @@
        }
 
        /**
-        * Checks, if the Username is valid to register
+        * Checks, if the Username is valid and createable
         * @param string $name The username to check
         * @return boolean
         */
        public static function isValidUserName( $name ) {
-               if (
-                       User::isCreatableName( $name ) &&
-                       User::isValidUserName( $name ) &&
-                       User::idFromName( $name ) === null
-               ) {
-                       return true;
-               } else {
+               $user = User::newFromName( $name, 'creatable' );
+               if ( !$user ) {
                        return false;
                }
+               return true;
        }
 
        /**
diff --git a/includes/GoogleLogin.hooks.php b/includes/GoogleLogin.hooks.php
index 78579e8..1944c01 100644
--- a/includes/GoogleLogin.hooks.php
+++ b/includes/GoogleLogin.hooks.php
@@ -160,4 +160,17 @@
        public static function onLoginFormValidErrorMessages( array &$messages 
) {
                $messages[] = 'googlelogin-login-merge-warning';
        }
+
+       /**
+        * UnitTestsList hook handler
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
+        *
+        * @param array $files
+        * @return bool
+        */
+       public static function onUnitTestsList( &$files ) {
+               $files[] = __DIR__ . '/../tests/phpunit';
+
+               return true;
+       }
 }
diff --git a/tests/phpunit/GoogleLogin.bodyTest.php 
b/tests/phpunit/GoogleLogin.bodyTest.php
new file mode 100644
index 0000000..0d66da7
--- /dev/null
+++ b/tests/phpunit/GoogleLogin.bodyTest.php
@@ -0,0 +1,25 @@
+<?php
+
+class GoogleLoginTest extends MediaWikiTestCase {
+       /**
+        * Only some basic things, other tests are run in
+        * UserTest::testGetCanonicalName().
+        *
+        * @covers GoogleLogin::isValidUserName
+        * @dataProvider provideTestNames
+        */
+       public function testIsValidUserName( $name, $expected ) {
+               $retval = GoogleLogin::isValidUserName( $name );
+               $this->assertEquals( $expected, $retval );
+       }
+
+       public function provideTestNames() {
+               return array(
+                       array( 'ValidTestUser', true ),
+                       array( 'lowerCaseBegin', true ),
+                       array( 'InvalidTestUser#', false ),
+                       array( ' trailing ', true ),
+                       array( ' back / slash ', false ),
+               );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I49c5ba91dd2def979a25e1debc1369621c3d8043
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/GoogleLogin
Gerrit-Branch: master
Gerrit-Owner: Zifnab06 <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to