-( function ( mw, $ ) {
- QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
+( function ( mw ) {
+ QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment( {
+ setup: function () {
+ this.server = this.sandbox.useFakeServer();
+ }
+ } ) );
QUnit.test( 'options', 1, function ( assert ) {
assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
} );
- QUnit.asyncTest( 'getGroups', 3, function ( assert ) {
+ QUnit.test( 'getUserInfos', 3, function ( assert ) {
mw.user.getGroups( function ( groups ) {
- // First group should always be '*'
- assert.equal( $.type( groups ), 'array', 'Callback gets an array' );
- assert.notStrictEqual( $.inArray( '*', groups ), -1, '"*"" is in the list' );
- // Sort needed because of different methods if creating the arrays,
- // only the content matters.
- assert.deepEqual( groups.sort(), mw.config.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
- QUnit.start();
+ assert.deepEqual( groups, [ '*', 'user' ], 'Result' );
} );
- } );
-
- QUnit.test( 'getRights', 2, function ( assert ) {
- QUnit.stop();
- QUnit.stop();
mw.user.getRights( function ( rights ) {
- assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
- QUnit.start();
+ assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (callback)' );
} );
mw.user.getRights().done( function ( rights ) {
- assert.equal( $.type( rights ), 'array', 'Using promise interface instead of callback' );
- QUnit.start();
+ assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (promise)' );
} );
+
+ this.server.respondWith( /meta=userinfo/, function ( request ) {
+ request.respond( 200, { 'Content-Type': 'application/json' },
+ '{ "query": { "userinfo": { "groups": [ "*", "user" ], "rights": [ "read", "edit", "createtalk" ] } } }'
+ );
+ } );
+
+ this.server.respond();
} );
-}( mediaWiki, jQuery ) );
+}( mediaWiki ) );