Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.user.test.js
1 ( function ( mw, $ ) {
2
3 QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
4
5 QUnit.test( 'options', 1, function ( assert ) {
6 assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
7 });
8
9 QUnit.test( 'user status', 9, function ( assert ) {
10 /**
11 * Tests can be run under three different conditions:
12 * 1) From tests/qunit/index.html, user will be anonymous.
13 * 2) Logged in on [[Special:JavaScriptTest/qunit]]
14 * 3) Anonymously at the same special page.
15 */
16
17 // Forge an anonymous user:
18 mw.config.set( 'wgUserName', null );
19
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
25 // Not part of startUp module
26 mw.config.set( 'wgUserName', 'John' );
27
28 assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
29 assert.equal( mw.user.name(), 'John', 'user.name() compatibility' );
30 assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
31 assert.assertFalse( mw.user.anonymous(), 'user.anonymous() compatibility' );
32
33 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
34 });
35
36 QUnit.asyncTest( 'getGroups', 3, function ( assert ) {
37 mw.user.getGroups( function ( groups ) {
38 // First group should always be '*'
39 assert.equal( $.type( groups ), 'array', 'Callback gets an array' );
40 assert.notStrictEqual( $.inArray( '*', groups ), -1, '"*"" is in the list' );
41 // Sort needed because of different methods if creating the arrays,
42 // only the content matters.
43 assert.deepEqual( groups.sort(), mw.config.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
44 QUnit.start();
45 });
46 });
47
48 QUnit.asyncTest( 'getRights', 1, function ( assert ) {
49 mw.user.getRights( function ( rights ) {
50 assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
51 QUnit.start();
52 });
53 });
54
55 }( mediaWiki, jQuery ) );