diff --git a/includes/user/User.php b/includes/user/User.php index 1256287a812..c87694780ed 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -2715,6 +2715,7 @@ class User implements Authority, UserIdentity, UserEmailContact { 'user_registration' => $dbw->timestamp( $this->mRegistration ), 'user_editcount' => 0, 'user_touched' => $dbw->timestamp( $this->mTouched ), + 'user_is_temp' => $this->isTemp(), ] ) ->caller( $fname )->execute(); if ( !$dbw->affectedRows() ) { diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index a40d50c6d97..268b3f18958 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -1763,4 +1763,30 @@ class UserTest extends MediaWikiIntegrationTestCase { $user = new User; $this->assertFalse( $user->isNamed() ); } + + public static function provideAddToDatabase_temp() { + return [ + [ '*Unregistered 1', '1' ], + [ 'Some user', '0' ] + ]; + } + + /** + * @covers User::addToDatabase + * @dataProvider provideAddToDatabase_temp + */ + public function testAddToDatabase_temp( $name, $expected ) { + $this->enableAutoCreateTempUser(); + + $user = User::newFromName( $name ); + $user->addToDatabase(); + $field = $this->db->newSelectQueryBuilder() + ->select( 'user_is_temp' ) + ->from( 'user' ) + ->where( [ 'user_name' => $name ] ) + ->caller( __METHOD__ ) + ->fetchField(); + + $this->assertSame( $expected, $field ); + } }