From 9d95be4f90728894a4aedfd7a01582175fe02489 Mon Sep 17 00:00:00 2001 From: aude Date: Sat, 20 Sep 2014 17:11:00 +0200 Subject: [PATCH] UserTest: Fix edit count test which incorrectly added user to db Although 'added' to the database, the user name was cleared in User::loadDefaults() and not added correctly to the database. Then if one has BetaFeatures extension, then the test fails. Via a hook, BetaFeatures does "User::newFromName( $user->getName() );", that produces a null object as name is '127.0.0.1' and then $user->getOption() fails. loadDefaults() is automatically called by addToDatabase() with correct parameters, so we can just remove the call. Bug: 68626 Change-Id: Ibb5c60192eb83b2608f72b59d7705854549a5dac --- tests/phpunit/includes/UserTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 5be1b96e1d..a0c20bb407 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -214,8 +214,10 @@ class UserTest extends MediaWikiTestCase { */ public function testEditCount() { $user = User::newFromName( 'UnitTestUser' ); - $user->loadDefaults(); - $user->addToDatabase(); + + if ( !$user->getId() ) { + $user->addToDatabase(); + } // let the user have a few (3) edits $page = WikiPage::factory( Title::newFromText( 'Help:UserTest_EditCount' ) ); @@ -248,7 +250,10 @@ class UserTest extends MediaWikiTestCase { */ public function testOptions() { $user = User::newFromName( 'UnitTestUser' ); - $user->addToDatabase(); + + if ( !$user->getId() ) { + $user->addToDatabase(); + } $user->setOption( 'userjs-someoption', 'test' ); $user->setOption( 'cols', 200 ); @@ -281,7 +286,7 @@ class UserTest extends MediaWikiTestCase { $wgPasswordExpireGrace = 3600 * 24 * 7; // 7 days $user = User::newFromName( 'UnitTestUser' ); - $user->loadDefaults(); + $user->loadDefaults( 'UnitTestUser' ); $this->assertEquals( false, $user->getPasswordExpired() ); $ts = time() - ( 3600 * 24 * 1 ); // 1 day ago -- 2.20.1