From edf5632f6a3a163c159df06000b519371b718d20 Mon Sep 17 00:00:00 2001 From: parent5446 Date: Mon, 29 Oct 2012 16:07:49 -0400 Subject: [PATCH] (bug 37963) Fixed loading process for user options. The bug has actually already been fixed, so this patch just removes extraneous function calls and code in User::getOption() and User::setOption(). It also adds unit tests for user options (including a test for the case provided in the bug report). Change-Id: Idd8af9cf1a26a4adbde3ca71dde64539ecd0a207 --- RELEASE-NOTES-1.21 | 1 + includes/User.php | 13 +------------ tests/phpunit/includes/UserTest.php | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 3357686415..7111254fb8 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -56,6 +56,7 @@ production. current revision. * (bug 41494) Honor $wgLogExceptionBacktrace when logging non-API exceptions caught during API execution. +* (bug 37963) Fixed loading process for user options === API changes in 1.21 === * prop=revisions can now report the contentmodel and contentformat, see docs/contenthandler.txt diff --git a/includes/User.php b/includes/User.php index 770b28eed9..1efdf6b7ea 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2215,13 +2215,6 @@ class User { global $wgHiddenPrefs; $this->loadOptions(); - if ( is_null( $this->mOptions ) ) { - if($defaultOverride != '') { - return $defaultOverride; - } - $this->mOptions = User::getDefaultOptions(); - } - # We want 'disabled' preferences to always behave as the default value for # users, even if they have set the option explicitly in their settings (ie they # set it, and then it was disabled removing their ability to change it). But @@ -2297,15 +2290,11 @@ class User { * @param $val mixed New value to set */ public function setOption( $oname, $val ) { - $this->load(); $this->loadOptions(); // Explicitly NULL values should refer to defaults if( is_null( $val ) ) { - $defaultOption = self::getDefaultOption( $oname ); - if( !is_null( $defaultOption ) ) { - $val = $defaultOption; - } + $val = self::getDefaultOption( $oname ); } $this->mOptions[$oname] = $val; diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 8c92f364c7..bf9468ae23 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -187,4 +187,31 @@ class UserTest extends MediaWikiTestCase { $user->clearInstanceCache(); $this->assertEquals( 4, $user->getEditCount(), 'After increasing the edit count manually, the user edit count should be 4' ); } + + /** + * Test changing user options. + */ + public function testOptions() { + $user = User::newFromName( 'UnitTestUser' ); + $user->addToDatabase(); + + $user->setOption( 'someoption', 'test' ); + $user->setOption( 'cols', 200 ); + $user->saveSettings(); + + $user = User::newFromName( 'UnitTestUser' ); + $this->assertEquals( 'test', $user->getOption( 'someoption' ) ); + $this->assertEquals( 200, $user->getOption( 'cols' ) ); + } + + /** + * Bug 37963 + * Make sure defaults are loaded when setOption is called. + */ + public function testAnonOptions() { + global $wgDefaultUserOptions; + $this->user->setOption( 'someoption', 'test' ); + $this->assertEquals( $wgDefaultUserOptions['cols'], $this->user->getOption( 'cols' ) ); + $this->assertEquals( 'test', $this->user->getOption( 'someoption' ) ); + } } -- 2.20.1