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', 9, function ( assert
) {
10 * Tests can be run under three different conditions:
11 * 1) From tests/qunit/index.html, user will be anonymous.
12 * 2) Logged in on [[Special:JavaScriptTest/qunit]]
13 * 3) Anonymously at the same special page.
16 // Forge an anonymous user:
17 mw
.config
.set( 'wgUserName', null );
19 assert
.strictEqual( mw
.user
.getName(), null, 'user.getName() returns null when anonymous' );
20 assert
.strictEqual( mw
.user
.name(), null, 'user.name() compatibility' );
21 assert
.assertTrue( mw
.user
.isAnon(), 'user.isAnon() returns true when anonymous' );
22 assert
.assertTrue( mw
.user
.anonymous(), 'user.anonymous() compatibility' );
24 // Not part of startUp module
25 mw
.config
.set( 'wgUserName', 'John' );
27 assert
.equal( mw
.user
.getName(), 'John', 'user.getName() returns username when logged-in' );
28 assert
.equal( mw
.user
.name(), 'John', 'user.name() compatibility' );
29 assert
.assertFalse( mw
.user
.isAnon(), 'user.isAnon() returns false when logged-in' );
30 assert
.assertFalse( mw
.user
.anonymous(), 'user.anonymous() compatibility' );
32 assert
.equal( mw
.user
.id(), 'John', 'user.id Returns username when logged-in' );
35 QUnit
.asyncTest( 'getGroups', 3, function ( assert
) {
36 mw
.user
.getGroups( function ( groups
) {
37 // First group should always be '*'
38 assert
.equal( $.type( groups
), 'array', 'Callback gets an array' );
39 assert
.notStrictEqual( $.inArray( '*', groups
), -1, '"*"" is in the list' );
40 // Sort needed because of different methods if creating the arrays,
41 // only the content matters.
42 assert
.deepEqual( groups
.sort(), mw
.config
.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
47 QUnit
.asyncTest( 'getRights', 1, function ( assert
) {
48 mw
.user
.getRights( function ( rights
) {
49 assert
.equal( $.type( rights
), 'array', 'Callback gets an array' );
53 }( mediaWiki
, jQuery
) );