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 * 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 );
18 delete mw.config.values.wgUserId;
20 assert.strictEqual( mw.user.getName(), null, 'user.getName() returns null when anonymous' );
21 assert.strictEqual( mw.user.name(), null, 'user.name() compatibility' );
22 assert.assertTrue( mw.user.isAnon(), 'user.isAnon() returns true when anonymous' );
23 assert.assertTrue( mw.user.anonymous(), 'user.anonymous() compatibility' );
24 assert.strictEqual( mw.user.getId(), 0, 'user.getId() returns 0 when anonymous' );
26 // Not part of startUp module
27 mw.config.set( 'wgUserName', 'John' );
28 mw.config.set( 'wgUserId', 123 );
30 assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
31 assert.equal( mw.user.name(), 'John', 'user.name() compatibility' );
32 assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
33 assert.assertFalse( mw.user.anonymous(), 'user.anonymous() compatibility' );
34 assert.strictEqual( mw.user.getId(), 123, 'user.getId() returns correct ID when logged-in' );
36 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
39 QUnit.asyncTest( 'getGroups', 3, function ( assert ) {
40 mw.user.getGroups( function ( groups ) {
41 // First group should always be '*'
42 assert.equal( $.type( groups ), 'array', 'Callback gets an array' );
43 assert.notStrictEqual( $.inArray( '*', groups ), -1, '"*"" is in the list' );
44 // Sort needed because of different methods if creating the arrays,
45 // only the content matters.
46 assert.deepEqual( groups.sort(), mw.config.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
51 QUnit.asyncTest( 'getRights', 1, function ( assert ) {
52 mw.user.getRights( function ( rights ) {
53 assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
57 }( mediaWiki, jQuery ) );