Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.user.test.js
index 79768da..a9bbbf7 100644 (file)
@@ -1,4 +1,4 @@
-( function ( mw ) {
+( function ( mw, $ ) {
 
 QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
 
@@ -6,7 +6,7 @@ QUnit.test( 'options', 1, function ( assert ) {
        assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
 });
 
-QUnit.test( 'User login status', 5, function ( assert ) {
+QUnit.test( 'user status', 9, function ( assert ) {
        /**
         * Tests can be run under three different conditions:
         *   1) From tests/qunit/index.html, user will be anonymous.
@@ -15,18 +15,41 @@ QUnit.test( 'User login status', 5, function ( assert ) {
         */
 
        // Forge an anonymous user:
-       mw.config.set( 'wgUserName', null);
+       mw.config.set( 'wgUserName', null );
 
-       assert.strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' );
-       assert.ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' );
+       assert.strictEqual( mw.user.getName(), null, 'user.getName() returns null when anonymous' );
+       assert.strictEqual( mw.user.name(), null, 'user.name() compatibility' );
+       assert.assertTrue( mw.user.isAnon(), 'user.isAnon() returns true when anonymous' );
+       assert.assertTrue( mw.user.anonymous(), 'user.anonymous() compatibility' );
 
        // Not part of startUp module
        mw.config.set( 'wgUserName', 'John' );
 
-       assert.equal( mw.user.name(), 'John', 'user.name returns username when logged-in' );
-       assert.ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' );
+       assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
+       assert.equal( mw.user.name(), 'John', 'user.name() compatibility' );
+       assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
+       assert.assertFalse( mw.user.anonymous(), 'user.anonymous() compatibility' );
 
        assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
 });
 
-}( mediaWiki ) );
+QUnit.asyncTest( 'getGroups', 3, function ( assert ) {
+       mw.user.getGroups( function ( groups ) {
+               // First group should always be '*'
+               assert.equal( $.type( groups ), 'array', 'Callback gets an array' );
+               assert.notStrictEqual( $.inArray( '*', groups ), -1, '"*"" is in the list' );
+               // Sort needed because of different methods if creating the arrays,
+               // only the content matters.
+               assert.deepEqual( groups.sort(), mw.config.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
+               QUnit.start();
+       });
+});
+
+QUnit.asyncTest( 'getRights', 1, function ( assert ) {
+       mw.user.getRights( function ( rights ) {
+               assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
+               QUnit.start();
+       });
+});
+
+}( mediaWiki, jQuery ) );