TK-999 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/337807 )

Change subject: In Autopromote skip edit count lookup if requirement is 0 or 
invalid
......................................................................

In Autopromote skip edit count lookup if requirement is 0 or invalid

Autopromote makes a DB call to fetch user edit count when checking edit count 
requirements. We can skip this call if requirement is set to 0 or invalid (less 
than 0).

Bug: T157718
Change-Id: I7bcfa6e7e4991fe7b48bef84ad24621564261abc
---
M includes/Autopromote.php
A tests/phpunit/includes/AutopromoteTest.php
2 files changed, 53 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/07/337807/1

diff --git a/includes/Autopromote.php b/includes/Autopromote.php
index 56fbb07..c72a7eb 100644
--- a/includes/Autopromote.php
+++ b/includes/Autopromote.php
@@ -177,7 +177,14 @@
                                }
                                return false;
                        case APCOND_EDITCOUNT:
-                               return $user->getEditCount() >= $cond[1];
+                               $reqEditCount = $cond[1];
+
+                               // T157718: Skip edit count lookup if specified 
edit count is 0 or invalid
+                               if ( $reqEditCount <= 0) {
+                                       return true;
+                               } else {
+                                       return $user->getEditCount() >= 
$reqEditCount;
+                               }
                        case APCOND_AGE:
                                $age = time() - wfTimestampOrNull( TS_UNIX, 
$user->getRegistration() );
                                return $age >= $cond[1];
diff --git a/tests/phpunit/includes/AutopromoteTest.php 
b/tests/phpunit/includes/AutopromoteTest.php
new file mode 100644
index 0000000..0e130ab
--- /dev/null
+++ b/tests/phpunit/includes/AutopromoteTest.php
@@ -0,0 +1,45 @@
+<?php
+
+class AutopromoteTest extends MediaWikiLangTestCase {
+       /**
+        * T157718: Verify Autopromote does not perform edit count lookup if 
requirement is 0 or invalid
+        *
+        * @see Autopromote::getAutopromoteGroups()
+        * @dataProvider provideEditCountsAndRequirements
+        * @param int $editCount edit count of user to be checked by Autopromote
+        * @param int $requirement edit count required to autopromote user
+        */
+       public function testEditCountLookupIsSkippedIfRequirementIsZero( 
$editCount, $requirement ) {
+               $this->setMwGlobals( [
+                       'wgAutopromote' => [
+                               'autoconfirmed' => [ APCOND_EDITCOUNT, 
$requirement ]
+                       ]
+               ] );
+
+               /** @var PHPUnit_Framework_MockObject_MockObject|User $userMock 
*/
+               $userMock = $this->getMock( 'User', [ 'getEditCount' ] );
+               if ( $requirement > 0 ) {
+                       $userMock->expects( $this->once() )
+                               ->method( 'getEditCount' )
+                               ->willReturn( $editCount );
+               } else {
+                       $userMock->expects( $this->never() )
+                               ->method( 'getEditCount' );
+               }
+
+               $result = Autopromote::getAutopromoteGroups( $userMock );
+               if ( $editCount >= $requirement ) {
+                       $this->assertContains( 'autoconfirmed', $result, 'User 
must be promoted if they meet edit count requirement' );
+               } else {
+                       $this->assertNotContains( 'autoconfirmed', $result, 
'User must not be promoted if they fail edit count requirement' );
+               }
+       }
+
+       public static function provideEditCountsAndRequirements() {
+               return [
+                       'user with sufficient editcount' => [ 100, 10 ],
+                   'user with insufficient editcount' => [ 4, 10 ],
+                   'edit count requirement set to 0' => [ 1, 0 ],
+               ];
+       }
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bcfa6e7e4991fe7b48bef84ad24621564261abc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TK-999 <[email protected]>

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

Reply via email to