mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Clean up preferences code
- Reference preview preferences should be defined inside Cite - Don't use constants for seldom used strings to make the code more readable. - The lightweght ext.popups module is now always sent to the user This was a micro-optimization and not necessary to do Bug: T365538 Depends-On: Ic479c0a381ee16d1abcecfdd5ee48f0afccc1d3f Change-Id: Ie8fa1672b9fdbb1c6b840dde5c9060a20a625adb
This commit is contained in:
parent
348697630e
commit
fef3740fa5
|
@ -22,7 +22,6 @@
|
||||||
"BeforePageDisplay": "PopupsHooks",
|
"BeforePageDisplay": "PopupsHooks",
|
||||||
"ResourceLoaderGetConfigVars": "PopupsHooks",
|
"ResourceLoaderGetConfigVars": "PopupsHooks",
|
||||||
"GetPreferences": "PopupsHooks",
|
"GetPreferences": "PopupsHooks",
|
||||||
"UserGetDefaultOptions": "PopupsHooks",
|
|
||||||
"MakeGlobalVariablesScript": "PopupsHooks"
|
"MakeGlobalVariablesScript": "PopupsHooks"
|
||||||
},
|
},
|
||||||
"HookHandlers": {
|
"HookHandlers": {
|
||||||
|
@ -58,10 +57,6 @@
|
||||||
"description": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. False by default",
|
"description": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. False by default",
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
"PopupsOptInDefaultState": {
|
|
||||||
"description": "@var string:['1'|'0'] Default Page Previews visibility for old accounts. Has to be a string as a compatibility with beta feature settings. For more info see @T191888",
|
|
||||||
"value": "1"
|
|
||||||
},
|
|
||||||
"PopupsConflictingNavPopupsGadgetName": {
|
"PopupsConflictingNavPopupsGadgetName": {
|
||||||
"description": "@var string: Navigation popups gadget name",
|
"description": "@var string: Navigation popups gadget name",
|
||||||
"value": "Navigation_popups"
|
"value": "Navigation_popups"
|
||||||
|
@ -179,9 +174,7 @@
|
||||||
"includes/ServiceWiring.php"
|
"includes/ServiceWiring.php"
|
||||||
],
|
],
|
||||||
"DefaultUserOptions": {
|
"DefaultUserOptions": {
|
||||||
"popups": "1",
|
"popups": "1"
|
||||||
"popupsreferencepreviews": "0",
|
|
||||||
"popups-reference-previews": "0"
|
|
||||||
},
|
},
|
||||||
"ConditionalUserOptions": {
|
"ConditionalUserOptions": {
|
||||||
"popups": [
|
"popups": [
|
||||||
|
|
|
@ -22,9 +22,5 @@
|
||||||
"prefs-reading": "Reading preferences",
|
"prefs-reading": "Reading preferences",
|
||||||
"popups-prefs-optin": "Enable page previews (get quick previews of a topic while reading a page)",
|
"popups-prefs-optin": "Enable page previews (get quick previews of a topic while reading a page)",
|
||||||
"popups-prefs-disable-nav-gadgets-info": "You have to [[$1|disable the Navigation popups gadget]] in your Gadgets preferences to enable page previews.",
|
"popups-prefs-disable-nav-gadgets-info": "You have to [[$1|disable the Navigation popups gadget]] in your Gadgets preferences to enable page previews.",
|
||||||
"popups-prefs-conflicting-gadgets-info": "Certain gadgets and other customizations may affect the performance of this feature. If you experience problems please review your gadgets and user scripts, including global ones.",
|
"popups-prefs-conflicting-gadgets-info": "Certain gadgets and other customizations may affect the performance of this feature. If you experience problems please review your gadgets and user scripts, including global ones."
|
||||||
"popups-prefs-navpopups-gadget-conflict-info": "You have the [[$1|Navigation popups]] gadget enabled, so you won't see previews provided by this feature. Depending on your wiki, the gadget may have a slightly different name. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
|
||||||
"popups-prefs-reftooltips-gadget-conflict-info": "You have the [[$1|Reference Tooltips]] gadget enabled, so you won't see reference previews but will still see page previews. Depending on your wiki, the gadget may have a slightly different name. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
|
||||||
"popups-prefs-reftooltips-and-navpopups-gadget-conflict-info": "You have the [[$1|Navigation popups]] and [[$1|Reference Tooltips]] gadgets enabled, so you won't see previews provided by this feature. Depending on your wiki, the gadgets may have slightly different names. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
|
||||||
"popups-refpreview-user-preference-label": "Enable reference previews (get quick previews of a reference while reading a page)"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,5 @@
|
||||||
"prefs-reading": "Title for 'Reading preferences' section on preferences page; it's a magic message derived from PREVIEWS_PREFERENCES_SECTION (see commit f597e34)",
|
"prefs-reading": "Title for 'Reading preferences' section on preferences page; it's a magic message derived from PREVIEWS_PREFERENCES_SECTION (see commit f597e34)",
|
||||||
"popups-prefs-optin": "Label for Page Previews option (description for Page Previews option)",
|
"popups-prefs-optin": "Label for Page Previews option (description for Page Previews option)",
|
||||||
"popups-prefs-disable-nav-gadgets-info": "Help message telling to disable the \"Navigation popups\" gadget in order to enable page previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
"popups-prefs-disable-nav-gadgets-info": "Help message telling to disable the \"Navigation popups\" gadget in order to enable page previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
||||||
"popups-prefs-conflicting-gadgets-info": "Help message informing about possible conflicts with other gadgets/customizations",
|
"popups-prefs-conflicting-gadgets-info": "Help message informing about possible conflicts with other gadgets/customizations"
|
||||||
"popups-prefs-navpopups-gadget-conflict-info": "Help message telling to disable the \"Navigation popups\" gadget in order to allow page and reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
|
||||||
"popups-prefs-reftooltips-gadget-conflict-info": "Help message telling to disable the \"Reference Tooltips\" gadget in order to allow reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
|
||||||
"popups-prefs-reftooltips-and-navpopups-gadget-conflict-info": "Help message telling to disable the \"Navigation popups\" and \"Reference Tooltips\" gadgets in order to allow page and reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
|
||||||
"popups-refpreview-user-preference-label": "Label for the user option to enable or disable reference preview popups"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,23 +51,10 @@ class PopupsContext {
|
||||||
*/
|
*/
|
||||||
public const PREVIEWS_DISABLED = false;
|
public const PREVIEWS_DISABLED = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* User preference key to enable/disable Page Previews
|
|
||||||
*/
|
|
||||||
public const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User preference key to enable/disable Reference Previews. Named
|
|
||||||
* "mwe-popups-referencePreviews-enabled" in localStorage for anonymous users.
|
|
||||||
*/
|
|
||||||
public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popups-reference-previews';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags passed on to JS representing preferences
|
* Flags passed on to JS representing preferences
|
||||||
*/
|
*/
|
||||||
private const NAV_POPUPS_ENABLED = 1;
|
private const NAV_POPUPS_ENABLED = 1;
|
||||||
private const REF_TOOLTIPS_ENABLED = 2;
|
|
||||||
private const REFERENCE_PREVIEWS_ENABLED = 4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Config
|
* @var Config
|
||||||
|
@ -145,42 +132,12 @@ class PopupsContext {
|
||||||
return $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
return $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user User whose preferences are checked
|
|
||||||
* @return bool whether or not to show reference previews
|
|
||||||
*/
|
|
||||||
public function isReferencePreviewsEnabled( User $user ) {
|
|
||||||
return !$user->isNamed() || $this->userOptionsLookup->getBoolOption(
|
|
||||||
$user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user User whose preferences are checked
|
* @param User $user User whose preferences are checked
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getConfigBitmaskFromUser( User $user ) {
|
public function getConfigBitmaskFromUser( User $user ) {
|
||||||
return ( $this->conflictsWithNavPopupsGadget( $user ) ? self::NAV_POPUPS_ENABLED : 0 ) |
|
return ( $this->conflictsWithNavPopupsGadget( $user ) ? self::NAV_POPUPS_ENABLED : 0 );
|
||||||
( $this->conflictsWithRefTooltipsGadget( $user ) ? self::REF_TOOLTIPS_ENABLED : 0 ) |
|
|
||||||
( $this->isReferencePreviewsEnabled( $user ) ? self::REFERENCE_PREVIEWS_ENABLED : 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user User whose preferences are checked
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function shouldSendModuleToUser( User $user ) {
|
|
||||||
if ( !$user->isNamed() ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$shouldLoadPagePreviews = $this->userOptionsLookup->getBoolOption(
|
|
||||||
$user,
|
|
||||||
self::PREVIEWS_OPTIN_PREFERENCE_NAME
|
|
||||||
);
|
|
||||||
$shouldLoadReferencePreviews = $this->isReferencePreviewsEnabled( $user );
|
|
||||||
|
|
||||||
return $shouldLoadPagePreviews || $shouldLoadReferencePreviews;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,6 @@ use MediaWiki\Output\Hook\MakeGlobalVariablesScriptHook;
|
||||||
use MediaWiki\Output\OutputPage;
|
use MediaWiki\Output\OutputPage;
|
||||||
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
||||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
||||||
use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
|
|
||||||
use MediaWiki\User\Options\UserOptionsManager;
|
use MediaWiki\User\Options\UserOptionsManager;
|
||||||
use MediaWiki\User\User;
|
use MediaWiki\User\User;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -43,7 +42,6 @@ class PopupsHooks implements
|
||||||
GetPreferencesHook,
|
GetPreferencesHook,
|
||||||
BeforePageDisplayHook,
|
BeforePageDisplayHook,
|
||||||
ResourceLoaderGetConfigVarsHook,
|
ResourceLoaderGetConfigVarsHook,
|
||||||
UserGetDefaultOptionsHook,
|
|
||||||
MakeGlobalVariablesScriptHook
|
MakeGlobalVariablesScriptHook
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -101,10 +99,7 @@ class PopupsHooks implements
|
||||||
}
|
}
|
||||||
|
|
||||||
$skinPosition = array_search( 'skin', array_keys( $prefs ) );
|
$skinPosition = array_search( 'skin', array_keys( $prefs ) );
|
||||||
$readingOptions = array_merge(
|
$readingOptions = $this->getPagePreviewPrefToggle( $user );
|
||||||
$this->getPagePreviewPrefToggle( $user ),
|
|
||||||
$this->getReferencePreviewPrefToggle( $user )
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $skinPosition !== false ) {
|
if ( $skinPosition !== false ) {
|
||||||
$injectIntoIndex = $skinPosition + 1;
|
$injectIntoIndex = $skinPosition + 1;
|
||||||
|
@ -137,43 +132,7 @@ class PopupsHooks implements
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME => $option
|
'popups' => $option
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Reference Preview option
|
|
||||||
*
|
|
||||||
* @param User $user User whose preferences are being modified
|
|
||||||
* @return array[]
|
|
||||||
*/
|
|
||||||
private function getReferencePreviewPrefToggle( User $user ) {
|
|
||||||
$option = [
|
|
||||||
'type' => 'toggle',
|
|
||||||
'label-message' => 'popups-refpreview-user-preference-label',
|
|
||||||
'help-message' => 'popups-prefs-conflicting-gadgets-info',
|
|
||||||
'section' => self::PREVIEWS_PREFERENCES_SECTION
|
|
||||||
];
|
|
||||||
|
|
||||||
$isNavPopupsGadgetEnabled = $this->popupsContext->conflictsWithNavPopupsGadget( $user );
|
|
||||||
$isRefTooltipsGadgetEnabled = $this->popupsContext->conflictsWithRefTooltipsGadget( $user );
|
|
||||||
|
|
||||||
if ( $isNavPopupsGadgetEnabled && $isRefTooltipsGadgetEnabled ) {
|
|
||||||
$option[ 'disabled' ] = true;
|
|
||||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-and-navpopups-gadget-conflict-info',
|
|
||||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
|
||||||
} elseif ( $isNavPopupsGadgetEnabled ) {
|
|
||||||
$option[ 'disabled' ] = true;
|
|
||||||
$option[ 'help-message' ] = [ 'popups-prefs-navpopups-gadget-conflict-info',
|
|
||||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
|
||||||
} elseif ( $isRefTooltipsGadgetEnabled ) {
|
|
||||||
$option[ 'disabled' ] = true;
|
|
||||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-gadget-conflict-info',
|
|
||||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME => $option
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +153,7 @@ class PopupsHooks implements
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $out->getUser();
|
$out->addModules( [ 'ext.popups' ] );
|
||||||
if ( $this->popupsContext->shouldSendModuleToUser( $user ) ) {
|
|
||||||
$out->addModules( [ 'ext.popups' ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,8 +181,6 @@ class PopupsHooks implements
|
||||||
* the users settings. These variables end in an inline <script> in the documents head.
|
* the users settings. These variables end in an inline <script> in the documents head.
|
||||||
*
|
*
|
||||||
* Variables added:
|
* Variables added:
|
||||||
* * `wgPopupsReferencePreviews' - The server's notion of whether or not the reference
|
|
||||||
* previews should be enabled. Depending on the general setting done on the wiki.
|
|
||||||
* * `wgPopupsConflictsWithNavPopupGadget' - The server's notion of whether or not the
|
* * `wgPopupsConflictsWithNavPopupGadget' - The server's notion of whether or not the
|
||||||
* user has enabled conflicting Navigational Popups Gadget.
|
* user has enabled conflicting Navigational Popups Gadget.
|
||||||
* * `wgPopupsConflictsWithRefTooltipsGadget' - The server's notion of whether or not the
|
* * `wgPopupsConflictsWithRefTooltipsGadget' - The server's notion of whether or not the
|
||||||
|
@ -238,15 +192,4 @@ class PopupsHooks implements
|
||||||
public function onMakeGlobalVariablesScript( &$vars, $out ): void {
|
public function onMakeGlobalVariablesScript( &$vars, $out ): void {
|
||||||
$vars['wgPopupsFlags'] = $this->popupsContext->getConfigBitmaskFromUser( $out->getUser() );
|
$vars['wgPopupsFlags'] = $this->popupsContext->getConfigBitmaskFromUser( $out->getUser() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called whenever a user wants to reset their preferences.
|
|
||||||
*
|
|
||||||
* @param array &$defaultOptions
|
|
||||||
*/
|
|
||||||
public function onUserGetDefaultOptions( &$defaultOptions ) {
|
|
||||||
$default = $this->config->get( 'PopupsOptInDefaultState' );
|
|
||||||
$defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
|
|
||||||
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = '1';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,20 +94,6 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers ::shouldSendModuleToUser
|
|
||||||
*/
|
|
||||||
public function testShouldSendToAnonUser() {
|
|
||||||
$user = $this->createMock( User::class );
|
|
||||||
$user->method( 'getId' )->willReturn( self::ANONYMOUS_USER );
|
|
||||||
|
|
||||||
$context = $this->getContext();
|
|
||||||
$this->assertTrue(
|
|
||||||
$context->shouldSendModuleToUser( $user ),
|
|
||||||
'The module is always sent to anonymous users.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::areDependenciesMet
|
* @covers ::areDependenciesMet
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
|
@ -235,30 +221,20 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase {
|
||||||
* @covers ::getConfigBitmaskFromUser
|
* @covers ::getConfigBitmaskFromUser
|
||||||
* @dataProvider provideTestGetConfigBitmaskFromUser
|
* @dataProvider provideTestGetConfigBitmaskFromUser
|
||||||
* @param bool $navPops
|
* @param bool $navPops
|
||||||
* @param bool $refTooltips
|
|
||||||
* @param bool $refEnabled
|
|
||||||
* @param int $expected
|
* @param int $expected
|
||||||
*/
|
*/
|
||||||
public function testGetConfigBitmaskFromUser(
|
public function testGetConfigBitmaskFromUser(
|
||||||
$navPops,
|
$navPops,
|
||||||
$refTooltips,
|
|
||||||
$refEnabled,
|
|
||||||
$expected
|
$expected
|
||||||
) {
|
) {
|
||||||
$contextMock = $this->createPartialMock(
|
$contextMock = $this->createPartialMock(
|
||||||
PopupsContext::class,
|
PopupsContext::class,
|
||||||
[
|
[
|
||||||
'conflictsWithNavPopupsGadget',
|
'conflictsWithNavPopupsGadget'
|
||||||
'conflictsWithRefTooltipsGadget',
|
|
||||||
'isReferencePreviewsEnabled',
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$contextMock->method( 'conflictsWithNavPopupsGadget' )
|
$contextMock->method( 'conflictsWithNavPopupsGadget' )
|
||||||
->willReturn( $navPops );
|
->willReturn( $navPops );
|
||||||
$contextMock->method( 'conflictsWithRefTooltipsGadget' )
|
|
||||||
->willReturn( $refTooltips );
|
|
||||||
$contextMock->method( 'isReferencePreviewsEnabled' )
|
|
||||||
->willReturn( $refEnabled );
|
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$expected,
|
$expected,
|
||||||
|
@ -270,25 +246,9 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
true,
|
true,
|
||||||
true,
|
1,
|
||||||
true,
|
|
||||||
7,
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
2,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
5,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
|
|
|
@ -69,7 +69,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
$contextMock->expects( $this->once() )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'showPreviewsOptInOnPreferencesPage' )
|
->method( 'showPreviewsOptInOnPreferencesPage' )
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
$contextMock->expects( $this->exactly( 2 ) )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'conflictsWithNavPopupsGadget' )
|
->method( 'conflictsWithNavPopupsGadget' )
|
||||||
->with( $userMock )
|
->with( $userMock )
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
|
@ -83,16 +83,16 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
$this->getServiceContainer()->getUserOptionsManager()
|
$this->getServiceContainer()->getUserOptionsManager()
|
||||||
) )
|
) )
|
||||||
->onGetPreferences( $userMock, $prefs );
|
->onGetPreferences( $userMock, $prefs );
|
||||||
$this->assertArrayHasKey( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
$this->assertArrayHasKey( 'popups',
|
||||||
$prefs,
|
$prefs,
|
||||||
'The opt-in preference is retrieved.' );
|
'The opt-in preference is retrieved.' );
|
||||||
$this->assertArrayHasKey( 'disabled',
|
$this->assertArrayHasKey( 'disabled',
|
||||||
$prefs[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ],
|
$prefs[ 'popups' ],
|
||||||
'The opt-in preference has a status.' );
|
'The opt-in preference has a status.' );
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$prefs[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME]['disabled'],
|
$prefs[ 'popups']['disabled'],
|
||||||
'The opt-in preference\'s status is disabled.' );
|
'The opt-in preference\'s status is disabled.' );
|
||||||
$this->assertNotEmpty( $prefs[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME]['help-message'],
|
$this->assertNotEmpty( $prefs[ 'popups']['help-message'],
|
||||||
'The opt-in preference has a help message.' );
|
'The opt-in preference has a help message.' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
$contextMock->expects( $this->once() )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'showPreviewsOptInOnPreferencesPage' )
|
->method( 'showPreviewsOptInOnPreferencesPage' )
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
$contextMock->expects( $this->exactly( 2 ) )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'conflictsWithNavPopupsGadget' )
|
->method( 'conflictsWithNavPopupsGadget' )
|
||||||
->willReturn( false );
|
->willReturn( false );
|
||||||
|
|
||||||
|
@ -125,11 +125,11 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
$this->assertSame( 'notEmpty',
|
$this->assertSame( 'notEmpty',
|
||||||
$prefs[ 'someNotEmptyValue'],
|
$prefs[ 'someNotEmptyValue'],
|
||||||
'Unretrieved preferences are unchanged.' );
|
'Unretrieved preferences are unchanged.' );
|
||||||
$this->assertArrayHasKey( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
$this->assertArrayHasKey( 'popups',
|
||||||
$prefs,
|
$prefs,
|
||||||
'The opt-in preference is retrieved.' );
|
'The opt-in preference is retrieved.' );
|
||||||
$this->assertSame( 1,
|
$this->assertSame( 1,
|
||||||
array_search( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
array_search( 'popups',
|
||||||
array_keys( $prefs ) ),
|
array_keys( $prefs ) ),
|
||||||
'The opt-in preference is injected after Skin select.' );
|
'The opt-in preference is injected after Skin select.' );
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
$contextMock->expects( $this->once() )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'showPreviewsOptInOnPreferencesPage' )
|
->method( 'showPreviewsOptInOnPreferencesPage' )
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
$contextMock->expects( $this->exactly( 2 ) )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'conflictsWithNavPopupsGadget' )
|
->method( 'conflictsWithNavPopupsGadget' )
|
||||||
->willReturn( false );
|
->willReturn( false );
|
||||||
|
|
||||||
|
@ -159,11 +159,11 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
) )
|
) )
|
||||||
->onGetPreferences( $this->createMock( User::class ), $prefs );
|
->onGetPreferences( $this->createMock( User::class ), $prefs );
|
||||||
$this->assertGreaterThan( 2, count( $prefs ), 'A preference is retrieved.' );
|
$this->assertGreaterThan( 2, count( $prefs ), 'A preference is retrieved.' );
|
||||||
$this->assertArrayHasKey( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
$this->assertArrayHasKey( 'popups',
|
||||||
$prefs,
|
$prefs,
|
||||||
'The opt-in preference is retrieved.' );
|
'The opt-in preference is retrieved.' );
|
||||||
$this->assertSame( 2,
|
$this->assertSame( 2,
|
||||||
array_search( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
array_search( 'popups',
|
||||||
array_keys( $prefs ) ),
|
array_keys( $prefs ) ),
|
||||||
'The opt-in preference is appended.' );
|
'The opt-in preference is appended.' );
|
||||||
}
|
}
|
||||||
|
@ -229,12 +229,12 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
|
|
||||||
public static function providerOnBeforePageDisplay() {
|
public static function providerOnBeforePageDisplay() {
|
||||||
return [
|
return [
|
||||||
[ false, false, false ],
|
[ true, false ],
|
||||||
[ true, true, false ],
|
[ true, false ],
|
||||||
// Code not sent if title is excluded
|
// Code not sent if title is excluded
|
||||||
[ true, false, true ],
|
[ false, true ],
|
||||||
// Code not sent if title is excluded
|
// Code not sent if title is excluded
|
||||||
[ false, false, true ]
|
[ false, true ]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
* @covers ::onBeforePageDisplay
|
* @covers ::onBeforePageDisplay
|
||||||
* @dataProvider providerOnBeforePageDisplay
|
* @dataProvider providerOnBeforePageDisplay
|
||||||
*/
|
*/
|
||||||
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
public function testOnBeforePageDisplay(
|
||||||
$isCodeLoaded, $isTitleExcluded ) {
|
$isCodeLoaded, $isTitleExcluded ) {
|
||||||
$skinMock = $this->createMock( Skin::class );
|
$skinMock = $this->createMock( Skin::class );
|
||||||
|
|
||||||
|
@ -262,9 +262,6 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
$contextMock->method( 'shouldSendModuleToUser' )
|
|
||||||
->willReturn( $shouldSendModuleToUser );
|
|
||||||
|
|
||||||
$contextMock->expects( $this->once() )
|
$contextMock->expects( $this->once() )
|
||||||
->method( 'isTitleExcluded' )
|
->method( 'isTitleExcluded' )
|
||||||
->willReturn( $isTitleExcluded );
|
->willReturn( $isTitleExcluded );
|
||||||
|
@ -307,26 +304,4 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
'The wgPopupsFlags global is present and 0.' );
|
'The wgPopupsFlags global is present and 0.' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers ::onUserGetDefaultOptions
|
|
||||||
*/
|
|
||||||
public function testOnUserGetDefaultOptions() {
|
|
||||||
$userOptions = [
|
|
||||||
'test' => 'not_empty'
|
|
||||||
];
|
|
||||||
|
|
||||||
( new PopupsHooks(
|
|
||||||
new HashConfig( [
|
|
||||||
'PopupsOptInDefaultState' => '1',
|
|
||||||
] ),
|
|
||||||
$this->getServiceContainer()->getService( 'Popups.Context' ),
|
|
||||||
$this->getServiceContainer()->getService( 'Popups.Logger' ),
|
|
||||||
$this->getServiceContainer()->getUserOptionsManager()
|
|
||||||
) )
|
|
||||||
->onUserGetDefaultOptions( $userOptions );
|
|
||||||
$this->assertCount( 3, $userOptions );
|
|
||||||
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
|
|
||||||
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue