Merge "Installer: properly override default $wgLogo value"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.user.test.js
1 ( function ( mw, $ ) {
2 QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
3
4 QUnit.test( 'options', 1, function ( assert ) {
5 assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
6 } );
7
8 QUnit.test( 'user status', 11, function ( assert ) {
9
10 // Forge an anonymous user
11 mw.config.set( 'wgUserName', null );
12 delete mw.config.values.wgUserId;
13
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' );
19
20 // Not part of startUp module
21 mw.config.set( 'wgUserName', 'John' );
22 mw.config.set( 'wgUserId', 123 );
23
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' );
29
30 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
31 } );
32
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' );
41 QUnit.start();
42 } );
43 } );
44
45 QUnit.test( 'getRights', 2, function ( assert ) {
46 QUnit.stop();
47 QUnit.stop();
48
49 mw.user.getRights( function ( rights ) {
50 assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
51 QUnit.start();
52 } );
53
54 mw.user.getRights().done( function ( rights ) {
55 assert.equal( $.type( rights ), 'array', 'Using promise interface instead of callback' );
56 QUnit.start();
57 } );
58 } );
59 }( mediaWiki, jQuery ) );