mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Remove BetaFeature code
Popups is out of beta feature and this code is no longer needed. Removing code is the happiest activity a developer can do. Other changes: * Remove redundant type field on extension.json (If not set, the extension will default to the "other" section.) * Repurpose `name` with `namemsg` and make use of existing i18n messages Bug: T193053 Change-Id: Iea832cd1f37b0e7df6ff95efd66e4a1ff2a9004e
This commit is contained in:
parent
d7871bb9c4
commit
4e3282e5ff
|
@ -1,4 +1,4 @@
|
|||
![Popups](images/popups-ltr.svg)
|
||||
![Popups](images/popups.svg)
|
||||
|
||||
# mediawiki/extensions/Popups
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "Popups",
|
||||
"namemsg": "popups-message",
|
||||
"author": [
|
||||
"Prateek Saxena",
|
||||
"Yair Rand"
|
||||
|
@ -7,7 +8,6 @@
|
|||
"url": "https://www.mediawiki.org/wiki/Extension:Popups",
|
||||
"descriptionmsg": "popups-desc",
|
||||
"license-name": "GPL-2.0-or-later",
|
||||
"type": "betafeatures",
|
||||
"requires": {
|
||||
"MediaWiki": ">= 1.30.0"
|
||||
},
|
||||
|
@ -25,9 +25,6 @@
|
|||
"popups": "GlobalVarConfig::newInstance"
|
||||
},
|
||||
"Hooks": {
|
||||
"GetBetaFeaturePreferences": [
|
||||
"Popups\\PopupsHooks::onGetBetaPreferences"
|
||||
],
|
||||
"BeforePageDisplay": [
|
||||
"Popups\\PopupsHooks::onBeforePageDisplay"
|
||||
],
|
||||
|
@ -59,9 +56,7 @@
|
|||
"config": {
|
||||
"@PopupsVirtualPageViews": "@var bool: Whether the extension should log virtual pageviews.",
|
||||
"PopupsVirtualPageViews": false,
|
||||
"@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,
|
||||
"@PopupsHideOptInOnPreferencesPage": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. Please note if PopupsBetaFeature is set to true this option will be always hidden. False by default",
|
||||
"@PopupsHideOptInOnPreferencesPage": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. False by default",
|
||||
"PopupsHideOptInOnPreferencesPage": false,
|
||||
"@PopupsOptInDefaultState": "@var string:['1'|'0'] Default Page Previews visibility. Has to be a string as a compatibility with beta feature settings",
|
||||
"PopupsOptInDefaultState": "0",
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="264" height="162" viewBox="0 0 264 162">
|
||||
<defs>
|
||||
<clipPath id="jagged-edge">
|
||||
<path d="M0 0v152l12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10V0z"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g fill="#eaecf0" clip-path="url(#jagged-edge)" transform="matrix(-1 0 0 1 264 0)">
|
||||
<path id="background" fill="#fff" d="M0 0h264v162H0"/>
|
||||
<path id="logo" d="M11 22c0-8 6-14 14-14s14 6 14 14-6 14-14 14-14-6-14-14M38 45v-5H13v5h25"/>
|
||||
<path id="sidebar" d="M38 163V58H13v106h25"/>
|
||||
<path id="personal-tools" d="M233 5h26v6h-26V5zM209 5h22v6h-22zM185 5h22v6h-22zM162 5h13v6h-13zM177 5h6v6h-6zM154 5h6v6h-6z"/>
|
||||
<g id="search">
|
||||
<path id="input" d="M258 16v4h-92v-4h92m1-1h-94v6h94v-6z"/>
|
||||
<path id="icon" d="M168 17h2v2h-2z"/>
|
||||
</g>
|
||||
<path id="article" d="M252 162V29H48v133z"/>
|
||||
<path id="border" d="M0 0v162h264V0zm1 1h262v150.533l-11 9.166-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-11-9z"/>
|
||||
<path id="article-copy" fill="#72777d" d="M143.756 56h-38.14v7.782h38.14V56zm56.732 35.02v-8.755h-50.814v8.755h50.814zm-89.725-22.374H89.93v8.633h20.832v-8.636zm98.535 7.782v-7.782h-37.695v7.782h37.695zm-88.645 5.716H94.955v7.782h25.698v-7.782zM195.233 56h-46.207v7.782h46.207V56z"/>
|
||||
<path id="article-link" fill="#36c" d="M114.735 68.646v9.2h51.558v-9.2h-51.558z"/>
|
||||
<g id="popup">
|
||||
<path fill="#fff" d="M114 82h75v44h-75z"/>
|
||||
<path fill="#36c" d="M189 82h-31v44h31V82zm-18.167 24.13l5.904 9.652 3.206-2.958 4.83 6.05-21.137.03 6.244-12.775h.953z"/>
|
||||
<g id="copy" fill="#c8ccd1" transform="translate(284 -12)">
|
||||
<rect width="20" height="1" x="-163" y="100" rx="1"/>
|
||||
<rect width="20" height="1" x="-163" y="104" rx="1"/>
|
||||
<rect width="20" height="1" x="-163" y="108" rx="1"/>
|
||||
<rect width="28" height="1" x="-163" y="112" rx="1"/>
|
||||
<rect width="28" height="1" x="-163" y="116" rx="1"/>
|
||||
<rect width="28" height="1" x="-163" y="120" rx="1"/>
|
||||
<rect width="28" height="1" x="-163" y="124" rx="1"/>
|
||||
<rect width="28" height="1" x="-163" y="128" rx="1"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.2 KiB |
|
@ -45,30 +45,22 @@ class PopupsContext {
|
|||
const LOGGER_CHANNEL = 'popups';
|
||||
/**
|
||||
* User preference value for enabled Page Previews
|
||||
* Identical to \HTMLFeatureField::OPTION_ENABLED in BetaFeatures
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PREVIEWS_ENABLED = '1';
|
||||
/**
|
||||
* User preference value for disabled Page Previews
|
||||
* Identical to \HTMLFeatureField::OPTION_DISABLED in BetaFeatures
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PREVIEWS_DISABLED = '0';
|
||||
/**
|
||||
* User preference to enable/disable Page Previews
|
||||
* Currently for BETA and regular opt in we use same preference name
|
||||
* User preference key to enable/disable Page Previews
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
||||
/**
|
||||
* User preference to enable/disable Page Preivews as a beta feature
|
||||
* @var string
|
||||
*/
|
||||
const PREVIEWS_BETA_PREFERENCE_NAME = 'popups';
|
||||
/**
|
||||
* @var \Config
|
||||
*/
|
||||
|
@ -102,14 +94,6 @@ class PopupsContext {
|
|||
public function conflictsWithNavPopupsGadget( \User $user ) {
|
||||
return $this->gadgetsIntegration->conflictsWithNavPopupsGadget( $user );
|
||||
}
|
||||
/**
|
||||
* Is Beta Feature mode enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isBetaFeatureEnabled() {
|
||||
return $this->config->get( 'PopupsBetaFeature' ) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default Page previews state
|
||||
|
@ -127,8 +111,7 @@ class PopupsContext {
|
|||
* @return bool
|
||||
*/
|
||||
public function showPreviewsOptInOnPreferencesPage() {
|
||||
return !$this->isBetaFeatureEnabled()
|
||||
&& $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
||||
return $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,10 +119,6 @@ class PopupsContext {
|
|||
* @return bool
|
||||
*/
|
||||
public function shouldSendModuleToUser( \User $user ) {
|
||||
if ( $this->isBetaFeatureEnabled() ) {
|
||||
return $user->isAnon() ? false :
|
||||
\BetaFeatures::isFeatureEnabled( $user, self::PREVIEWS_BETA_PREFERENCE_NAME );
|
||||
}
|
||||
return $user->isAnon() ? true :
|
||||
$user->getOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME ) === self::PREVIEWS_ENABLED;
|
||||
}
|
||||
|
@ -155,10 +134,6 @@ class PopupsContext {
|
|||
&& $this->extensionRegistry->isLoaded( 'PageImages' );
|
||||
}
|
||||
|
||||
if ( $this->isBetaFeatureEnabled() ) {
|
||||
$areMet = $areMet && $this->extensionRegistry->isLoaded( 'BetaFeatures' );
|
||||
}
|
||||
|
||||
return $areMet;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,33 +33,6 @@ use Skin;
|
|||
class PopupsHooks {
|
||||
const PREVIEWS_PREFERENCES_SECTION = 'rendering/reading';
|
||||
|
||||
/**
|
||||
* Hook executed on retrieving User beta preferences
|
||||
* @param User $user User whose beta preferences are retrieved
|
||||
* @param array &$prefs An associative array of all beta preferences
|
||||
*/
|
||||
static function onGetBetaPreferences( User $user, array &$prefs ) {
|
||||
global $wgExtensionAssetsPath;
|
||||
/** @var PopupsContext $context */
|
||||
$context = MediaWikiServices::getInstance()->getService( 'Popups.Context' );
|
||||
if ( $context->isBetaFeatureEnabled() !== true ) {
|
||||
return;
|
||||
}
|
||||
$prefs[PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME] = [
|
||||
'label-message' => 'popups-message',
|
||||
'desc-message' => 'popups-desc',
|
||||
'screenshot' => [
|
||||
'ltr' => "$wgExtensionAssetsPath/Popups/images/popups-ltr.svg",
|
||||
'rtl' => "$wgExtensionAssetsPath/Popups/images/popups-rtl.svg",
|
||||
],
|
||||
'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Beta_Features/Hovercards',
|
||||
'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Beta_Features/Hovercards',
|
||||
'requirements' => [
|
||||
'javascript' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Page Previews options to user Preferences page
|
||||
*
|
||||
|
@ -116,13 +89,13 @@ class PopupsHooks {
|
|||
|
||||
if ( !$context->areDependenciesMet() ) {
|
||||
$logger = $context->getLogger();
|
||||
$logger->error( 'Popups requires the PageImages and TextExtracts extensions. '
|
||||
. 'If Beta mode is on it requires also BetaFeatures extension' );
|
||||
$logger->error( 'Popups requires the PageImages extensions.
|
||||
TextExtracts extension is required when using mwApiPlain gateway.' );
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $out->getUser();
|
||||
if ( !$context->isBetaFeatureEnabled() || $context->shouldSendModuleToUser( $user ) ) {
|
||||
if ( $context->shouldSendModuleToUser( $user ) ) {
|
||||
$out->addModules( [ 'ext.popups' ] );
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +105,6 @@ class PopupsHooks {
|
|||
*/
|
||||
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
||||
$conf = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$vars['wgPopupsBetaFeature'] = $conf->get( 'PopupsBetaFeature' );
|
||||
$vars['wgPopupsVirtualPageViews'] = $conf->get( 'PopupsVirtualPageViews' );
|
||||
$vars['wgPopupsGateway'] = $conf->get( 'PopupsGateway' );
|
||||
$vars['wgPopupsEventLogging'] = $conf->get( 'PopupsEventLogging' );
|
||||
|
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.json
vendored
BIN
resources/dist/index.js.json
vendored
Binary file not shown.
|
@ -203,7 +203,7 @@ function registerChangeListeners(
|
|||
);
|
||||
const boundActions = Redux.bindActionCreators( actions, store.dispatch );
|
||||
const previewBehavior = createPreviewBehavior(
|
||||
mw.config, mw.user, boundActions
|
||||
mw.user, boundActions
|
||||
);
|
||||
|
||||
registerChangeListeners(
|
||||
|
|
|
@ -9,11 +9,6 @@ import { BUCKETS } from './constants';
|
|||
*
|
||||
* Page Previews is disabled when the Navigation Popups gadget is enabled.
|
||||
*
|
||||
* If Page Previews is configured as a beta feature (see
|
||||
* `$wgPopupsBetaFeature`), the user must be logged in and have enabled the
|
||||
* beta feature in order to see previews. Logged out users won't be able
|
||||
* to see the feature.
|
||||
*
|
||||
* If Page Previews is configured as a user preference, then the user must
|
||||
* either be logged in and have enabled the preference or be logged out and have
|
||||
* not disabled previews via the settings modal. Logged out users who have not
|
||||
|
@ -36,10 +31,6 @@ export default function isEnabled( user, userSettings, config, bucket ) {
|
|||
return config.get( 'wgPopupsShouldSendModuleToUser' );
|
||||
}
|
||||
|
||||
if ( config.get( 'wgPopupsBetaFeature' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !userSettings.hasIsEnabled() ) {
|
||||
return bucket === BUCKETS.on;
|
||||
}
|
||||
|
|
|
@ -26,16 +26,13 @@ const mw = window.mediaWiki,
|
|||
* modal.
|
||||
*
|
||||
* If the user is logged in, then clicking the cog should send them to the
|
||||
* Special:Preferences page with the "Beta features" tab open if Page Previews
|
||||
* is enabled as a beta feature, or the "Appearance" tab otherwise.
|
||||
* the "Appearance" tab otherwise.
|
||||
*
|
||||
* @param {mw.Map} config
|
||||
* @param {mw.User} user
|
||||
* @param {Object} actions The action creators bound to the Redux store
|
||||
* @return {ext.popups.PreviewBehavior}
|
||||
*/
|
||||
export default function createPreviewBehavior( config, user, actions ) {
|
||||
const isBetaFeature = config.get( 'wgPopupsBetaFeature' );
|
||||
export default function createPreviewBehavior( user, actions ) {
|
||||
let settingsUrl, showSettings = $.noop;
|
||||
|
||||
if ( user.isAnon() ) {
|
||||
|
@ -45,8 +42,7 @@ export default function createPreviewBehavior( config, user, actions ) {
|
|||
actions.showSettings();
|
||||
};
|
||||
} else {
|
||||
let rawTitle = 'Special:Preferences#mw-prefsection-';
|
||||
rawTitle += isBetaFeature ? 'betafeatures' : 'rendering';
|
||||
const rawTitle = 'Special:Preferences#mw-prefsection-rendering';
|
||||
|
||||
settingsUrl = mw.Title.newFromText( rawTitle )
|
||||
.getUrl();
|
||||
|
|
|
@ -56,28 +56,6 @@ QUnit.test( 'is should handle logged out users', ( assert ) => {
|
|||
testCase[ 3 ]
|
||||
);
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
config.set( 'wgPopupsBetaFeature', true );
|
||||
|
||||
assert.notOk(
|
||||
isEnabled( user, userSettings, config, BUCKETS.on ),
|
||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
||||
' enabled for logged out users when they are in the on group.'
|
||||
);
|
||||
|
||||
assert.notOk(
|
||||
isEnabled( user, userSettings, config, BUCKETS.control ),
|
||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
||||
' enabled for logged out users when they are not in the control group.'
|
||||
);
|
||||
|
||||
assert.notOk(
|
||||
isEnabled( user, userSettings, config, BUCKETS.off ),
|
||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
||||
' enabled for logged out users when they are in the off group.'
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
||||
|
|
|
@ -15,31 +15,22 @@ QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
|||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( assert ) {
|
||||
QUnit.test( 'it should set the settingsUrl', function ( assert ) {
|
||||
const user = createStubUser( /* isAnon = */ false ),
|
||||
actions = {};
|
||||
|
||||
const cases = [
|
||||
[ true, 'Special:Preferences#mw-prefsection-betafeatures' ],
|
||||
[ false, 'Special:Preferences#mw-prefsection-rendering' ]
|
||||
];
|
||||
|
||||
cases.forEach( ( testCase ) => {
|
||||
this.config.set( 'wgPopupsBetaFeature', testCase[ 0 ] );
|
||||
|
||||
const behavior = createPreviewBehavior( this.config, user, actions );
|
||||
const behavior = createPreviewBehavior( user, actions );
|
||||
|
||||
assert.deepEqual(
|
||||
behavior.settingsUrl,
|
||||
`url/${ testCase[ 1 ] }`
|
||||
'url/Special:Preferences#mw-prefsection-rendering'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
||||
const user = createStubUser( /* isAnon = */ true ),
|
||||
actions = {},
|
||||
behavior = createPreviewBehavior( this.config, user, actions );
|
||||
behavior = createPreviewBehavior( user, actions );
|
||||
|
||||
assert.strictEqual( behavior.settingsUrl, undefined );
|
||||
} );
|
||||
|
@ -47,7 +38,7 @@ QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', funct
|
|||
QUnit.test( 'it shouldn\'t set a showSettings handler if the user is logged in', function ( assert ) {
|
||||
const user = createStubUser( /* isAnon = */ false ),
|
||||
actions = {},
|
||||
behavior = createPreviewBehavior( this.config, user, actions );
|
||||
behavior = createPreviewBehavior( user, actions );
|
||||
|
||||
assert.strictEqual( behavior.showSettings, $.noop );
|
||||
} );
|
||||
|
@ -60,7 +51,7 @@ QUnit.test( 'it should set a showSettings handler if the user is logged out', fu
|
|||
actions = {
|
||||
showSettings: this.sandbox.spy()
|
||||
},
|
||||
behavior = createPreviewBehavior( this.config, user, actions );
|
||||
behavior = createPreviewBehavior( user, actions );
|
||||
|
||||
behavior.showSettings( event );
|
||||
|
||||
|
@ -84,7 +75,7 @@ QUnit.test( 'it should mix in default actions', function ( assert ) {
|
|||
actions.previewShow = () => {};
|
||||
actions.linkClick = () => {};
|
||||
|
||||
const behavior = createPreviewBehavior( this.config, user, actions );
|
||||
const behavior = createPreviewBehavior( user, actions );
|
||||
|
||||
assert.strictEqual( behavior.previewDwell, actions.previewDwell );
|
||||
assert.strictEqual( behavior.previewAbandon, actions.abandon );
|
||||
|
|
|
@ -76,38 +76,27 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
public function provideConfigForShowPreviewsInOptIn() {
|
||||
return [
|
||||
[
|
||||
"options" => [
|
||||
"wgPopupsBetaFeature" => false,
|
||||
[
|
||||
"wgPopupsHideOptInOnPreferencesPage" => false
|
||||
],
|
||||
"expected" => true
|
||||
], [
|
||||
"options" => [
|
||||
"wgPopupsBetaFeature" => true,
|
||||
"wgPopupsHideOptInOnPreferencesPage" => false
|
||||
true
|
||||
],
|
||||
"expected" => false
|
||||
], [
|
||||
"options" => [
|
||||
"wgPopupsBetaFeature" => false,
|
||||
[
|
||||
[
|
||||
"wgPopupsHideOptInOnPreferencesPage" => true
|
||||
],
|
||||
"expected" => false
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::shouldSendModuleToUser
|
||||
* @covers ::isBetaFeatureEnabled
|
||||
* @dataProvider provideTestDataForShouldSendModuleToUser
|
||||
* @param bool $optIn
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testShouldSendModuleToUser( $optIn, $expected ) {
|
||||
$this->setMwGlobals( [
|
||||
"wgPopupsBetaFeature" => false
|
||||
] );
|
||||
$context = $this->getContext();
|
||||
$user = $this->getMutableTestUser()->getUser();
|
||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $optIn );
|
||||
|
@ -130,41 +119,16 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::shouldSendModuleToUser
|
||||
* @covers ::isBetaFeatureEnabled
|
||||
* @dataProvider provideTestDataForShouldSendModuleToUserWhenBetaEnabled
|
||||
* @param bool $optIn
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testShouldSendModuleToUserWhenBetaEnabled( $optIn, $expected ) {
|
||||
if ( !class_exists( 'BetaFeatures' ) ) {
|
||||
$this->markTestSkipped( 'Skipped as BetaFeatures is not available' );
|
||||
}
|
||||
$this->setMwGlobals( [
|
||||
"wgPopupsBetaFeature" => true
|
||||
] );
|
||||
|
||||
$context = $this->getContext();
|
||||
$user = $this->getMutableTestUser()->getUser();
|
||||
$user->setOption( PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME, $optIn );
|
||||
$this->assertEquals( $context->shouldSendModuleToUser( $user ), $expected );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tst Page Previews are disabled for anonymous user
|
||||
* @covers ::shouldSendModuleToUser
|
||||
* @covers ::isBetaFeatureEnabled
|
||||
* @dataProvider providerAnonUserHasDisabledPagePreviews
|
||||
*/
|
||||
public function testAnonUserHasDisabledPagePreviews( $betaFeatureEnabled, $expected ) {
|
||||
public function testAnonUserHasDisabledPagePreviews( $expected ) {
|
||||
$user = $this->getMutableTestUser()->getUser();
|
||||
$user->setId( self::ANONYMOUS_USER );
|
||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
||||
PopupsContext::PREVIEWS_DISABLED );
|
||||
$this->setMwGlobals( [
|
||||
"wgPopupsBetaFeature" => $betaFeatureEnabled,
|
||||
] );
|
||||
|
||||
$context = $this->getContext();
|
||||
$this->assertEquals( $expected, $context->shouldSendModuleToUser( $user ) );
|
||||
|
@ -172,43 +136,24 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
|
||||
public static function providerAnonUserHasDisabledPagePreviews() {
|
||||
return [
|
||||
// If beta feature is enabled we can assume it's opt in only.
|
||||
[ true, false ],
|
||||
// If beta feature is disabled we can assume it's rolled out to everyone.
|
||||
[ false, true ],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @return array/
|
||||
*/
|
||||
public function provideTestDataForShouldSendModuleToUserWhenBetaEnabled() {
|
||||
return [
|
||||
[
|
||||
"optin" => PopupsContext::PREVIEWS_ENABLED,
|
||||
'expected' => true
|
||||
], [
|
||||
"optin" => PopupsContext::PREVIEWS_DISABLED,
|
||||
'expected' => false
|
||||
]
|
||||
// Anons see this by default
|
||||
[ true ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::areDependenciesMet
|
||||
* @dataProvider provideTestDataForTestAreDependenciesMet
|
||||
* @param bool $betaOn
|
||||
* @param bool $textExtracts
|
||||
* @param bool $pageImages
|
||||
* @param bool $betaFeatures
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testAreDependenciesMet( $betaOn, $textExtracts, $pageImages,
|
||||
$betaFeatures, $gateway, $expected ) {
|
||||
public function testAreDependenciesMet( $textExtracts, $pageImages,
|
||||
$gateway, $expected ) {
|
||||
$this->setMwGlobals( [
|
||||
"wgPopupsBetaFeature" => $betaOn,
|
||||
"wgPopupsGateway" => $gateway,
|
||||
] );
|
||||
$returnValues = [ $textExtracts, $pageImages, $betaFeatures ];
|
||||
$returnValues = [ $textExtracts, $pageImages ];
|
||||
|
||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
||||
$mock->expects( $this->any() )
|
||||
|
@ -223,57 +168,31 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function provideTestDataForTestAreDependenciesMet() {
|
||||
return [
|
||||
// Beta is off, dependencies are met even BetaFeatures ext is not available
|
||||
// Dependencies are met
|
||||
[
|
||||
"betaOn" => false,
|
||||
"textExtracts" => true,
|
||||
"pageImages" => true,
|
||||
"betaFeatures" => false,
|
||||
"gateway" => "mwApiPlain",
|
||||
"expected" => true
|
||||
],
|
||||
// textExtracts dep is missing
|
||||
[
|
||||
"betaOn" => false,
|
||||
"textExtracts" => false,
|
||||
"pageImages" => true,
|
||||
"betaFeatures" => false,
|
||||
"gateway" => "mwApiPlain",
|
||||
"expected" => false
|
||||
],
|
||||
// PageImages dep is missing
|
||||
[
|
||||
"betaOn" => false,
|
||||
"textExtracts" => true,
|
||||
"pageImages" => false,
|
||||
"betaFeatures" => false,
|
||||
"gateway" => "mwApiPlain",
|
||||
"expected" => false
|
||||
],
|
||||
// Beta is on but BetaFeatures dep is missing
|
||||
[
|
||||
"betaOn" => true,
|
||||
"textExtracts" => true,
|
||||
"pageImages" => true,
|
||||
"betaFeatures" => false,
|
||||
"gateway" => "mwApiPlain",
|
||||
"expected" => false
|
||||
],
|
||||
// beta is on and all deps are available
|
||||
[
|
||||
"betaOn" => true,
|
||||
"textExtracts" => true,
|
||||
"pageImages" => true,
|
||||
"betaFeatures" => true,
|
||||
"gateway" => "mwApiPlain",
|
||||
"expected" => true
|
||||
],
|
||||
// when Popups uses gateway!=mwApiPlain we don't require PageImages nor TextExtracts
|
||||
[
|
||||
"betaOn" => false,
|
||||
"textExtracts" => false,
|
||||
"pageImages" => false,
|
||||
"betaFeatures" => false,
|
||||
"gateway" => "restbaseHTML",
|
||||
"expected" => true
|
||||
],
|
||||
|
@ -285,7 +204,7 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
* @dataProvider provideTestIsTitleBLacklisted
|
||||
* @param array $blacklist
|
||||
* @param Title $title
|
||||
$ @param bool $expected
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testIsTitleBlacklisted( $blacklist, Title $title, $expected ) {
|
||||
$this->setMwGlobals( [ "wgPopupsPageBlacklist" => $blacklist ] );
|
||||
|
|
|
@ -33,30 +33,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onGetBetaPreferences
|
||||
*/
|
||||
public function testOnGetBetaPreferencesBetaDisabled() {
|
||||
$prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
|
||||
$this->setMwGlobals( [ 'wgPopupsBetaFeature' => false ] );
|
||||
|
||||
PopupsHooks::onGetBetaPreferences( $this->getTestUser()->getUser(), $prefs );
|
||||
$this->assertCount( 1, $prefs );
|
||||
$this->assertEquals( 'notEmpty', $prefs[ 'someNotEmptyValue'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onGetBetaPreferences
|
||||
*/
|
||||
public function testOnGetBetaPreferencesBetaEnabled() {
|
||||
$prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
|
||||
$this->setMwGlobals( [ 'wgPopupsBetaFeature' => true ] );
|
||||
|
||||
PopupsHooks::onGetBetaPreferences( $this->getTestUser()->getUser(), $prefs );
|
||||
$this->assertCount( 2, $prefs );
|
||||
$this->assertArrayHasKey( PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME, $prefs );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onGetPreferences
|
||||
*/
|
||||
|
@ -176,7 +152,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
$config = [
|
||||
'wgPopupsAnonsExperimentalGroupSize' => 0.1,
|
||||
'wgPopupsEventLogging' => false,
|
||||
'wgPopupsBetaFeature' => true,
|
||||
'wgPopupsRestGatewayEndpoint' => '/api',
|
||||
'wgPopupsVirtualPageViews' => true,
|
||||
'wgPopupsGateway' => 'mwApiPlain',
|
||||
|
@ -184,7 +159,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
];
|
||||
$this->setMwGlobals( $config );
|
||||
PopupsHooks::onResourceLoaderGetConfigVars( $vars );
|
||||
$this->assertCount( 8, $vars );
|
||||
$this->assertCount( 7, $vars );
|
||||
|
||||
foreach ( $config as $key => $value ) {
|
||||
$this->assertEquals(
|
||||
|
@ -251,15 +226,12 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
|
||||
public function providerOnBeforePageDisplay() {
|
||||
return [
|
||||
[ false, true, false, false ],
|
||||
[ true, true, true, false ],
|
||||
// if the user doesnt have the feature but the beta feature is disabled
|
||||
// we can assume the user has it (as its rolled out to everyone)
|
||||
[ false, false, true, false ],
|
||||
// If the user has enabled it and the beta feature is disabled
|
||||
// we can assume the code will be loaded.
|
||||
[ true, false, true, false ],
|
||||
[ false, false, false, true ]
|
||||
[ false, false, false ],
|
||||
[ true, true, false ],
|
||||
// Code not sent if title blacklisted
|
||||
[ true, false, true ],
|
||||
// Code not sent if title blacklisted
|
||||
[ false, false, true ]
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -268,7 +240,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
* @dataProvider providerOnBeforePageDisplay
|
||||
*/
|
||||
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
||||
$isBetaFeatureEnabled, $isCodeLoaded, $isTitleBlacklisted ) {
|
||||
$isCodeLoaded, $isTitleBlacklisted ) {
|
||||
$skinMock = $this->getMock( Skin::class );
|
||||
|
||||
$outPageMock = $this->getMock(
|
||||
|
@ -284,7 +256,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
->with( [ 'ext.popups' ] );
|
||||
|
||||
$contextMock = $this->getMockBuilder( PopupsContext::class )
|
||||
->setMethods( [ 'areDependenciesMet', 'isBetaFeatureEnabled',
|
||||
->setMethods( [ 'areDependenciesMet',
|
||||
'shouldSendModuleToUser', 'isTitleBlacklisted' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -295,10 +267,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
->will( $this->returnValue( true ) );
|
||||
}
|
||||
|
||||
$contextMock->expects( $this->any() )
|
||||
->method( 'isBetaFeatureEnabled' )
|
||||
->will( $this->returnValue( $isBetaFeatureEnabled ) );
|
||||
|
||||
$contextMock->expects( $this->any() )
|
||||
->method( 'shouldSendModuleToUser' )
|
||||
->will( $this->returnValue( $shouldSendModuleToUser ) );
|
||||
|
|
Loading…
Reference in a new issue