Merge "Fix ORMRow::insert() on PostgreSQL."
[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', 9, 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
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' );
23
24 // Not part of startUp module
25 mw.config.set( 'wgUserName', 'John' );
26
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' );
31
32 assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
33 } );
34
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' );
43 QUnit.start();
44 } );
45 } );
46
47 QUnit.asyncTest( 'getRights', 1, function ( assert ) {
48 mw.user.getRights( function ( rights ) {
49 assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
50 QUnit.start();
51 } );
52 } );
53 }( mediaWiki, jQuery ) );