From 8838da4329d26bf5dd76df77dfe270ccf6586871 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 8 May 2014 12:32:40 +0200 Subject: [PATCH] mediawiki.user.test: Use FakeXHR and clean up The test was quite vague (type array, contain '*') which was because it made an actual API request and that means the actual user and wiki configuration influence it, naturally. Replaced with a mock (also speeds up the test), which lets us do a more appropiate and strict unit test. There was also a test for asserting mw.config 'wgUserGroups' and ApiQueryUserInfo/prop=groups return the same thing. This had to be removed. Not sure where this would belong (if anywhere). Both OutputPage and ApiQueryUserInfo get it from User::getEffectiveGroups(). Change-Id: I052ad0b93e8cef7a27f7020411ba4665132675f5 --- .../mediawiki/mediawiki.user.test.js | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js index e6c2b5c089..0bfd50119d 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js @@ -1,5 +1,9 @@ -( function ( mw, $ ) { - QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() ); +( function ( mw ) { + QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment( { + setup: function () { + this.server = this.sandbox.useFakeServer(); + } + } ) ); QUnit.test( 'options', 1, function ( assert ) { assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' ); @@ -30,30 +34,25 @@ assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' ); } ); - QUnit.asyncTest( 'getGroups', 3, function ( assert ) { + QUnit.test( 'getUserInfos', 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(); + assert.deepEqual( groups, [ '*', 'user' ], 'Result' ); } ); - } ); - - QUnit.test( 'getRights', 2, function ( assert ) { - QUnit.stop(); - QUnit.stop(); mw.user.getRights( function ( rights ) { - assert.equal( $.type( rights ), 'array', 'Callback gets an array' ); - QUnit.start(); + assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (callback)' ); } ); mw.user.getRights().done( function ( rights ) { - assert.equal( $.type( rights ), 'array', 'Using promise interface instead of callback' ); - QUnit.start(); + assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (promise)' ); } ); + + this.server.respondWith( /meta=userinfo/, function ( request ) { + request.respond( 200, { 'Content-Type': 'application/json' }, + '{ "query": { "userinfo": { "groups": [ "*", "user" ], "rights": [ "read", "edit", "createtalk" ] } } }' + ); + } ); + + this.server.respond(); } ); -}( mediaWiki, jQuery ) ); +}( mediaWiki ) ); -- 2.20.1