diff --git a/includes/Hooks.php b/includes/Hooks.php index 0d8aa77..dac25bc 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -320,7 +320,8 @@ class Hooks { if ( !$isVectorEnabled && array_key_exists( Constants::PREF_KEY_SKIN_VERSION, $oldPreferences ) ) { // The setting was cleared. However, this is likely because a different skin was chosen and // the skin version preference was hidden. - $user->setOption( + MediaWikiServices::getInstance()->getUserOptionsManager()->setOption( + $user, Constants::PREF_KEY_SKIN_VERSION, $oldPreferences[ Constants::PREF_KEY_SKIN_VERSION ] ); @@ -337,7 +338,11 @@ class Hooks { $default = self::getConfig( Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS ); // Permanently set the default preference. The user can later change this preference, however, // self::onLocalUserCreated() will not be executed for that account again. - $user->setOption( Constants::PREF_KEY_SKIN_VERSION, $default ); + MediaWikiServices::getInstance()->getUserOptionsManager()->setOption( + $user, + Constants::PREF_KEY_SKIN_VERSION, + $default + ); } /** diff --git a/tests/phpunit/integration/VectorHooksTest.php b/tests/phpunit/integration/VectorHooksTest.php index f9052af..a40e23e 100644 --- a/tests/phpunit/integration/VectorHooksTest.php +++ b/tests/phpunit/integration/VectorHooksTest.php @@ -4,6 +4,7 @@ * @ingroup skins */ +use MediaWiki\User\UserOptionsManager; use Vector\Constants; use Vector\FeatureManagement\FeatureManager; use Vector\Hooks; @@ -263,8 +264,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { ]; $form = $this->createMock( HTMLForm::class ); $user = $this->createMock( User::class ); - $user->expects( $this->never() ) + $userOptionsManager = $this->createMock( UserOptionsManager::class ); + $userOptionsManager->expects( $this->never() ) ->method( 'setOption' ); + $this->setService( 'UserOptionsManager', $userOptionsManager ); $result = true; $oldPreferences = []; @@ -280,8 +283,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { ]; $form = $this->createMock( HTMLForm::class ); $user = $this->createMock( User::class ); - $user->expects( $this->never() ) + $userOptionsManager = $this->createMock( UserOptionsManager::class ); + $userOptionsManager->expects( $this->never() ) ->method( 'setOption' ); + $this->setService( 'UserOptionsManager', $userOptionsManager ); $result = true; $oldPreferences = []; @@ -297,9 +302,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { ]; $form = $this->createMock( HTMLForm::class ); $user = $this->createMock( User::class ); - $user->expects( $this->once() ) + $userOptionsManager = $this->createMock( UserOptionsManager::class ); + $userOptionsManager->expects( $this->once() ) ->method( 'setOption' ) - ->with( 'VectorSkinVersion', 'old' ); + ->with( $user, 'VectorSkinVersion', 'old' ); + $this->setService( 'UserOptionsManager', $userOptionsManager ); $result = true; $oldPreferences = [ 'VectorSkinVersion' => 'old', @@ -318,9 +325,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { $this->setService( 'Vector.Config', $config ); $user = $this->createMock( User::class ); - $user->expects( $this->once() ) + $userOptionsManager = $this->createMock( UserOptionsManager::class ); + $userOptionsManager->expects( $this->once() ) ->method( 'setOption' ) - ->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LEGACY ); + ->with( $user, 'VectorSkinVersion', Constants::SKIN_VERSION_LEGACY ); + $this->setService( 'UserOptionsManager', $userOptionsManager ); $isAutoCreated = false; Hooks::onLocalUserCreated( $user, $isAutoCreated ); } @@ -335,9 +344,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { $this->setService( 'Vector.Config', $config ); $user = $this->createMock( User::class ); - $user->expects( $this->once() ) + $userOptionsManager = $this->createMock( UserOptionsManager::class ); + $userOptionsManager->expects( $this->once() ) ->method( 'setOption' ) - ->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LATEST ); + ->with( $user, 'VectorSkinVersion', Constants::SKIN_VERSION_LATEST ); + $this->setService( 'UserOptionsManager', $userOptionsManager ); $isAutoCreated = false; Hooks::onLocalUserCreated( $user, $isAutoCreated ); }