2 QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment( {
4 this.server = this.sandbox.useFakeServer();
8 QUnit.test( 'options', 1, function ( assert ) {
9 assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
12 QUnit.test( 'user status', 7, function ( assert ) {
14 // Forge an anonymous user
15 mw.config.set( 'wgUserName', null );
16 delete mw.config.values.wgUserId;
18 assert.strictEqual( mw.user.getName(), null, 'user.getName() returns null when anonymous' );
19 assert.assertTrue( mw.user.isAnon(), 'user.isAnon() returns true when anonymous' );
20 assert.strictEqual( mw.user.getId(), 0, 'user.getId() returns 0 when anonymous' );
22 // Not part of startUp module
23 mw.config.set( 'wgUserName', 'John' );
24 mw.config.set( 'wgUserId', 123 );
26 assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
27 assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
28 assert.strictEqual( mw.user.getId(), 123, 'user.getId() returns correct ID when logged-in' );
30 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
33 QUnit.test( 'getUserInfos', 3, function ( assert ) {
34 mw.user.getGroups( function ( groups ) {
35 assert.deepEqual( groups, [ '*', 'user' ], 'Result' );
38 mw.user.getRights( function ( rights ) {
39 assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (callback)' );
42 mw.user.getRights().done( function ( rights ) {
43 assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (promise)' );
46 this.server.respondWith( /meta=userinfo/, function ( request ) {
47 request.respond( 200, { 'Content-Type': 'application/json' },
48 '{ "query": { "userinfo": { "groups": [ "*", "user" ], "rights": [ "read", "edit", "createtalk" ] } } }'
52 this.server.respond();