mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
Merge "Hygiene: use UserGetDefaultOptions instead of ExtensionRegistration" into mpga
This commit is contained in:
commit
fc2b055934
|
@ -141,19 +141,12 @@ class PopupsHooks {
|
|||
|
||||
/**
|
||||
* Register default preferences for popups
|
||||
*
|
||||
* @param array $wgDefaultUserOptions Reference to default options array
|
||||
*/
|
||||
public static function onExtensionRegistration() {
|
||||
global $wgDefaultUserOptions;
|
||||
/**
|
||||
* We use MainConfig because PopupConfig is not available yet. We cannot use
|
||||
* ExtensionFunctions as it's called too late (see T153280)
|
||||
*
|
||||
* @todo Use ConfigFactory() - when T153280 gets fixed switch it to ExtensionFunctions hook
|
||||
* or when ConfigRegistry gets populated before calling `callback` ExtensionRegistry hook
|
||||
*/
|
||||
$config = \MediaWiki\MediaWikiServices::getInstance()->getMainConfig();
|
||||
public static function onUserGetDefaultOptions( &$wgDefaultUserOptions ) {
|
||||
$wgDefaultUserOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] =
|
||||
$config->get( 'PopupsOptInDefaultState' );
|
||||
PopupsContext::getInstance()->getDefaultIsEnabledState();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
],
|
||||
"GetPreferences": [
|
||||
"PopupsHooks::onGetPreferences"
|
||||
],
|
||||
"UserGetDefaultOptions": [
|
||||
"PopupsHooks::onUserGetDefaultOptions"
|
||||
]
|
||||
},
|
||||
"MessagesDirs": {
|
||||
|
@ -40,7 +43,6 @@
|
|||
"EventLoggingSchemas": {
|
||||
"Popups": 16163887
|
||||
},
|
||||
"callback": "PopupsHooks::onExtensionRegistration",
|
||||
"config": {
|
||||
"@PopupsBetaFeature": "@var bool: Whether the extension should be enabled as an opt-in beta feature. If true, the BetaFeatures extension must be installed. False by default.",
|
||||
"PopupsBetaFeature": false,
|
||||
|
|
|
@ -103,6 +103,17 @@ class PopupsContext {
|
|||
public function isBetaFeatureEnabled() {
|
||||
return $this->config->get( 'PopupsBetaFeature' ) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default Page previews state
|
||||
*
|
||||
* @see PopupsContext::PREVIEWS_ENABLED
|
||||
* @see PopupsContext::PREVIEWS_DISABLED
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultIsEnabledState() {
|
||||
return $this->config->get( 'PopupsOptInDefaultState' );
|
||||
}
|
||||
/**
|
||||
* Are Page previews visible on User Preferences Page
|
||||
*
|
||||
|
|
|
@ -271,4 +271,13 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
$this->assertInstanceOf( PopupsContext::class, $first );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefaultIsEnabledState
|
||||
*/
|
||||
public function testGetDefaultIsEnabledState() {
|
||||
$this->setMwGlobals( [
|
||||
'wgPopupsOptInDefaultState' => "2"
|
||||
] );
|
||||
$this->assertEquals( "2", PopupsContext::getInstance()->getDefaultIsEnabledState() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,16 +150,27 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers PopupsHooks::onExtensionRegistration
|
||||
* @covers PopupsHooks::onUserGetDefaultOptions
|
||||
*/
|
||||
public function testOnExtensionRegistration() {
|
||||
global $wgDefaultUserOptions;
|
||||
public function testOnUserGetDefaultOptions() {
|
||||
$userOptions = [
|
||||
'test' => 'not_empty'
|
||||
];
|
||||
$contextMock = $this->getMockBuilder( PopupsContextTestWrapper::class )
|
||||
->setMethods( [ 'getDefaultIsEnabledState' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$test = 'testValue';
|
||||
$this->setMwGlobals( [ 'wgPopupsOptInDefaultState' => $test ] );
|
||||
PopupsHooks::onExtensionRegistration();
|
||||
$this->assertEquals( $test,
|
||||
$wgDefaultUserOptions[ \Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
|
||||
$contextMock->expects( $this->once() )
|
||||
->method( 'getDefaultIsEnabledState' )
|
||||
->willReturn( true );
|
||||
|
||||
PopupsContextTestWrapper::injectTestInstance( $contextMock );
|
||||
|
||||
PopupsHooks::onUserGetDefaultOptions( $userOptions );
|
||||
$this->assertCount( 2, $userOptions );
|
||||
$this->assertEquals( true,
|
||||
$userOptions[ \Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue