mediawiki.api: Prevent misusing #saveOptions
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.options.test.js
index 549deb0..5691a1b 100644 (file)
@@ -1,5 +1,8 @@
 ( function () {
        QUnit.module( 'mediawiki.api.options', QUnit.newMwEnvironment( {
+               config: {
+                       wgUserName: 'Foo'
+               },
                setup: function () {
                        this.server = this.sandbox.useFakeServer();
                        this.server.respondImmediately = true;
                        } )
                );
        } );
+
+       QUnit.test( 'saveOptions (anonymous)', function ( assert ) {
+               var promise, test = this;
+
+               mw.config.set( 'wgUserName', null );
+               promise = new mw.Api().saveOptions( { foo: 'bar' } );
+
+               assert.rejects( promise, /notloggedin/, 'Can not save options while not logged in' );
+
+               return promise
+                       .catch( function () {
+                               return $.Deferred().resolve();
+                       } )
+                       .then( function () {
+                               assert.strictEqual( test.server.requests.length, 0, 'No requests made' );
+                       } );
+       } );
 }() );