summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js
blob: 15265db57dd22aedb27b3ad75bf85e5fa2726748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module( 'mediawiki.user', QUnit.newMwEnvironment() );

test( '-- Initial check', function() {
	expect(1);

	ok( mw.user, 'mw.user defined' );
});


test( 'options', function() {
	expect(1);

	ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
});

test( 'User login status', function() {
	expect(5);

	/**
	 * Tests can be run under three different conditions:
	 *   1) From tests/qunit/index.html, user will be anonymous.
	 *   2) Logged in on [[Special:JavaScriptTest/qunit]]
	 *   3) Anonymously at the same special page.
	 */

	// Forge an anonymous user:
	mw.config.set( 'wgUserName', null);

	strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' );
	ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' );

	// Not part of startUp module
	mw.config.set( 'wgUserName', 'John' );

	equal( mw.user.name(), 'John', 'user.name returns username when logged-in' );
	ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' );

	equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
});