Add DROP INDEX support to DatabaseSqlite::replaceVars method
[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 * 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.
14 */
15
16 // Forge an anonymous user:
17 mw.config.set( 'wgUserName', null );
18 delete mw.config.values.wgUserId;
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 assert.strictEqual( mw.user.getId(), 0, 'user.getId() returns 0 when anonymous' );
25
26 // Not part of startUp module
27 mw.config.set( 'wgUserName', 'John' );
28 mw.config.set( 'wgUserId', 123 );
29
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' );
35
36 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
37 } );
38
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' );
47 QUnit.start();
48 } );
49 } );
50
51 QUnit.asyncTest( 'getRights', 1, function ( assert ) {
52 mw.user.getRights( function ( rights ) {
53 assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
54 QUnit.start();
55 } );
56 } );
57 }( mediaWiki, jQuery ) );