2 QUnit
.module( 'mediawiki.user', QUnit
.newMwEnvironment() );
4 QUnit
.test( 'options', 1, function ( assert
) {
5 assert
.ok( mw
.user
.options
instanceof mw
.Map
, 'options instance of mw.Map' );
8 QUnit
.test( 'user status', 11, function ( assert
) {
10 // Forge an anonymous user
11 mw
.config
.set( 'wgUserName', null );
12 delete mw
.config
.values
.wgUserId
;
14 assert
.strictEqual( mw
.user
.getName(), null, 'user.getName() returns null when anonymous' );
15 assert
.strictEqual( mw
.user
.name(), null, 'user.name() compatibility' );
16 assert
.assertTrue( mw
.user
.isAnon(), 'user.isAnon() returns true when anonymous' );
17 assert
.assertTrue( mw
.user
.anonymous(), 'user.anonymous() compatibility' );
18 assert
.strictEqual( mw
.user
.getId(), 0, 'user.getId() returns 0 when anonymous' );
20 // Not part of startUp module
21 mw
.config
.set( 'wgUserName', 'John' );
22 mw
.config
.set( 'wgUserId', 123 );
24 assert
.equal( mw
.user
.getName(), 'John', 'user.getName() returns username when logged-in' );
25 assert
.equal( mw
.user
.name(), 'John', 'user.name() compatibility' );
26 assert
.assertFalse( mw
.user
.isAnon(), 'user.isAnon() returns false when logged-in' );
27 assert
.assertFalse( mw
.user
.anonymous(), 'user.anonymous() compatibility' );
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
.asyncTest( 'getGroups', 3, function ( assert
) {
34 mw
.user
.getGroups( function ( groups
) {
35 // First group should always be '*'
36 assert
.equal( $.type( groups
), 'array', 'Callback gets an array' );
37 assert
.notStrictEqual( $.inArray( '*', groups
), -1, '"*"" is in the list' );
38 // Sort needed because of different methods if creating the arrays,
39 // only the content matters.
40 assert
.deepEqual( groups
.sort(), mw
.config
.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
45 QUnit
.test( 'getRights', 2, function ( assert
) {
49 mw
.user
.getRights( function ( rights
) {
50 assert
.equal( $.type( rights
), 'array', 'Callback gets an array' );
54 mw
.user
.getRights().done( function ( rights
) {
55 assert
.equal( $.type( rights
), 'array', 'Using promise interface instead of callback' );
59 }( mediaWiki
, jQuery
) );