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

Change subject: Exclude users with null user_registration
......................................................................


Exclude users with null user_registration

Previously, they were incorrectly considered to have registered
now (the time wfTimestamp was called).

Add corresponding test.  Since this must check that NULL is not
equivalent to now, make it so now would be bucketed into the test.
This requires changing the other tests to be relative to now as well.

Bug: 70759
Change-Id: I73e0315e270f2754199d599074a06cf3fe4daddc
(cherry picked from commit 0079ae54107c2beaee0a073571fa75140f2767ee)
---
M TaskRecommendationsExperimentV1.php
M tests/phpunit/TaskRecommendationsExperimentV1Test.php
M tests/phpunit/mocks/LoggedInUser.php
3 files changed, 26 insertions(+), 8 deletions(-)

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



diff --git a/TaskRecommendationsExperimentV1.php 
b/TaskRecommendationsExperimentV1.php
index 20e6ceb..3858204 100644
--- a/TaskRecommendationsExperimentV1.php
+++ b/TaskRecommendationsExperimentV1.php
@@ -39,9 +39,11 @@
                global $wgTaskRecommendationsExperimentV1StartDate,
                        $wgTaskRecommendationsExperimentV1EndDate;
 
-               $registrationDateInUnixTime = wfTimestamp( TS_UNIX, 
$user->getRegistration() );
+               $registrationDateInUnixTime = wfTimestampOrNull( TS_UNIX, 
$user->getRegistration() );
 
-               return $registrationDateInUnixTime >= 
$wgTaskRecommendationsExperimentV1StartDate &&
+               // null user_registration is treated as a very old user, always 
excluded
+               return $registrationDateInUnixTime !== null &&
+                       $registrationDateInUnixTime >= 
$wgTaskRecommendationsExperimentV1StartDate &&
                        $registrationDateInUnixTime < 
$wgTaskRecommendationsExperimentV1EndDate;
        }
 
diff --git a/tests/phpunit/TaskRecommendationsExperimentV1Test.php 
b/tests/phpunit/TaskRecommendationsExperimentV1Test.php
index 15dd85e..9cea4b5 100644
--- a/tests/phpunit/TaskRecommendationsExperimentV1Test.php
+++ b/tests/phpunit/TaskRecommendationsExperimentV1Test.php
@@ -14,8 +14,11 @@
        public function setUp() {
                parent::setUp();
 
-               $this->setMwGlobals( 
'wgTaskRecommendationsExperimentV1StartDate', 1000 );
-               $this->setMwGlobals( 
'wgTaskRecommendationsExperimentV1EndDate', 2000 );
+               $now = time();
+               $startDateOffset = -500;
+               $endDateOffset = 500;
+               $this->setMwGlobals( 
'wgTaskRecommendationsExperimentV1StartDate', $startDateOffset + $now );
+               $this->setMwGlobals( 
'wgTaskRecommendationsExperimentV1EndDate', $endDateOffset + $now );
        }
 
        public function testAnAnonymousUserShouldntSeeThePostEditNotification() 
{
@@ -46,6 +49,15 @@
                $this->assertFalse( $experiment->isFlyoutEnabled() );
        }
 
+       public function 
testLoggedInOldUserWithNullRegistrationDateShouldntSeeAnything() {
+               $user = $this->getLoggedInOldUserWithNullRegistrationDate();
+               $user->setId( 3 );
+               $experiment = new TaskRecommendationsExperimentV1( $user );
+
+               $this->assertFalse( $experiment->isFlyoutEnabled() );
+               $this->assertFalse( $experiment->isPostEditEnabled() );
+       }
+
        public static function bucketingDataProvider() {
                return array(
                        array(
@@ -71,10 +83,14 @@
        }
 
        private function getLoggedInOldUser() {
-               return new LoggedInUser( 800 );
+               return new LoggedInUser( -700 + time() );
        }
 
        private function getLoggedInNewUser() {
-               return new LoggedInUser( 1700 );
+               return new LoggedInUser( 200 + time() );
+       }
+
+       private function getLoggedInOldUserWithNullRegistrationDate() {
+               return new LoggedInUser( null );
        }
 }
diff --git a/tests/phpunit/mocks/LoggedInUser.php 
b/tests/phpunit/mocks/LoggedInUser.php
index 77e5378..eaf46a0 100644
--- a/tests/phpunit/mocks/LoggedInUser.php
+++ b/tests/phpunit/mocks/LoggedInUser.php
@@ -11,12 +11,12 @@
        /**
         * Constructs a mock user and sets the timestamp field in the correct 
format
         *
-        * @param mixed $registration A timestamp in one of the input formats 
supported by wfTimestamp
+        * @param int|string|null $registration A timestamp in one of the input 
formats supported by wfTimestampOrNull
         */
        public function __construct( $registration ) {
                parent::__construct();
 
-               $this->registration = wfTimeStamp( TS_MW, $registration );
+               $this->registration = wfTimestampOrNull( TS_MW, $registration );
        }
 
        public function isLoggedIn() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I73e0315e270f2754199d599074a06cf3fe4daddc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GettingStarted
Gerrit-Branch: wmf/1.24wmf21
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to