Use saveOption from 'mediawiki.api.options'

Change-Id: I33a60cbaf10f5d53a4e49f335ce8f16d108f9dfb
This commit is contained in:
Fomafix 2018-02-03 14:26:17 +01:00
parent 6f1bd995da
commit 61581fa905
3 changed files with 7 additions and 9 deletions

View file

@ -344,6 +344,8 @@
"mmv/mmv.bootstrap.less"
],
"dependencies": [
"mediawiki.api",
"mediawiki.api.options",
"mediawiki.ui.button",
"mediawiki.ui.icon",
"mediawiki.Title",

View file

@ -123,11 +123,7 @@
* @return {jQuery.Promise} a deferred which resolves/rejects on success/failure respectively
*/
CP.setUserPreference = function ( key, value ) {
return this.api.postWithToken( 'options', {
action: 'options',
optionname: key,
optionvalue: value
} );
return this.api.saveOption( key, value );
};
/**

View file

@ -137,14 +137,14 @@
} ),
mwUser = { isAnon: this.sandbox.stub() },
mwConfig = new mw.Map(),
api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) },
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) },
config = new mw.mmv.Config( {}, mwConfig, mwUser, api, localStorage );
mwConfig.set( 'wgMediaViewerEnabledByDefault', false );
mwUser.isAnon.returns( false );
api.postWithToken.returns( $.Deferred().resolve() );
api.saveOption.returns( $.Deferred().resolve() );
config.setMediaViewerEnabledOnClick( false );
assert.ok( api.postWithToken.called, 'For logged-in users, pref change is via API' );
assert.ok( api.saveOption.called, 'For logged-in users, pref change is via API' );
mwUser.isAnon.returns( true );
config.setMediaViewerEnabledOnClick( false );
@ -160,7 +160,7 @@
mwConfig = new mw.Map(),
fakeLocalStorage = mw.mmv.testHelpers.getFakeLocalStorage(),
mwUser = { isAnon: this.sandbox.stub() },
api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) };
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) };
mwConfig.set( {
wgMediaViewer: true,