summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki')
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js121
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js388
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js74
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js124
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js40
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js394
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.test.js631
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js57
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js241
9 files changed, 1679 insertions, 391 deletions
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
index e04111f1..a736e121 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
@@ -55,147 +55,146 @@ var config = {
"wgCaseSensitiveNamespaces": []
};
-module( 'mediawiki.Title', QUnit.newMwEnvironment( config ) );
+QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment({ config: config }) );
-test( '-- Initial check', function () {
- expect(1);
- ok( mw.Title, 'mw.Title defined' );
-});
-
-test( 'Transformation', function () {
- expect(8);
+QUnit.test( 'Transformation', 8, function ( assert ) {
var title;
title = new mw.Title( 'File:quux pif.jpg' );
- equal( title.getName(), 'Quux_pif' );
+ assert.equal( title.getName(), 'Quux_pif' );
title = new mw.Title( 'File:Glarg_foo_glang.jpg' );
- equal( title.getNameText(), 'Glarg foo glang' );
+ assert.equal( title.getNameText(), 'Glarg foo glang' );
title = new mw.Title( 'User:ABC.DEF' );
- equal( title.toText(), 'User:ABC.DEF' );
- equal( title.getNamespaceId(), 2 );
- equal( title.getNamespacePrefix(), 'User:' );
+ assert.equal( title.toText(), 'User:ABC.DEF' );
+ assert.equal( title.getNamespaceId(), 2 );
+ assert.equal( title.getNamespacePrefix(), 'User:' );
title = new mw.Title( 'uSEr:hAshAr' );
- equal( title.toText(), 'User:HAshAr' );
- equal( title.getNamespaceId(), 2 );
+ assert.equal( title.toText(), 'User:HAshAr' );
+ assert.equal( title.getNamespaceId(), 2 );
title = new mw.Title( ' MediaWiki: Foo bar .js ' );
// Don't ask why, it's the way the backend works. One space is kept of each set
- equal( title.getName(), 'Foo_bar_.js', "Merge multiple spaces to a single space." );
+ assert.equal( title.getName(), 'Foo_bar_.js', "Merge multiple spaces to a single space." );
});
-test( 'Main text for filename', function () {
- expect(8);
-
+QUnit.test( 'Main text for filename', 8, function ( assert ) {
var title = new mw.Title( 'File:foo_bar.JPG' );
- equal( title.getNamespaceId(), 6 );
- equal( title.getNamespacePrefix(), 'File:' );
- equal( title.getName(), 'Foo_bar' );
- equal( title.getNameText(), 'Foo bar' );
- equal( title.getMain(), 'Foo_bar.JPG' );
- equal( title.getMainText(), 'Foo bar.JPG' );
- equal( title.getExtension(), 'JPG' );
- equal( title.getDotExtension(), '.JPG' );
+ assert.equal( title.getNamespaceId(), 6 );
+ assert.equal( title.getNamespacePrefix(), 'File:' );
+ assert.equal( title.getName(), 'Foo_bar' );
+ assert.equal( title.getNameText(), 'Foo bar' );
+ assert.equal( title.getMain(), 'Foo_bar.JPG' );
+ assert.equal( title.getMainText(), 'Foo bar.JPG' );
+ assert.equal( title.getExtension(), 'JPG' );
+ assert.equal( title.getDotExtension(), '.JPG' );
});
-test( 'Namespace detection and conversion', function () {
- expect(6);
-
+QUnit.test( 'Namespace detection and conversion', 6, function ( assert ) {
var title;
title = new mw.Title( 'something.PDF', 6 );
- equal( title.toString(), 'File:Something.PDF' );
+ assert.equal( title.toString(), 'File:Something.PDF' );
title = new mw.Title( 'NeilK', 3 );
- equal( title.toString(), 'User_talk:NeilK' );
- equal( title.toText(), 'User talk:NeilK' );
+ assert.equal( title.toString(), 'User_talk:NeilK' );
+ assert.equal( title.toText(), 'User talk:NeilK' );
title = new mw.Title( 'Frobisher', 100 );
- equal( title.toString(), 'Penguins:Frobisher' );
+ assert.equal( title.toString(), 'Penguins:Frobisher' );
title = new mw.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
- equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
+ assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
title = new mw.Title( 'Penguins:flightless_yet_cute.jpg' );
- equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
+ assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
});
-test( 'Throw error on invalid title', function () {
- expect(1);
-
- raises(function () {
+QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
+ assert.throws(function () {
var title = new mw.Title( '' );
}, 'Throw error on empty string' );
});
-test( 'Case-sensivity', function () {
- expect(3);
-
+QUnit.test( 'Case-sensivity', 3, function ( assert ) {
var title;
// Default config
mw.config.set( 'wgCaseSensitiveNamespaces', [] );
title = new mw.Title( 'article' );
- equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
+ assert.equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
// $wgCapitalLinks = false;
mw.config.set( 'wgCaseSensitiveNamespaces', [0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15] );
title = new mw.Title( 'article' );
- equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
+ assert.equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
title = new mw.Title( 'john', 2 );
- equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
+ assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
});
-test( 'toString / toText', function () {
- expect(2);
-
+QUnit.test( 'toString / toText', 2, function ( assert ) {
var title = new mw.Title( 'Some random page' );
- equal( title.toString(), title.getPrefixedDb() );
- equal( title.toText(), title.getPrefixedText() );
+ assert.equal( title.toString(), title.getPrefixedDb() );
+ assert.equal( title.toText(), title.getPrefixedText() );
});
-test( 'Exists', function () {
- expect(3);
+QUnit.test( 'getExtension', 7, function ( assert ) {
+
+ function extTest( pagename, ext, description ) {
+ var title = new mw.Title( pagename );
+ assert.equal( title.getExtension(), ext, description || pagename );
+ }
+
+ extTest( 'MediaWiki:Vector.js', 'js' );
+ extTest( 'User:Example/common.css', 'css' );
+ extTest( 'File:Example.longextension', 'longextension', 'Extension parsing not limited (bug 36151)' );
+ extTest( 'Example/information.json', 'json', 'Extension parsing not restricted from any namespace' );
+ extTest( 'Foo.', null, 'Trailing dot is not an extension' );
+ extTest( 'Foo..', null, 'Trailing dots are not an extension' );
+ extTest( 'Foo.a.', null, 'Page name with dots and ending in a dot does not have an extension' );
+ // @broken: Throws an exception
+ // extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
+});
+
+QUnit.test( 'exists', 3, function ( assert ) {
var title;
// Empty registry, checks default to null
title = new mw.Title( 'Some random page', 4 );
- strictEqual( title.exists(), null, 'Return null with empty existance registry' );
+ assert.strictEqual( title.exists(), null, 'Return null with empty existance registry' );
// Basic registry, checks default to boolean
mw.Title.exist.set( ['Does_exist', 'User_talk:NeilK', 'Wikipedia:Sandbox_rules'], true );
mw.Title.exist.set( ['Does_not_exist', 'User:John', 'Foobar'], false );
title = new mw.Title( 'Project:Sandbox rules' );
- assertTrue( title.exists(), 'Return true for page titles marked as existing' );
+ assert.assertTrue( title.exists(), 'Return true for page titles marked as existing' );
title = new mw.Title( 'Foobar' );
- assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );
+ assert.assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );
});
-test( 'Url', function () {
- expect(2);
-
+QUnit.test( 'getUrl', 2, function ( assert ) {
var title;
// Config
mw.config.set( 'wgArticlePath', '/wiki/$1' );
title = new mw.Title( 'Foobar' );
- equal( title.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
+ assert.equal( title.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
title = new mw.Title( 'John Doe', 3 );
- equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
+ assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
});
}() ); \ No newline at end of file
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
new file mode 100644
index 00000000..68a9eafb
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
@@ -0,0 +1,388 @@
+QUnit.module( 'mediawiki.Uri', QUnit.newMwEnvironment({
+ setup: function () {
+ this.mwUriOrg = mw.Uri;
+ mw.Uri = mw.UriRelative( 'http://example.org/w/index.php' );
+ },
+ teardown: function () {
+ mw.Uri = this.mwUriOrg;
+ delete this.mwUriOrg;
+ }
+}) );
+
+$.each( [true, false], function ( i, strictMode ) {
+ QUnit.test( 'Basic mw.Uri object test in ' + ( strictMode ? '' : 'non-' ) + 'strict mode for a simple HTTP URI', 2, function ( assert ) {
+ var uriString, uri;
+ uriString = 'http://www.ietf.org/rfc/rfc2396.txt';
+ uri = new mw.Uri( uriString, {
+ strictMode: strictMode
+ });
+
+ assert.deepEqual(
+ {
+ protocol: uri.protocol,
+ host: uri.host,
+ port: uri.port,
+ path: uri.path,
+ query: uri.query,
+ fragment: uri.fragment
+ }, {
+ protocol: 'http',
+ host: 'www.ietf.org',
+ port: undefined,
+ path: '/rfc/rfc2396.txt',
+ query: {},
+ fragment: undefined
+ },
+ 'basic object properties'
+ );
+
+ assert.deepEqual(
+ {
+ userInfo: uri.getUserInfo(),
+ authority: uri.getAuthority(),
+ hostPort: uri.getHostPort(),
+ queryString: uri.getQueryString(),
+ relativePath: uri.getRelativePath(),
+ toString: uri.toString()
+ },
+ {
+ userInfo: '',
+ authority: 'www.ietf.org',
+ hostPort: 'www.ietf.org',
+ queryString: '',
+ relativePath: '/rfc/rfc2396.txt',
+ toString: uriString
+ },
+ 'construct composite components of URI on request'
+ );
+
+ });
+});
+
+QUnit.test( 'Parse an ftp URI correctly with user and password', 1, function ( assert ) {
+ var uri = new mw.Uri( 'ftp://usr:pwd@192.0.2.16/' );
+
+ assert.deepEqual(
+ {
+ protocol: uri.protocol,
+ user: uri.user,
+ password: uri.password,
+ host: uri.host,
+ port: uri.port,
+ path: uri.path,
+ query: uri.query,
+ fragment: uri.fragment
+ },
+ {
+ protocol: 'ftp',
+ user: 'usr',
+ password: 'pwd',
+ host: '192.0.2.16',
+ port: undefined,
+ path: '/',
+ query: {},
+ fragment: undefined
+ },
+ 'basic object properties'
+ );
+} );
+
+QUnit.test( 'Parse a uri with simple querystring', 1, function ( assert ) {
+ var uri = new mw.Uri( 'http://www.google.com/?q=uri' );
+
+ assert.deepEqual(
+ {
+ protocol: uri.protocol,
+ host: uri.host,
+ port: uri.port,
+ path: uri.path,
+ query: uri.query,
+ fragment: uri.fragment,
+ queryString: uri.getQueryString()
+ },
+ {
+ protocol: 'http',
+ host: 'www.google.com',
+ port: undefined,
+ path: '/',
+ query: { q: 'uri' },
+ fragment: undefined,
+ queryString: 'q=uri'
+ },
+ 'basic object properties'
+ );
+} );
+
+QUnit.test( 'Handle multiple query parameter (overrideKeys on)', 5, function ( assert ) {
+ var uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
+ overrideKeys: true
+ });
+
+ assert.equal( uri.query.n, '1', 'multiple parameters are parsed' );
+ assert.equal( uri.query.m, 'bar', 'last key overrides earlier keys' );
+
+ uri.query.n = [ 'x', 'y', 'z' ];
+
+ // Verify parts and total length instead of entire string because order
+ // of iteration can vary.
+ assert.ok( uri.toString().indexOf( 'm=bar' ), 'toString preserves other values' );
+ assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ), 'toString parameter includes all values of an array query parameter' );
+ assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
+} );
+
+QUnit.test( 'Handle multiple query parameter (overrideKeys off)', 9, function ( assert ) {
+ var uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
+ overrideKeys: false
+ });
+
+ // Strict comparison so that types are also verified (n should be string '1')
+ assert.strictEqual( uri.query.m.length, 2, 'multi-value query should be an array with 2 items' );
+ assert.strictEqual( uri.query.m[0], 'foo', 'order and value is correct' );
+ assert.strictEqual( uri.query.m[1], 'bar', 'order and value is correct' );
+ assert.strictEqual( uri.query.n, '1', 'n=1 is parsed with the correct value of the expected type' );
+
+ // Change query values
+ uri.query.n = [ 'x', 'y', 'z' ];
+
+ // Verify parts and total length instead of entire string because order
+ // of iteration can vary.
+ assert.ok( uri.toString().indexOf( 'm=foo&m=bar' ) >= 0, 'toString preserves other values' );
+ assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ) >= 0, 'toString parameter includes all values of an array query parameter' );
+ assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
+
+ // Remove query values
+ uri.query.m.splice( 0, 1 );
+ delete uri.query.n;
+
+ assert.equal( uri.toString(), 'http://www.example.com/dir/?m=bar', 'deletion properties' );
+
+ // Remove more query values, leaving an empty array
+ uri.query.m.splice( 0, 1 );
+ assert.equal( uri.toString(), 'http://www.example.com/dir/', 'empty array value is ommitted' );
+} );
+
+QUnit.test( 'All-dressed URI with everything', 11, function ( assert ) {
+ var uri, queryString, relativePath;
+
+ uri = new mw.Uri( 'http://auth@www.example.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top' );
+
+ assert.deepEqual(
+ {
+ protocol: uri.protocol,
+ user: uri.user,
+ password: uri.password,
+ host: uri.host,
+ port: uri.port,
+ path: uri.path,
+ query: uri.query,
+ fragment: uri.fragment
+ },
+ {
+ protocol: 'http',
+ user: 'auth',
+ password: undefined,
+ host: 'www.example.com',
+ port: '81',
+ path: '/dir/dir.2/index.htm',
+ query: { q1: '0', test1: null, test2: 'value (escaped)' },
+ fragment: 'top'
+ },
+ 'basic object properties'
+ );
+
+ assert.equal( uri.getUserInfo(), 'auth', 'user info' );
+
+ assert.equal( uri.getAuthority(), 'auth@www.example.com:81', 'authority equal to auth@hostport' );
+
+ assert.equal( uri.getHostPort(), 'www.example.com:81', 'hostport equal to host:port' );
+
+ queryString = uri.getQueryString();
+ assert.ok( queryString.indexOf( 'q1=0' ) >= 0, 'query param with numbers' );
+ assert.ok( queryString.indexOf( 'test1' ) >= 0, 'query param with null value is included' );
+ assert.ok( queryString.indexOf( 'test1=' ) === -1, 'query param with null value does not generate equals sign' );
+ assert.ok( queryString.indexOf( 'test2=value+%28escaped%29' ) >= 0, 'query param is url escaped' );
+
+ relativePath = uri.getRelativePath();
+ assert.ok( relativePath.indexOf( uri.path ) >= 0, 'path in relative path' );
+ assert.ok( relativePath.indexOf( uri.getQueryString() ) >= 0, 'query string in relative path' );
+ assert.ok( relativePath.indexOf( uri.fragment ) >= 0, 'fragement in relative path' );
+} );
+
+QUnit.test( 'Cloning', 6, function ( assert ) {
+ var original, clone;
+
+ original = new mw.Uri( 'http://foo.example.org/index.php?one=1&two=2' );
+ clone = original.clone();
+
+ assert.deepEqual( clone, original, 'clone has equivalent properties' );
+ assert.equal( original.toString(), clone.toString(), 'toString matches original' );
+
+ assert.notStrictEqual( clone, original, 'clone is a different object when compared by reference' );
+
+ clone.host = 'bar.example.org';
+ assert.notEqual( original.host, clone.host, 'manipulating clone did not effect original' );
+ assert.notEqual( original.toString(), clone.toString(), 'Stringified url no longer matches original' );
+
+ clone.query.three = 3;
+
+ assert.deepEqual(
+ original.query,
+ { 'one': '1', 'two': '2' },
+ 'Properties is deep cloned (bug 37708)'
+ );
+} );
+
+QUnit.test( 'Constructing mw.Uri from plain object', 3, function ( assert ) {
+ var uri = new mw.Uri({
+ protocol: 'http',
+ host: 'www.foo.local',
+ path: '/this'
+ });
+ assert.equal( uri.toString(), 'http://www.foo.local/this', 'Basic properties' );
+
+ uri = new mw.Uri({
+ protocol: 'http',
+ host: 'www.foo.local',
+ path: '/this',
+ query: { hi: 'there' },
+ fragment: 'blah'
+ });
+ assert.equal( uri.toString(), 'http://www.foo.local/this?hi=there#blah', 'More complex properties' );
+
+ assert.throws(
+ function () {
+ var uri = new mw.Uri({
+ protocol: 'http',
+ host: 'www.foo.local'
+ });
+ },
+ function ( e ) {
+ return e.message === 'Bad constructor arguments';
+ },
+ 'Construction failed when missing required properties'
+ );
+} );
+
+QUnit.test( 'Manipulate properties', 8, function ( assert ) {
+ var uriBase, uri;
+
+ uriBase = new mw.Uri( 'http://en.wiki.local/w/api.php' );
+
+ uri = uriBase.clone();
+ uri.fragment = 'frag';
+ assert.equal( uri.toString(), 'http://en.wiki.local/w/api.php#frag', 'add a fragment' );
+
+ uri = uriBase.clone();
+ uri.host = 'fr.wiki.local';
+ uri.port = '8080';
+ assert.equal( uri.toString(), 'http://fr.wiki.local:8080/w/api.php', 'change host and port' );
+
+ uri = uriBase.clone();
+ uri.query.foo = 'bar';
+ assert.equal( uri.toString(), 'http://en.wiki.local/w/api.php?foo=bar', 'add query arguments' );
+
+ delete uri.query.foo;
+ assert.equal( uri.toString(), 'http://en.wiki.local/w/api.php', 'delete query arguments' );
+
+ uri = uriBase.clone();
+ uri.query.foo = 'bar';
+ assert.equal( uri.toString(), 'http://en.wiki.local/w/api.php?foo=bar', 'extend query arguments' );
+ uri.extend({
+ foo: 'quux',
+ pif: 'paf'
+ });
+ assert.ok( uri.toString().indexOf( 'foo=quux' ) >= 0, 'extend query arguments' );
+ assert.ok( uri.toString().indexOf( 'foo=bar' ) === -1, 'extend query arguments' );
+ assert.ok( uri.toString().indexOf( 'pif=paf' ) >= 0 , 'extend query arguments' );
+} );
+
+QUnit.test( 'Handle protocol-relative URLs', 5, function ( assert ) {
+ var UriRel, uri;
+
+ UriRel = mw.UriRelative( 'glork://en.wiki.local/foo.php' );
+
+ uri = new UriRel( '//en.wiki.local/w/api.php' );
+ assert.equal( uri.protocol, 'glork', 'create protocol-relative URLs with same protocol as document' );
+
+ uri = new UriRel( '/foo.com' );
+ assert.equal( uri.toString(), 'glork://en.wiki.local/foo.com', 'handle absolute paths by supplying protocol and host from document in loose mode' );
+
+ uri = new UriRel( 'http:/foo.com' );
+ assert.equal( uri.toString(), 'http://en.wiki.local/foo.com', 'handle absolute paths by supplying host from document in loose mode' );
+
+ uri = new UriRel( '/foo.com', true );
+ assert.equal( uri.toString(), 'glork://en.wiki.local/foo.com', 'handle absolute paths by supplying protocol and host from document in strict mode' );
+
+ uri = new UriRel( 'http:/foo.com', true );
+ assert.equal( uri.toString(), 'http://en.wiki.local/foo.com', 'handle absolute paths by supplying host from document in strict mode' );
+} );
+
+QUnit.test( 'Bad calls', 3, function ( assert ) {
+ var uri;
+
+ assert.throws(
+ function () {
+ return new mw.Uri( 'glaswegian penguins' );
+ },
+ function ( e ) {
+ return e.message === 'Bad constructor arguments';
+ },
+ 'throw error on non-URI as argument to constructor'
+ );
+
+ assert.throws(
+ function () {
+ return new mw.Uri( 'foo.com/bar/baz', {
+ strictMode: true
+ });
+ },
+ function ( e ) {
+ return e.message === 'Bad constructor arguments';
+ },
+ 'throw error on URI without protocol or // or leading / in strict mode'
+ );
+
+ uri = new mw.Uri( 'foo.com/bar/baz', {
+ strictMode: false
+ });
+ assert.equal( uri.toString(), 'http://foo.com/bar/baz', 'normalize URI without protocol or // in loose mode' );
+});
+
+QUnit.test( 'bug 35658', 2, function ( assert ) {
+ var testProtocol, testServer, testPort, testPath, UriClass, uri, href;
+
+ testProtocol = 'https://';
+ testServer = 'foo.example.org';
+ testPort = '3004';
+ testPath = '/!1qy';
+
+ UriClass = mw.UriRelative( testProtocol + testServer + '/some/path/index.html' );
+ uri = new UriClass( testPath );
+ href = uri.toString();
+ assert.equal( href, testProtocol + testServer + testPath, 'Root-relative URL gets host & protocol supplied' );
+
+ UriClass = mw.UriRelative( testProtocol + testServer + ':' + testPort + '/some/path.php' );
+ uri = new UriClass( testPath );
+ href = uri.toString();
+ assert.equal( href, testProtocol + testServer + ':' + testPort + testPath, 'Root-relative URL gets host, protocol, and port supplied' );
+
+} );
+
+QUnit.test( 'Constructor falls back to default location', 4, function ( assert ) {
+ var testuri, MyUri, uri;
+
+ testuri = 'http://example.org/w/index.php';
+ MyUri = mw.UriRelative( testuri );
+
+ uri = new MyUri();
+ assert.equal( uri.toString(), testuri, 'no arguments' );
+
+ uri = new MyUri( undefined );
+ assert.equal( uri.toString(), testuri, 'undefined' );
+
+ uri = new MyUri( null );
+ assert.equal( uri.toString(), testuri, 'null' );
+
+ uri = new MyUri( '' );
+ assert.equal( uri.toString(), testuri, 'empty string' );
+} );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js
new file mode 100644
index 00000000..e2c66685
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js
@@ -0,0 +1,74 @@
+QUnit.module( 'mediawiki.cldr', QUnit.newMwEnvironment() );
+
+var pluralTestcases = {
+ /*
+ * Sample:
+ * "languagecode" : [
+ * [ number, [ "form1", "form2", ... ], "expected", "description" ]
+ * ];
+ */
+ "en": [
+ [ 0, [ "one", "other" ], "other", "English plural test- 0 is other" ],
+ [ 1, [ "one", "other" ], "one", "English plural test- 1 is one" ]
+ ],
+ "fa": [
+ [ 0, [ "one", "other" ], "other", "Persian plural test- 0 is other" ],
+ [ 1, [ "one", "other" ], "one", "Persian plural test- 1 is one" ],
+ [ 2, [ "one", "other" ], "other", "Persian plural test- 2 is other" ]
+ ],
+ "fr": [
+ [ 0, [ "one", "other" ], "other", "French plural test- 0 is other" ],
+ [ 1, [ "one", "other" ], "one", "French plural test- 1 is one" ]
+ ],
+ "hi": [
+ [ 0, [ "one", "other" ], "one", "Hindi plural test- 0 is one" ],
+ [ 1, [ "one", "other" ], "one", "Hindi plural test- 1 is one" ],
+ [ 2, [ "one", "other" ], "other", "Hindi plural test- 2 is other" ]
+ ],
+ "he": [
+ [ 0, [ "one", "other" ], "other", "Hebrew plural test- 0 is other" ],
+ [ 1, [ "one", "other" ], "one", "Hebrew plural test- 1 is one" ],
+ [ 2, [ "one", "other" ], "other", "Hebrew plural test- 2 is other with 2 forms" ],
+ [ 2, [ "one", "dual", "other" ], "dual", "Hebrew plural test- 2 is dual with 3 forms" ]
+ ],
+ "hu": [
+ [ 0, [ "one", "other" ], "other", "Hungarian plural test- 0 is other" ],
+ [ 1, [ "one", "other" ], "one", "Hungarian plural test- 1 is one" ],
+ [ 2, [ "one", "other" ], "other", "Hungarian plural test- 2 is other" ]
+ ],
+ "ar": [
+ [ 0, [ "zero", "one", "two", "few", "many", "other" ], "zero", "Arabic plural test - 0 is zero" ],
+ [ 1, [ "zero", "one", "two", "few", "many", "other" ], "one", "Arabic plural test - 1 is one" ],
+ [ 2, [ "zero", "one", "two", "few", "many", "other" ], "two", "Arabic plural test - 2 is two" ],
+ [ 3, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 3 is few" ],
+ [ 9, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
+ [ "9", [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 9 is few" ],
+ [ 110, [ "zero", "one", "two", "few", "many", "other" ], "few", "Arabic plural test - 110 is few" ],
+ [ 11, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 11 is many" ],
+ [ 15, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 15 is many" ],
+ [ 99, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 99 is many" ],
+ [ 9999, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 9999 is many" ],
+ [ 100, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 100 is other" ],
+ [ 102, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 102 is other" ],
+ [ 1000, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1000 is other" ],
+ [ 1.7, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1.7 is other" ]
+ ]
+};
+
+function pluralTest( langCode, tests ) {
+ QUnit.test( 'Plural Test for ' + langCode, tests.length, function ( assert ) {
+ for ( var i = 0; i < tests.length; i++ ) {
+ assert.equal(
+ mw.language.convertPlural( tests[i][0], tests[i][1] ),
+ tests[i][2],
+ tests[i][3]
+ );
+ }
+ } );
+}
+
+$.each( pluralTestcases, function ( langCode, tests ) {
+ if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
+ pluralTest( langCode, tests );
+ }
+} );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
index 265ec2ae..b8193a92 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
@@ -1,43 +1,97 @@
-module( 'mediawiki.jqueryMsg' );
+QUnit.module( 'mediawiki.jqueryMsg' );
-test( '-- Initial check', function() {
- expect( 1 );
- ok( mw.jqueryMsg, 'mw.jqueryMsg defined' );
-} );
-
-test( 'mw.jqueryMsg Plural', function() {
- expect( 5 );
+QUnit.test( 'mw.jqueryMsg Plural', 3, function ( assert ) {
var parser = mw.jqueryMsg.getMessageFunction();
- ok( parser, 'Parser Function initialized' );
- ok( mw.messages.set( 'plural-msg', 'Found $1 {{PLURAL:$1|item|items}}' ), 'mw.messages.set: Register' );
- equal( parser( 'plural-msg', 0 ) , 'Found 0 items', 'Plural test for english with zero as count' );
- equal( parser( 'plural-msg', 1 ) , 'Found 1 item', 'Singular test for english' );
- equal( parser( 'plural-msg', 2 ) , 'Found 2 items', 'Plural test for english' );
+
+ mw.messages.set( 'plural-msg', 'Found $1 {{PLURAL:$1|item|items}}' );
+ assert.equal( parser( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
+ assert.equal( parser( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
+ assert.equal( parser( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
} );
-test( 'mw.jqueryMsg Gender', function() {
- expect( 16 );
- //TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
- var user = mw.user;
+QUnit.test( 'mw.jqueryMsg Gender', 11, function ( assert ) {
+ // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
+ // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
+ var user = mw.user,
+ parser = mw.jqueryMsg.getMessageFunction();
+
+ // The values here are not significant,
+ // what matters is which of the values is choosen by the parser
+ mw.messages.set( 'gender-msg', '$1: {{GENDER:$2|blue|pink|green}}' );
+
user.options.set( 'gender', 'male' );
- var parser = mw.jqueryMsg.getMessageFunction();
- ok( parser, 'Parser Function initialized' );
- //TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
- ok( mw.messages.set( 'gender-msg', '$1 reverted {{GENDER:$2|his|her|their}} last edit' ), 'mw.messages.set: Register' );
- equal( parser( 'gender-msg', 'Bob', 'male' ) , 'Bob reverted his last edit', 'Gender masculine' );
- equal( parser( 'gender-msg', 'Bob', user ) , 'Bob reverted his last edit', 'Gender masculine' );
+ assert.equal(
+ parser( 'gender-msg', 'Bob', 'male' ),
+ 'Bob: blue',
+ 'Masculine from string "male"'
+ );
+ assert.equal(
+ parser( 'gender-msg', 'Bob', user ),
+ 'Bob: blue',
+ 'Masculine from mw.user object'
+ );
+
user.options.set( 'gender', 'unknown' );
- equal( parser( 'gender-msg', 'They', user ) , 'They reverted their last edit', 'Gender neutral or unknown' );
- equal( parser( 'gender-msg', 'Alice', 'female' ) , 'Alice reverted her last edit', 'Gender feminine' );
- equal( parser( 'gender-msg', 'User' ) , 'User reverted their last edit', 'Gender neutral' );
- equal( parser( 'gender-msg', 'User', 'unknown' ) , 'User reverted their last edit', 'Gender neutral' );
- ok( mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}} reverted last $2 {{PLURAL:$2|edit|edits}}' ), 'mw.messages.set: Register' );
- equal( parser( 'gender-msg-one-form', 'male', 10 ) , 'User reverted last 10 edits', 'Gender neutral and plural form' );
- equal( parser( 'gender-msg-one-form', 'female', 1 ) , 'User reverted last 1 edit', 'Gender neutral and singular form' );
- ok( mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' ), 'mw.messages.set: Register' );
- equal( parser( 'gender-msg-lowercase', 'male' ) , 'he is awesome', 'Gender masculine' );
- equal( parser( 'gender-msg-lowercase', 'female' ) , 'she is awesome', 'Gender feminine' );
- ok( mw.messages.set( 'gender-msg-wrong', '{{gender}} is awesome' ), 'mw.messages.set: Register' );
- equal( parser( 'gender-msg-wrong', 'female' ) , ' is awesome', 'Wrong syntax used, but ignore the {{gender}}' );
+ assert.equal(
+ parser( 'gender-msg', 'Foo', user ),
+ 'Foo: green',
+ 'Neutral from mw.user object' );
+ assert.equal(
+ parser( 'gender-msg', 'Alice', 'female' ),
+ 'Alice: pink',
+ 'Feminine from string "female"' );
+ assert.equal(
+ parser( 'gender-msg', 'User' ),
+ 'User: green',
+ 'Neutral when no parameter given' );
+ assert.equal(
+ parser( 'gender-msg', 'User', 'unknown' ),
+ 'User: green',
+ 'Neutral from string "unknown"'
+ );
+
+ mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
+
+ assert.equal(
+ parser( 'gender-msg-one-form', 'male', 10 ),
+ 'User: 10 edits',
+ 'Gender neutral and plural form'
+ );
+ assert.equal(
+ parser( 'gender-msg-one-form', 'female', 1 ),
+ 'User: 1 edit',
+ 'Gender neutral and singular form'
+ );
+
+ mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
+ assert.equal(
+ parser( 'gender-msg-lowercase', 'male' ),
+ 'he is awesome',
+ 'Gender masculine'
+ );
+ assert.equal(
+ parser( 'gender-msg-lowercase', 'female' ),
+ 'she is awesome',
+ 'Gender feminine'
+ );
+
+ mw.messages.set( 'gender-msg-wrong', '{{gender}} test' );
+ assert.equal(
+ parser( 'gender-msg-wrong', 'female' ),
+ ' test',
+ 'Invalid syntax should result in {{gender}} simply being stripped away'
+ );
+} );
+
+
+QUnit.test( 'mw.jqueryMsg Grammar', 2, function ( assert ) {
+ var parser = mw.jqueryMsg.getMessageFunction();
+
+ // Assume the grammar form grammar_case_foo is not valid in any language
+ mw.messages.set( 'grammar-msg', 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}' );
+ assert.equal( parser( 'grammar-msg' ), 'Przeszukaj ' + mw.config.get( 'wgSiteName' ), 'Grammar Test with sitename' );
+
+ mw.messages.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
+ assert.equal( parser( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ' , 'Grammar Test with wrong grammar template syntax' );
} );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
index 24005b64..2baa4f37 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
@@ -1,24 +1,24 @@
/* Some misc JavaScript compatibility tests, just to make sure the environments we run in are consistent */
-module( 'mediawiki.jscompat', QUnit.newMwEnvironment() );
+QUnit.module( 'mediawiki.jscompat', QUnit.newMwEnvironment() );
-test( 'Variable with Unicode letter in name', function() {
- expect(3);
+QUnit.test( 'Variable with Unicode letter in name', 3, function ( assert ) {
var orig = "some token";
var ŝablono = orig;
- deepEqual( ŝablono, orig, 'ŝablono' );
- deepEqual( \u015dablono, orig, '\\u015dablono' );
- deepEqual( \u015Dablono, orig, '\\u015Dablono' );
+
+ assert.deepEqual( ŝablono, orig, 'ŝablono' );
+ assert.deepEqual( \u015dablono, orig, '\\u015dablono' );
+ assert.deepEqual( \u015Dablono, orig, '\\u015Dablono' );
});
/*
// Not that we need this. ;)
// This fails on IE 6-8
// Works on IE 9, Firefox 6, Chrome 14
-test( 'Keyword workaround: "if" as variable name using Unicode escapes', function() {
+QUnit.test( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
var orig = "another token";
\u0069\u0066 = orig;
- deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
+ assert.deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
});
*/
@@ -26,37 +26,37 @@ test( 'Keyword workaround: "if" as variable name using Unicode escapes', functio
// Not that we need this. ;)
// This fails on IE 6-9
// Works on Firefox 6, Chrome 14
-test( 'Keyword workaround: "if" as member variable name using Unicode escapes', function() {
+QUnit.test( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
var orig = "another token";
var foo = {};
foo.\u0069\u0066 = orig;
- deepEqual( foo.\u0069\u0066, orig, 'foo.\\u0069\\u0066' );
+ assert.deepEqual( foo.\u0069\u0066, orig, 'foo.\\u0069\\u0066' );
});
*/
-test( 'Stripping of single initial newline from textarea\'s literal contents (bug 12130)', function() {
+QUnit.test( 'Stripping of single initial newline from textarea\'s literal contents (bug 12130)', function ( assert ) {
var maxn = 4;
- expect(maxn * 2);
+ QUnit.expect( maxn * 2 );
- var repeat = function(str, n) {
- if (n <= 0) {
+ function repeat( str, n ) {
+ if ( n <= 0 ) {
return '';
} else {
- var out = Array(n);
- for (var i = 0; i < n; i++) {
+ var out = new Array(n);
+ for ( var i = 0; i < n; i++ ) {
out[i] = str;
}
return out.join('');
}
- };
+ }
- for (var n = 0; n < maxn; n++) {
+ for ( var n = 0; n < maxn; n++ ) {
var expected = repeat('\n', n) + 'some text';
var $textarea = $('<textarea>\n' + expected + '</textarea>');
- equal($textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + (n + 1) + ')');
+ assert.equal( $textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + (n + 1) + ')' );
var $textarea2 = $('<textarea>').val(expected);
- equal($textarea2.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')');
+ assert.equal( $textarea2.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')' );
}
});
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
new file mode 100644
index 00000000..3fa2b099
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
@@ -0,0 +1,394 @@
+QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment({
+ setup: function () {
+ this.liveLangData = mw.language.data.values;
+ mw.language.data.values = $.extend( true, {}, this.liveLangData );
+ },
+ teardown: function () {
+ // Restore
+ mw.language.data.values = this.liveLangData;
+ }
+}) );
+
+QUnit.test( 'mw.language getData and setData', function ( assert ) {
+ QUnit.expect( 2 );
+
+ mw.language.setData( 'en', 'testkey', 'testvalue' );
+ assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
+ assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
+} );
+
+function grammarTest( langCode, test ) {
+ // The test works only if the content language is opt.language
+ // because it requires [lang].js to be loaded.
+ QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
+ QUnit.expect( test.length );
+
+ for ( var i = 0 ; i < test.length; i++ ) {
+ assert.equal(
+ mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
+ test[i].expected,
+ test[i].description
+ );
+ }
+ });
+}
+
+var grammarTests = {
+ bs: [
+ {
+ word: 'word',
+ grammarForm: 'instrumental',
+ expected: 's word',
+ description: 'Grammar test for instrumental case'
+ },
+ {
+ word: 'word',
+ grammarForm: 'lokativ',
+ expected: 'o word',
+ description: 'Grammar test for lokativ case'
+ }
+ ],
+
+ he: [
+ {
+ word: "ויקיפדיה",
+ grammarForm: 'prefixed',
+ expected: "וויקיפדיה",
+ description: 'Duplicate the "Waw" if prefixed'
+ },
+ {
+ word: "וולפגנג",
+ grammarForm: 'prefixed',
+ expected: "וולפגנג",
+ description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
+ },
+ {
+ word: "הקובץ",
+ grammarForm: 'prefixed',
+ expected: "קובץ",
+ description: 'Remove the "He" if prefixed'
+ },
+ {
+ word: 'Wikipedia',
+ grammarForm: 'תחילית',
+ expected: '־Wikipedia',
+ description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
+ },
+ {
+ word: '1995',
+ grammarForm: 'תחילית',
+ expected: '־1995',
+ description: 'Add a hyphen (maqaf) before numbers'
+ }
+ ],
+
+ hsb: [
+ {
+ word: 'word',
+ grammarForm: 'instrumental',
+ expected: 'z word',
+ description: 'Grammar test for instrumental case'
+ },
+ {
+ word: 'word',
+ grammarForm: 'lokatiw',
+ expected: 'wo word',
+ description: 'Grammar test for lokatiw case'
+ }
+ ],
+
+ dsb: [
+ {
+ word: 'word',
+ grammarForm: 'instrumental',
+ expected: 'z word',
+ description: 'Grammar test for instrumental case'
+ },
+ {
+ word: 'word',
+ grammarForm: 'lokatiw',
+ expected: 'wo word',
+ description: 'Grammar test for lokatiw case'
+ }
+ ],
+
+ hy: [
+ {
+ word: 'Մաունա',
+ grammarForm: 'genitive',
+ expected: 'Մաունայի',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'հետո',
+ grammarForm: 'genitive',
+ expected: 'հետոյի',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'գիրք',
+ grammarForm: 'genitive',
+ expected: 'գրքի',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'ժամանակի',
+ grammarForm: 'genitive',
+ expected: 'ժամանակիի',
+ description: 'Grammar test for genitive case'
+ }
+ ],
+
+ fi: [
+ {
+ word: 'talo',
+ grammarForm: 'genitive',
+ expected: 'talon',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'linux',
+ grammarForm: 'genitive',
+ expected: 'linuxin',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'talo',
+ grammarForm: 'elative',
+ expected: 'talosta',
+ description: 'Grammar test for elative case'
+ },
+ {
+ word: 'pastöroitu',
+ grammarForm: 'partitive',
+ expected: 'pastöroitua',
+ description: 'Grammar test for partitive case'
+ },
+ {
+ word: 'talo',
+ grammarForm: 'partitive',
+ expected: 'taloa',
+ description: 'Grammar test for partitive case'
+ },
+ {
+ word: 'talo',
+ grammarForm: 'illative',
+ expected: 'taloon',
+ description: 'Grammar test for illative case'
+ },
+ {
+ word: 'linux',
+ grammarForm: 'inessive',
+ expected: 'linuxissa',
+ description: 'Grammar test for inessive case'
+ }
+ ],
+
+ ru: [
+ {
+ word: 'тесть',
+ grammarForm: 'genitive',
+ expected: 'тестя',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'привилегия',
+ grammarForm: 'genitive',
+ expected: 'привилегии',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'установка',
+ grammarForm: 'genitive',
+ expected: 'установки',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'похоти',
+ grammarForm: 'genitive',
+ expected: 'похотей',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'доводы',
+ grammarForm: 'genitive',
+ expected: 'доводов',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'песчаник',
+ grammarForm: 'genitive',
+ expected: 'песчаника',
+ description: 'Grammar test for genitive case'
+ }
+ ],
+
+
+ hu: [
+ {
+ word: 'Wikipédiá',
+ grammarForm: 'rol',
+ expected: 'Wikipédiáról',
+ description: 'Grammar test for rol case'
+ },
+ {
+ word: 'Wikipédiá',
+ grammarForm: 'ba',
+ expected: 'Wikipédiába',
+ description: 'Grammar test for ba case'
+ },
+ {
+ word: 'Wikipédiá',
+ grammarForm: 'k',
+ expected: 'Wikipédiák',
+ description: 'Grammar test for k case'
+ }
+ ],
+
+ ga: [
+ {
+ word: 'an Domhnach',
+ grammarForm: 'ainmlae',
+ expected: 'Dé Domhnaigh',
+ description: 'Grammar test for ainmlae case'
+ },
+ {
+ word: 'an Luan',
+ grammarForm: 'ainmlae',
+ expected: 'Dé Luain',
+ description: 'Grammar test for ainmlae case'
+ },
+ {
+ word: 'an Satharn',
+ grammarForm: 'ainmlae',
+ expected: 'Dé Sathairn',
+ description: 'Grammar test for ainmlae case'
+ }
+ ],
+
+ uk: [
+ {
+ word: 'тесть',
+ grammarForm: 'genitive',
+ expected: 'тестя',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'Вікіпедія',
+ grammarForm: 'genitive',
+ expected: 'Вікіпедії',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'установка',
+ grammarForm: 'genitive',
+ expected: 'установки',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'похоти',
+ grammarForm: 'genitive',
+ expected: 'похотей',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'доводы',
+ grammarForm: 'genitive',
+ expected: 'доводов',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'песчаник',
+ grammarForm: 'genitive',
+ expected: 'песчаника',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'Вікіпедія',
+ grammarForm: 'accusative',
+ expected: 'Вікіпедію',
+ description: 'Grammar test for accusative case'
+ }
+ ],
+
+ sl: [
+ {
+ word: 'word',
+ grammarForm: 'orodnik',
+ expected: 'z word',
+ description: 'Grammar test for orodnik case'
+ },
+ {
+ word: 'word',
+ grammarForm: 'mestnik',
+ expected: 'o word',
+ description: 'Grammar test for mestnik case'
+ }
+ ],
+
+ os: [
+ {
+ word: 'бæстæ',
+ grammarForm: 'genitive',
+ expected: 'бæсты',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'бæстæ',
+ grammarForm: 'allative',
+ expected: 'бæстæм',
+ description: 'Grammar test for allative case'
+ },
+ {
+ word: 'Тигр',
+ grammarForm: 'dative',
+ expected: 'Тигрæн',
+ description: 'Grammar test for dative case'
+ },
+ {
+ word: 'цъити',
+ grammarForm: 'dative',
+ expected: 'цъитийæн',
+ description: 'Grammar test for dative case'
+ },
+ {
+ word: 'лæппу',
+ grammarForm: 'genitive',
+ expected: 'лæппуйы',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: '2011',
+ grammarForm: 'equative',
+ expected: '2011-ау',
+ description: 'Grammar test for equative case'
+ }
+ ],
+
+ la: [
+ {
+ word: 'Translatio',
+ grammarForm: 'genitive',
+ expected: 'Translationis',
+ description: 'Grammar test for genitive case'
+ },
+ {
+ word: 'Translatio',
+ grammarForm: 'accusative',
+ expected: 'Translationem',
+ description: 'Grammar test for accusative case'
+ },
+ {
+ word: 'Translatio',
+ grammarForm: 'ablative',
+ expected: 'Translatione',
+ description: 'Grammar test for ablative case'
+ }
+ ]
+};
+
+$.each( grammarTests, function ( langCode, test ) {
+ if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
+ grammarTest( langCode, test );
+ }
+});
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
index e6934eda..be59f1ad 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -1,71 +1,71 @@
-module( 'mediawiki', QUnit.newMwEnvironment() );
+( function ( mw ) {
-test( '-- Initial check', function() {
- expect(8);
+QUnit.module( 'mediawiki', QUnit.newMwEnvironment() );
- ok( window.jQuery, 'jQuery defined' );
- ok( window.$, '$j defined' );
- ok( window.$j, '$j defined' );
- strictEqual( window.$, window.jQuery, '$ alias to jQuery' );
- strictEqual( window.$j, window.jQuery, '$j alias to jQuery' );
+QUnit.test( 'Initial check', 8, function ( assert ) {
+ assert.ok( window.jQuery, 'jQuery defined' );
+ assert.ok( window.$, '$j defined' );
+ assert.ok( window.$j, '$j defined' );
+ assert.strictEqual( window.$, window.jQuery, '$ alias to jQuery' );
+ assert.strictEqual( window.$j, window.jQuery, '$j alias to jQuery' );
- ok( window.mediaWiki, 'mediaWiki defined' );
- ok( window.mw, 'mw defined' );
- strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
+ assert.ok( window.mediaWiki, 'mediaWiki defined' );
+ assert.ok( window.mw, 'mw defined' );
+ assert.strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
});
-test( 'mw.Map', function() {
- expect(17);
+QUnit.test( 'mw.Map', 17, function ( assert ) {
+ var arry, conf, funky, globalConf, nummy, someValues;
- ok( mw.Map, 'mw.Map defined' );
+ assert.ok( mw.Map, 'mw.Map defined' );
- var conf = new mw.Map(),
- // Dummy variables
- funky = function() {},
- arry = [],
- nummy = 7;
+ conf = new mw.Map();
+ // Dummy variables
+ funky = function () {};
+ arry = [];
+ nummy = 7;
// Tests for input validation
- strictEqual( conf.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' );
- strictEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' );
- strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
- strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
- strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
- equal( conf.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' );
- strictEqual( conf.get( nummy ), null, 'Map.get ruturns null if selection was invalid (Number)' );
- strictEqual( conf.get( funky ), null, 'Map.get ruturns null if selection was invalid (Function)' );
+ assert.strictEqual( conf.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' );
+ assert.strictEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' );
+ assert.strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
+ assert.strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
+ assert.strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
+ assert.equal( conf.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' );
+ assert.strictEqual( conf.get( nummy ), null, 'Map.get ruturns null if selection was invalid (Number)' );
+ assert.strictEqual( conf.get( funky ), null, 'Map.get ruturns null if selection was invalid (Function)' );
// Multiple values at once
- var someValues = {
+ someValues = {
'foo': 'bar',
'lorem': 'ipsum',
'MediaWiki': true
};
- strictEqual( conf.set( someValues ), true, 'Map.set returns boolean true if multiple values were set by passing an object' );
- deepEqual( conf.get( ['foo', 'lorem'] ), {
+ assert.strictEqual( conf.set( someValues ), true, 'Map.set returns boolean true if multiple values were set by passing an object' );
+ assert.deepEqual( conf.get( ['foo', 'lorem'] ), {
'foo': 'bar',
'lorem': 'ipsum'
}, 'Map.get returns multiple values correctly as an object' );
- deepEqual( conf.get( ['foo', 'notExist'] ), {
+ assert.deepEqual( conf.get( ['foo', 'notExist'] ), {
'foo': 'bar',
'notExist': null
}, 'Map.get return includes keys that were not found as null values' );
- strictEqual( conf.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' );
- strictEqual( conf.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' );
+ assert.strictEqual( conf.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' );
+ assert.strictEqual( conf.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' );
// Interacting with globals and accessing the values object
- strictEqual( conf.get(), conf.values, 'Map.get returns the entire values object by reference (if called without arguments)' );
+ assert.strictEqual( conf.get(), conf.values, 'Map.get returns the entire values object by reference (if called without arguments)' );
conf.set( 'globalMapChecker', 'Hi' );
- ok( false === 'globalMapChecker' in window, 'new mw.Map did not store its values in the global window object by default' );
+ assert.ok( false === 'globalMapChecker' in window, 'new mw.Map did not store its values in the global window object by default' );
- var globalConf = new mw.Map( true );
+ globalConf = new mw.Map( true );
globalConf.set( 'anotherGlobalMapChecker', 'Hello' );
- ok( 'anotherGlobalMapChecker' in window, 'new mw.Map( true ) did store its values in the global window object' );
+ assert.ok( 'anotherGlobalMapChecker' in window, 'new mw.Map( true ) did store its values in the global window object' );
// Whitelist this global variable for QUnit's 'noglobal' mode
if ( QUnit.config.noglobals ) {
@@ -73,124 +73,488 @@ test( 'mw.Map', function() {
}
});
-test( 'mw.config', function() {
- expect(1);
-
- ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
+QUnit.test( 'mw.config', 1, function ( assert ) {
+ assert.ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
});
-test( 'mw.message & mw.messages', function() {
- expect(20);
+QUnit.test( 'mw.message & mw.messages', 20, function ( assert ) {
+ var goodbye, hello, pluralMessage;
- ok( mw.messages, 'messages defined' );
- ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
- ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
+ assert.ok( mw.messages, 'messages defined' );
+ assert.ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
+ assert.ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
- var hello = mw.message( 'hello' );
+ hello = mw.message( 'hello' );
- equal( hello.format, 'plain', 'Message property "format" defaults to "plain"' );
- strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' );
- equal( hello.key, 'hello', 'Message property "key" (currect key)' );
- deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' );
+ assert.equal( hello.format, 'plain', 'Message property "format" defaults to "plain"' );
+ assert.strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' );
+ assert.equal( hello.key, 'hello', 'Message property "key" (currect key)' );
+ assert.deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' );
// Todo
- ok( hello.params, 'Message prototype "params"' );
+ assert.ok( hello.params, 'Message prototype "params"' );
hello.format = 'plain';
- equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' );
+ assert.equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' );
- equal( hello.escaped(), 'Hello &lt;b&gt;awesome&lt;/b&gt; world', 'Message.escaped returns the escaped message' );
- equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' );
+ assert.equal( hello.escaped(), 'Hello &lt;b&gt;awesome&lt;/b&gt; world', 'Message.escaped returns the escaped message' );
+ assert.equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' );
hello.parse();
- equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' );
+ assert.equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' );
hello.plain();
- equal( hello.format, 'plain', 'Message.plain correctly updated the "format" property' );
+ assert.equal( hello.format, 'plain', 'Message.plain correctly updated the "format" property' );
- strictEqual( hello.exists(), true, 'Message.exists returns true for existing messages' );
+ assert.strictEqual( hello.exists(), true, 'Message.exists returns true for existing messages' );
- var goodbye = mw.message( 'goodbye' );
- strictEqual( goodbye.exists(), false, 'Message.exists returns false for nonexistent messages' );
+ goodbye = mw.message( 'goodbye' );
+ assert.strictEqual( goodbye.exists(), false, 'Message.exists returns false for nonexistent messages' );
- equal( goodbye.plain(), '<goodbye>', 'Message.toString returns plain <key> if format is "plain" and key does not exist' );
+ assert.equal( goodbye.plain(), '<goodbye>', 'Message.toString returns plain <key> if format is "plain" and key does not exist' );
// bug 30684
- equal( goodbye.escaped(), '&lt;goodbye&gt;', 'Message.toString returns properly escaped &lt;key&gt; if format is "escaped" and key does not exist' );
+ assert.equal( goodbye.escaped(), '&lt;goodbye&gt;', 'Message.toString returns properly escaped &lt;key&gt; if format is "escaped" and key does not exist' );
- ok( mw.messages.set( 'pluraltestmsg', 'There {{PLURAL:$1|is|are}} $1 {{PLURAL:$1|result|results}}' ), 'mw.messages.set: Register' );
- var pluralMessage = mw.message( 'pluraltestmsg' , 6 );
- equal( pluralMessage.plain(), 'There are 6 results', 'plural get resolved when format is plain' );
- equal( pluralMessage.parse(), 'There are 6 results', 'plural get resolved when format is parse' );
+ assert.ok( mw.messages.set( 'pluraltestmsg', 'There {{PLURAL:$1|is|are}} $1 {{PLURAL:$1|result|results}}' ), 'mw.messages.set: Register' );
+ pluralMessage = mw.message( 'pluraltestmsg' , 6 );
+ assert.equal( pluralMessage.plain(), 'There are 6 results', 'plural get resolved when format is plain' );
+ assert.equal( pluralMessage.parse(), 'There are 6 results', 'plural get resolved when format is parse' );
});
-test( 'mw.msg', function() {
- expect(11);
-
- ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
- equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
- equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (nonexistent message)' );
+QUnit.test( 'mw.msg', 11, function ( assert ) {
+ assert.ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
+ assert.equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
+ assert.equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (nonexistent message)' );
- ok( mw.messages.set( 'plural-item' , 'Found $1 {{PLURAL:$1|item|items}}' ) );
- equal( mw.msg( 'plural-item', 5 ), 'Found 5 items', 'Apply plural for count 5' );
- equal( mw.msg( 'plural-item', 0 ), 'Found 0 items', 'Apply plural for count 0' );
- equal( mw.msg( 'plural-item', 1 ), 'Found 1 item', 'Apply plural for count 1' );
+ assert.ok( mw.messages.set( 'plural-item' , 'Found $1 {{PLURAL:$1|item|items}}' ) );
+ assert.equal( mw.msg( 'plural-item', 5 ), 'Found 5 items', 'Apply plural for count 5' );
+ assert.equal( mw.msg( 'plural-item', 0 ), 'Found 0 items', 'Apply plural for count 0' );
+ assert.equal( mw.msg( 'plural-item', 1 ), 'Found 1 item', 'Apply plural for count 1' );
- ok( mw.messages.set('gender-plural-msg' , '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome' ) );
- equal( mw.msg( 'gender-plural-msg', 'male', 1 ), 'he is awesome', 'Gender test for male, plural count 1' );
- equal( mw.msg( 'gender-plural-msg', 'female', '1' ), 'she is awesome', 'Gender test for female, plural count 1' );
- equal( mw.msg( 'gender-plural-msg', 'unknown', 10 ), 'they are awesome', 'Gender test for neutral, plural count 10' );
+ assert.ok( mw.messages.set('gender-plural-msg' , '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome' ) );
+ assert.equal( mw.msg( 'gender-plural-msg', 'male', 1 ), 'he is awesome', 'Gender test for male, plural count 1' );
+ assert.equal( mw.msg( 'gender-plural-msg', 'female', '1' ), 'she is awesome', 'Gender test for female, plural count 1' );
+ assert.equal( mw.msg( 'gender-plural-msg', 'unknown', 10 ), 'they are awesome', 'Gender test for neutral, plural count 10' );
});
-test( 'mw.loader', function() {
- expect(1);
+/**
+ * The sync style load test (for @import). This is, in a way, also an open bug for
+ * ResourceLoader ("execute js after styles are loaded"), but browsers don't offer a
+ * way to get a callback from when a stylesheet is loaded (that is, including any
+ * @import rules inside). To work around this, we'll have a little time loop to check
+ * if the styles apply.
+ * Note: This test originally used new Image() and onerror to get a callback
+ * when the url is loaded, but that is fragile since it doesn't monitor the
+ * same request as the css @import, and Safari 4 has issues with
+ * onerror/onload not being fired at all in weird cases like this.
+ */
+function assertStyleAsync( assert, $element, prop, val, fn ) {
+ var styleTestStart,
+ el = $element.get( 0 ),
+ styleTestTimeout = ( QUnit.config.testTimeout - 200 ) || 5000;
+
+ function isCssImportApplied() {
+ // Trigger reflow, repaint, redraw, whatever (cross-browser)
+ var x = $element.css( 'height' );
+ x = el.innerHTML;
+ el.className = el.className;
+ x = document.documentElement.clientHeight;
+
+ return $element.css( prop ) === val;
+ }
+
+ function styleTestLoop() {
+ var styleTestSince = new Date().getTime() - styleTestStart;
+ // If it is passing or if we timed out, run the real test and stop the loop
+ if ( isCssImportApplied() || styleTestSince > styleTestTimeout ) {
+ assert.equal( $element.css( prop ), val,
+ 'style "' + prop + ': ' + val + '" from url is applied (after ' + styleTestSince + 'ms)'
+ );
+
+ if ( fn ) {
+ fn();
+ }
+
+ return;
+ }
+ // Otherwise, keep polling
+ setTimeout( styleTestLoop, 150 );
+ }
+
+ // Start the loop
+ styleTestStart = new Date().getTime();
+ styleTestLoop();
+}
+
+function urlStyleTest( selector, prop, val ) {
+ return QUnit.fixurl(
+ mw.config.get( 'wgScriptPath' ) +
+ '/tests/qunit/data/styleTest.css.php?' +
+ $.param( {
+ selector: selector,
+ prop: prop,
+ val: val
+ } )
+ );
+}
+
+QUnit.asyncTest( 'mw.loader', 2, function ( assert ) {
+ var isAwesomeDone;
- // Asynchronous ahead
- stop();
+ mw.loader.testCallback = function () {
+ QUnit.start();
+ assert.strictEqual( isAwesomeDone, undefined, 'Implementing module is.awesome: isAwesomeDone should still be undefined');
+ isAwesomeDone = true;
+ };
- mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} );
+ mw.loader.implement( 'test.callback', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' )], {}, {} );
- mw.loader.using( 'is.awesome', function() {
+ mw.loader.using( 'test.callback', function () {
// /sample/awesome.js declares the "mw.loader.testCallback" function
// which contains a call to start() and ok()
- mw.loader.testCallback();
- mw.loader.testCallback = undefined;
+ assert.strictEqual( isAwesomeDone, true, "test.callback module should've caused isAwesomeDone to be true" );
+ delete mw.loader.testCallback;
- }, function() {
- start();
- ok( false, 'Error callback fired while implementing "is.awesome" module' );
+ }, function () {
+ QUnit.start();
+ assert.ok( false, 'Error callback fired while loader.using "test.callback" module' );
});
-
});
-test( 'mw.loader.bug29107' , function() {
- expect(2);
+QUnit.test( 'mw.loader.implement( styles={ "css": [text, ..] } )', 2, function ( assert ) {
+ var $element = $( '<div class="mw-test-implement-a"></div>' ).appendTo( '#qunit-fixture' );
+
+ assert.notEqual(
+ $element.css( 'float' ),
+ 'right',
+ 'style is clear'
+ );
+
+ mw.loader.implement(
+ 'test.implement.a',
+ function () {
+ assert.equal(
+ $element.css( 'float' ),
+ 'right',
+ 'style is applied'
+ );
+ },
+ {
+ 'all': '.mw-test-implement-a { float: right; }'
+ },
+ {}
+ );
+
+ mw.loader.load([
+ 'test.implement.a'
+ ]);
+} );
+
+QUnit.asyncTest( 'mw.loader.implement( styles={ "url": { <media>: [url, ..] } } )', 7, function ( assert ) {
+ var $element1 = $( '<div class="mw-test-implement-b1"></div>' ).appendTo( '#qunit-fixture' ),
+ $element2 = $( '<div class="mw-test-implement-b2"></div>' ).appendTo( '#qunit-fixture' ),
+ $element3 = $( '<div class="mw-test-implement-b3"></div>' ).appendTo( '#qunit-fixture' );
+
+ assert.notEqual(
+ $element1.css( 'text-align' ),
+ 'center',
+ 'style is clear'
+ );
+ assert.notEqual(
+ $element2.css( 'float' ),
+ 'left',
+ 'style is clear'
+ );
+ assert.notEqual(
+ $element3.css( 'text-align' ),
+ 'right',
+ 'style is clear'
+ );
+
+ mw.loader.implement(
+ 'test.implement.b',
+ function () {
+ assertStyleAsync( assert, $element2, 'float', 'left', function () {
+ assert.notEqual( $element1.css( 'text-align' ), 'center', 'print style is not applied' );
+
+ QUnit.start();
+ } );
+ assertStyleAsync( assert, $element3, 'float', 'right', function () {
+ assert.notEqual( $element1.css( 'text-align' ), 'center', 'print style is not applied' );
+
+ QUnit.start();
+ } );
+ },
+ {
+ 'url': {
+ 'print': [urlStyleTest( '.mw-test-implement-b1', 'text-align', 'center' )],
+ 'screen': [
+ // bug 40834: Make sure it actually works with more than 1 stylesheet reference
+ urlStyleTest( '.mw-test-implement-b2', 'float', 'left' ),
+ urlStyleTest( '.mw-test-implement-b3', 'float', 'right' )
+ ]
+ }
+ },
+ {}
+ );
+
+ mw.loader.load([
+ 'test.implement.b'
+ ]);
+} );
+
+// Backwards compatibility
+QUnit.test( 'mw.loader.implement( styles={ <media>: text } ) (back-compat)', 2, function ( assert ) {
+ var $element = $( '<div class="mw-test-implement-c"></div>' ).appendTo( '#qunit-fixture' );
+
+ assert.notEqual(
+ $element.css( 'float' ),
+ 'right',
+ 'style is clear'
+ );
+
+ mw.loader.implement(
+ 'test.implement.c',
+ function () {
+ assert.equal(
+ $element.css( 'float' ),
+ 'right',
+ 'style is applied'
+ );
+ },
+ {
+ 'all': '.mw-test-implement-c { float: right; }'
+ },
+ {}
+ );
+
+ mw.loader.load([
+ 'test.implement.c'
+ ]);
+} );
+
+// Backwards compatibility
+QUnit.asyncTest( 'mw.loader.implement( styles={ <media>: [url, ..] } ) (back-compat)', 4, function ( assert ) {
+ var $element = $( '<div class="mw-test-implement-d"></div>' ).appendTo( '#qunit-fixture' ),
+ $element2 = $( '<div class="mw-test-implement-d2"></div>' ).appendTo( '#qunit-fixture' );
+
+ assert.notEqual(
+ $element.css( 'float' ),
+ 'right',
+ 'style is clear'
+ );
+ assert.notEqual(
+ $element2.css( 'text-align' ),
+ 'center',
+ 'style is clear'
+ );
+
+ mw.loader.implement(
+ 'test.implement.d',
+ function () {
+ assertStyleAsync( assert, $element, 'float', 'right', function () {
+
+ assert.notEqual( $element2.css( 'text-align' ), 'center', 'print style is not applied (bug 40500)' );
+
+ QUnit.start();
+ } );
+ },
+ {
+ 'all': [urlStyleTest( '.mw-test-implement-d', 'float', 'right' )],
+ 'print': [urlStyleTest( '.mw-test-implement-d2', 'text-align', 'center' )]
+ },
+ {}
+ );
- // Message doesn't exist already
- ok( !mw.messages.exists( 'bug29107' ) );
+ mw.loader.load([
+ 'test.implement.d'
+ ]);
+} );
+
+// @import (bug 31676)
+QUnit.asyncTest( 'mw.loader.implement( styles has @import)', 5, function ( assert ) {
+ var isJsExecuted, $element;
+
+ mw.loader.implement(
+ 'test.implement.import',
+ function () {
+ assert.strictEqual( isJsExecuted, undefined, 'javascript not executed multiple times' );
+ isJsExecuted = true;
+
+ assert.equal( mw.loader.getState( 'test.implement.import' ), 'ready', 'module state is "ready" while implement() is executing javascript' );
+
+ $element = $( '<div class="mw-test-implement-import">Foo bar</div>' ).appendTo( '#qunit-fixture' );
+
+ assert.equal( mw.msg( 'test-foobar' ), 'Hello Foobar, $1!', 'Messages are loaded before javascript execution' );
+
+ assertStyleAsync( assert, $element, 'float', 'right', function () {
+ assert.equal( $element.css( 'text-align' ),'center',
+ 'CSS styles after the @import rule are working'
+ );
+
+ QUnit.start();
+ } );
+ },
+ {
+ 'css': [
+ '@import url(\''
+ + urlStyleTest( '.mw-test-implement-import', 'float', 'right' )
+ + '\');\n'
+ + '.mw-test-implement-import { text-align: center; }'
+ ]
+ },
+ {
+ 'test-foobar': 'Hello Foobar, $1!'
+ }
+ );
+
+ mw.loader.load( 'test.implement' );
+
+});
- // Async! Failure in this test may lead to neither the success nor error callbacks getting called.
- // Due to QUnit's timeout feauture we won't hang here forever if this happends.
- stop();
+QUnit.asyncTest( 'mw.loader.implement( only messages )' , 2, function ( assert ) {
+ assert.assertFalse( mw.messages.exists( 'bug_29107' ), 'Verify that the test message doesn\'t exist yet' );
- mw.loader.implement( 'bug29107.messages-only', [], {}, {'bug29107': 'loaded'} );
- mw.loader.using( 'bug29107.messages-only', function() {
- start();
- ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should implement ok' );
+ mw.loader.implement( 'test.implement.msgs', [], {}, { 'bug_29107': 'loaded' } );
+ mw.loader.using( 'test.implement.msgs', function() {
+ QUnit.start();
+ assert.ok( mw.messages.exists( 'bug_29107' ), 'Bug 29107: messages-only module should implement ok' );
}, function() {
- start();
- ok( false, 'Error callback fired while implementing "bug29107.messages-only" module' );
+ QUnit.start();
+ assert.ok( false, 'Error callback fired while implementing "test.implement.msgs" module' );
});
});
-test( 'mw.loader.bug30825', function() {
+QUnit.test( 'mw.loader erroneous indirect dependency', 3, function ( assert ) {
+ mw.loader.register( [
+ ['test.module1', '0'],
+ ['test.module2', '0', ['test.module1']],
+ ['test.module3', '0', ['test.module2']]
+ ] );
+ mw.loader.implement( 'test.module1', function () { throw new Error( 'expected' ); }, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module1' ), 'error', 'Expected "error" state for test.module1' );
+ assert.strictEqual( mw.loader.getState( 'test.module2' ), 'error', 'Expected "error" state for test.module2' );
+ assert.strictEqual( mw.loader.getState( 'test.module3' ), 'error', 'Expected "error" state for test.module3' );
+} );
+
+QUnit.test( 'mw.loader out-of-order implementation', 9, function ( assert ) {
+ mw.loader.register( [
+ ['test.module4', '0'],
+ ['test.module5', '0', ['test.module4']],
+ ['test.module6', '0', ['test.module5']]
+ ] );
+ mw.loader.implement( 'test.module4', function () {}, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
+ assert.strictEqual( mw.loader.getState( 'test.module5' ), 'registered', 'Expected "registered" state for test.module5' );
+ assert.strictEqual( mw.loader.getState( 'test.module6' ), 'registered', 'Expected "registered" state for test.module6' );
+ mw.loader.implement( 'test.module6', function () {}, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
+ assert.strictEqual( mw.loader.getState( 'test.module5' ), 'registered', 'Expected "registered" state for test.module5' );
+ assert.strictEqual( mw.loader.getState( 'test.module6' ), 'loaded', 'Expected "loaded" state for test.module6' );
+ mw.loader.implement( 'test.module5', function() {}, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
+ assert.strictEqual( mw.loader.getState( 'test.module5' ), 'ready', 'Expected "ready" state for test.module5' );
+ assert.strictEqual( mw.loader.getState( 'test.module6' ), 'ready', 'Expected "ready" state for test.module6' );
+} );
+
+QUnit.test( 'mw.loader missing dependency', 13, function ( assert ) {
+ mw.loader.register( [
+ ['test.module7', '0'],
+ ['test.module8', '0', ['test.module7']],
+ ['test.module9', '0', ['test.module8']]
+ ] );
+ mw.loader.implement( 'test.module8', function () {}, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module7' ), 'registered', 'Expected "registered" state for test.module7' );
+ assert.strictEqual( mw.loader.getState( 'test.module8' ), 'loaded', 'Expected "loaded" state for test.module8' );
+ assert.strictEqual( mw.loader.getState( 'test.module9' ), 'registered', 'Expected "registered" state for test.module9' );
+ mw.loader.state( 'test.module7', 'missing' );
+ assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' );
+ assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' );
+ assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' );
+ mw.loader.implement( 'test.module9', function () {}, {}, {} );
+ assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' );
+ assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' );
+ assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' );
+ mw.loader.using(
+ ['test.module7'],
+ function () {
+ assert.ok( false, "Success fired despite missing dependency" );
+ assert.ok( true , "QUnit expected() count dummy" );
+ },
+ function ( e, dependencies ) {
+ assert.strictEqual( $.isArray( dependencies ), true, 'Expected array of dependencies' );
+ assert.deepEqual( dependencies, ['test.module7'], 'Error callback called with module test.module7' );
+ }
+ );
+ mw.loader.using(
+ ['test.module9'],
+ function () {
+ assert.ok( false, "Success fired despite missing dependency" );
+ assert.ok( true , "QUnit expected() count dummy" );
+ },
+ function ( e, dependencies ) {
+ assert.strictEqual( $.isArray( dependencies ), true, 'Expected array of dependencies' );
+ dependencies.sort();
+ assert.deepEqual(
+ dependencies,
+ ['test.module7', 'test.module8', 'test.module9'],
+ 'Error callback called with all three modules as dependencies'
+ );
+ }
+ );
+} );
+
+QUnit.asyncTest( 'mw.loader dependency handling', 5, function ( assert ) {
+ mw.loader.addSource(
+ 'testloader',
+ {
+ loadScript: QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/load.mock.php' )
+ }
+ );
+
+ mw.loader.register( [
+ // [module, version, dependencies, group, source]
+ ['testMissing', '1', [], null, 'testloader'],
+ ['testUsesMissing', '1', ['testMissing'], null, 'testloader'],
+ ['testUsesNestedMissing', '1', ['testUsesMissing'], null, 'testloader']
+ ] );
+
+ function verifyModuleStates() {
+ assert.equal( mw.loader.getState( 'testMissing' ), 'missing', 'Module not known to server must have state "missing"' );
+ assert.equal( mw.loader.getState( 'testUsesMissing' ), 'error', 'Module with missing dependency must have state "error"' );
+ assert.equal( mw.loader.getState( 'testUsesNestedMissing' ), 'error', 'Module with indirect missing dependency must have state "error"' );
+ }
+
+ mw.loader.using( ['testUsesNestedMissing'],
+ function () {
+ assert.ok( false, 'Error handler should be invoked.' );
+ assert.ok( true ); // Dummy to reach QUnit expect()
+
+ verifyModuleStates();
+
+ QUnit.start();
+ },
+ function ( e, badmodules ) {
+ assert.ok( true, 'Error handler should be invoked.' );
+ // As soon as server spits out state('testMissing', 'missing');
+ // it will bubble up and trigger the error callback.
+ // Therefor the badmodules array is not testUsesMissing or testUsesNestedMissing.
+ assert.deepEqual( badmodules, ['testMissing'], 'Bad modules as expected.' );
+
+ verifyModuleStates();
+
+ QUnit.start();
+ }
+ );
+} );
+
+QUnit.asyncTest( 'mw.loader( "//protocol-relative" ) (bug 30825)', 2, function ( assert ) {
// This bug was actually already fixed in 1.18 and later when discovered in 1.17.
// Test is for regressions!
- expect(2);
-
// Forge an URL to the test callback script
var target = QUnit.fixurl(
mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/qunitOkCall.js'
@@ -199,31 +563,31 @@ test( 'mw.loader.bug30825', function() {
// Confirm that mw.loader.load() works with protocol-relative URLs
target = target.replace( /https?:/, '' );
- equal( target.substr( 0, 2 ), '//',
+ assert.equal( target.substr( 0, 2 ), '//',
'URL must be relative to test relative URLs!'
);
// Async!
- stop();
+ // The target calls QUnit.start
mw.loader.load( target );
});
-test( 'mw.html', function() {
- expect(11);
-
- raises( function(){
+QUnit.test( 'mw.html', 13, function ( assert ) {
+ assert.throws( function () {
mw.html.escape();
}, TypeError, 'html.escape throws a TypeError if argument given is not a string' );
- equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
- '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'html.escape escapes html snippet' );
+ assert.equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
+ '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'escape() escapes special characters to html entities' );
- equal( mw.html.element(),
- '<undefined/>', 'html.element Always return a valid html string (even without arguments)' );
+ assert.equal( mw.html.element(),
+ '<undefined/>', 'element() always returns a valid html string (even without arguments)' );
- equal( mw.html.element( 'div' ), '<div/>', 'html.element DIV (simple)' );
+ assert.equal( mw.html.element( 'div' ), '<div/>', 'element() Plain DIV (simple)' );
- equal(
+ assert.equal( mw.html.element( 'div', {}, '' ), '<div></div>', 'element() Basic DIV (simple)' );
+
+ assert.equal(
mw.html.element(
'div', {
id: 'foobar'
@@ -232,11 +596,24 @@ test( 'mw.html', function() {
'<div id="foobar"/>',
'html.element DIV (attribs)' );
- equal( mw.html.element( 'p', null, 12 ), '<p>12</p>', 'Numbers are valid content and should be casted to a string' );
+ assert.equal( mw.html.element( 'p', null, 12 ), '<p>12</p>', 'Numbers are valid content and should be casted to a string' );
+
+ assert.equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'Numbers are valid attribute values' );
- equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'Numbers are valid attribute values' );
+ // Example from https://www.mediawiki.org/wiki/ResourceLoader/Default_modules#mediaWiki.html
+ assert.equal(
+ mw.html.element(
+ 'div',
+ {},
+ new mw.html.Raw(
+ mw.html.element( 'img', { src: '<' } )
+ )
+ ),
+ '<div><img src="&lt;"/></div>',
+ 'Raw inclusion of another element'
+ );
- equal(
+ assert.equal(
mw.html.element(
'option', {
selected: true
@@ -246,7 +623,7 @@ test( 'mw.html', function() {
'Attributes may have boolean values. True copies the attribute name to the value.'
);
- equal(
+ assert.equal(
mw.html.element(
'option', {
value: 'foo',
@@ -257,14 +634,16 @@ test( 'mw.html', function() {
'Attributes may have boolean values. False keeps the attribute from output.'
);
- equal( mw.html.element( 'div',
+ assert.equal( mw.html.element( 'div',
null, 'a' ),
'<div>a</div>',
'html.element DIV (content)' );
- equal( mw.html.element( 'a',
+ assert.equal( mw.html.element( 'a',
{ href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
'<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
'html.element DIV (attribs + content)' );
});
+
+}( mediaWiki ) );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js
index 15265db5..16c97dff 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js
@@ -1,21 +1,12 @@
-module( 'mediawiki.user', QUnit.newMwEnvironment() );
+( function ( mw ) {
-test( '-- Initial check', function() {
- expect(1);
+QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
- ok( mw.user, 'mw.user defined' );
+QUnit.test( 'options', 1, function ( assert ) {
+ assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
});
-
-test( 'options', function() {
- expect(1);
-
- ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
-});
-
-test( 'User login status', function() {
- expect(5);
-
+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.
@@ -24,16 +15,42 @@ test( 'User login status', function() {
*/
// Forge an anonymous user:
- mw.config.set( 'wgUserName', null);
+ 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' );
+ 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' );
- equal( mw.user.name(), 'John', 'user.name returns username when logged-in' );
- 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' );
- equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
+ assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
});
+
+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 ) {
+ // First group should always be '*'
+ assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
+ QUnit.start();
+ });
+});
+
+}( mediaWiki ) );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
index ea28935e..ababa8d9 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -1,73 +1,58 @@
-module( 'mediawiki.util', QUnit.newMwEnvironment() );
+QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment() );
-test( '-- Initial check', function() {
- expect(1);
-
- ok( mw.util, 'mw.util defined' );
-});
-
-test( 'rawurlencode', function() {
- expect(1);
-
- equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
+QUnit.test( 'rawurlencode', 1, function ( assert ) {
+ assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
});
-test( 'wikiUrlencode', function() {
- expect(1);
-
- equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
+QUnit.test( 'wikiUrlencode', 1, function ( assert ) {
+ assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
});
-test( 'wikiGetlink', function() {
- expect(3);
-
+QUnit.test( 'wikiGetlink', 3, function ( assert ) {
// Not part of startUp module
mw.config.set( 'wgArticlePath', '/wiki/$1' );
mw.config.set( 'wgPageName', 'Foobar' );
var hrefA = mw.util.wikiGetlink( 'Sandbox' );
- equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
+ assert.equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
- equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
+ assert.equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
var hrefC = mw.util.wikiGetlink();
- equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
+ assert.equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
});
-test( 'wikiScript', function() {
- expect(2);
-
+QUnit.test( 'wikiScript', 4, function ( assert ) {
mw.config.set({
- 'wgScript': '/w/index.php',
+ 'wgScript': '/w/i.php', // customized wgScript for bug 39103
+ 'wgLoadScript': '/w/l.php', // customized wgLoadScript for bug 39103
'wgScriptPath': '/w',
'wgScriptExtension': '.php'
});
- equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
- equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
+ assert.equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'wikiScript() returns wgScript' );
+ assert.equal( mw.util.wikiScript( 'index' ), mw.config.get( 'wgScript' ), "wikiScript( 'index' ) returns wgScript" );
+ assert.equal( mw.util.wikiScript( 'load' ), mw.config.get( 'wgLoadScript' ), "wikiScript( 'load' ) returns wgLoadScript" );
+ assert.equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
});
-test( 'addCSS', function() {
- expect(3);
-
+QUnit.test( 'addCSS', 3, function ( assert ) {
var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( '#qunit-fixture' );
var style = mw.util.addCSS( '#mw-addcsstest { visibility: hidden; }' );
- equal( typeof style, 'object', 'addCSS returned an object' );
- strictEqual( style.disabled, false, 'property "disabled" is available and set to false' );
+ assert.equal( typeof style, 'object', 'addCSS returned an object' );
+ assert.strictEqual( style.disabled, false, 'property "disabled" is available and set to false' );
- equal( $testEl.css( 'visibility' ), 'hidden', 'Added style properties are in effect' );
+ assert.equal( $testEl.css( 'visibility' ), 'hidden', 'Added style properties are in effect' );
// Clean up
$( style.ownerNode ).remove();
});
-test( 'toggleToc', function() {
- expect(4);
-
- strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
+QUnit.asyncTest( 'toggleToc', 4, function ( assert ) {
+ assert.strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
var tocHtml =
'<table id="toc" class="toc"><tr><td>' +
@@ -80,57 +65,46 @@ test( 'toggleToc', function() {
$toc = $(tocHtml).appendTo( '#qunit-fixture' ),
$toggleLink = $( '#togglelink' );
- strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
-
- // Toggle animation is asynchronous
- // QUnit should not finish this test() untill they are all done
- stop();
+ assert.strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
var actionC = function() {
- start();
+ QUnit.start();
};
var actionB = function() {
- start(); stop();
- strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
+ assert.strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
};
var actionA = function() {
- strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
+ assert.strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
};
actionA();
});
-test( 'getParamValue', function() {
- expect(5);
-
+QUnit.test( 'getParamValue', 5, function ( assert ) {
var url1 = 'http://example.org/?foo=wrong&foo=right#&foo=bad';
- equal( mw.util.getParamValue( 'foo', url1 ), 'right', 'Use latest one, ignore hash' );
- strictEqual( mw.util.getParamValue( 'bar', url1 ), null, 'Return null when not found' );
+ assert.equal( mw.util.getParamValue( 'foo', url1 ), 'right', 'Use latest one, ignore hash' );
+ assert.strictEqual( mw.util.getParamValue( 'bar', url1 ), null, 'Return null when not found' );
var url2 = 'http://example.org/#&foo=bad';
- strictEqual( mw.util.getParamValue( 'foo', url2 ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' );
+ assert.strictEqual( mw.util.getParamValue( 'foo', url2 ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' );
var url3 = 'example.org?' + $.param({ 'TEST': 'a b+c' });
- strictEqual( mw.util.getParamValue( 'TEST', url3 ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' );
+ assert.strictEqual( mw.util.getParamValue( 'TEST', url3 ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' );
var url4 = 'example.org?' + $.param({ 'TEST': 'a b+c d' }); // check for sloppy code from r95332 :)
- strictEqual( mw.util.getParamValue( 'TEST', url4 ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' );
+ assert.strictEqual( mw.util.getParamValue( 'TEST', url4 ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' );
});
-test( 'tooltipAccessKey', function() {
- expect(3);
-
- equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
- ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
- ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' );
+QUnit.test( 'tooltipAccessKey', 3, function ( assert ) {
+ assert.equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
+ assert.ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
+ assert.ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' );
});
-test( '$content', function() {
- expect(2);
-
- ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' );
- strictEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
+QUnit.test( '$content', 2, function ( assert ) {
+ assert.ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' );
+ assert.strictEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
});
@@ -138,87 +112,98 @@ test( '$content', function() {
* Portlet names are prefixed with 'p-test' to avoid conflict with core
* when running the test suite under a wiki page.
* Previously, test elements where invisible to the selector since only
- * one element can have a given id.
+ * one element can have a given id.
*/
-test( 'addPortletLink', function() {
- expect(7);
-
- var mwPanel = '<div id="mw-panel" class="noprint">\
- <h5>Toolbox</h5>\
+QUnit.test( 'addPortletLink', 8, function ( assert ) {
+ var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo;
+ pTestTb = '\
<div class="portlet" id="p-test-tb">\
+ <h5>Toolbox</h5>\
<ul class="body"></ul>\
- </div>\
-</div>',
- vectorTabs = '<div id="p-test-views" class="vectorTabs">\
- <h5>Views</h5>\
- <ul></ul>\
-</div>',
- $mwPanel = $(mwPanel).appendTo( '#qunit-fixture' ),
- $vectorTabs = $(vectorTabs).appendTo( '#qunit-fixture' );
-
- var tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
+ </div>';
+ pCustom = '\
+ <div class="portlet" id="p-test-custom">\
+ <h5>Views</h5>\
+ <ul class="body">\
+ <li id="c-foo"><a href="#">Foo</a></li>\
+ <li id="c-barmenu">\
+ <ul>\
+ <li id="c-bar-baz"><a href="#">Baz</a></a>\
+ </ul>\
+ </li>\
+ </ul>\
+ </div>';
+ vectorTabs = '\
+ <div id="p-test-views" class="vectorTabs">\
+ <h5>Views</h5>\
+ <ul></ul>\
+ </div>';
+
+ $( '#qunit-fixture' ).append( pTestTb, pCustom, vectorTabs );
+
+ tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' );
- ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' );
+ assert.ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' );
- var tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/',
- 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ),
- $tbMW = $( tbMW );
+ tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/',
+ 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL );
+ $tbMW = $( tbMW );
- equal( $tbMW.attr( 'id' ), 't-mworg', 'Link has correct ID set' );
- equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' );
- equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
+ assert.equal( $tbMW.attr( 'id' ), 't-mworg', 'Link has correct ID set' );
+ assert.equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' );
+ assert.equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
- var tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM',
- 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' );
+ cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux' );
+ $cuQuux = $(cuQuux);
- equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' );
+ assert.equal(
+ $( '#p-test-custom #c-barmenu ul li' ).length,
+ 1,
+ 'addPortletLink did not add the item to all <ul> elements in the portlet (bug 35082)'
+ );
- var caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' );
+ tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM',
+ 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' );
- strictEqual( $tbMW.find( 'span').length, 0, 'No <span> element should be added for porlets without vectorTabs class.' );
- strictEqual( $( caFoo ).find( 'span').length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
+ assert.equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' );
- // Clean up
- $( [tbRL, tbMW, tbRLDM, caFoo] ).remove();
-});
+ caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' );
-test( 'jsMessage', function() {
- expect(1);
+ assert.strictEqual( $tbMW.find( 'span').length, 0, 'No <span> element should be added for porlets without vectorTabs class.' );
+ assert.strictEqual( $( caFoo ).find( 'span').length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
+});
+QUnit.test( 'jsMessage', 1, function ( assert ) {
var a = mw.util.jsMessage( "MediaWiki is <b>Awesome</b>." );
- ok( a, 'Basic checking of return value' );
+ assert.ok( a, 'Basic checking of return value' );
// Clean up
$( '#mw-js-message' ).remove();
});
-test( 'validateEmail', function() {
- expect(6);
-
- strictEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
- strictEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
+QUnit.test( 'validateEmail', 6, function ( assert ) {
+ assert.strictEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
+ assert.strictEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
// testEmailWithCommasAreInvalids
- strictEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
- strictEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
+ assert.strictEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
+ assert.strictEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
// testEmailWithHyphens
- strictEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
- strictEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
+ assert.strictEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
+ assert.strictEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
});
-test( 'isIPv6Address', function() {
- expect(40);
-
+QUnit.test( 'isIPv6Address', 40, function ( assert ) {
// Shortcuts
- var assertFalseIPv6 = function( addy, summary ) {
- return strictEqual( mw.util.isIPv6Address( addy ), false, summary );
- },
- assertTrueIPv6 = function( addy, summary ) {
- return strictEqual( mw.util.isIPv6Address( addy ), true, summary );
- };
+ function assertFalseIPv6( addy, summary ) {
+ return assert.strictEqual( mw.util.isIPv6Address( addy ), false, summary );
+ }
+ function assertTrueIPv6( addy, summary ) {
+ return assert.strictEqual( mw.util.isIPv6Address( addy ), true, summary );
+ }
// Based on IPTest.php > testisIPv6
assertFalseIPv6( ':fc:100::', 'IPv6 starting with lone ":"' );
@@ -232,7 +217,7 @@ test( 'isIPv6Address', function() {
'fc:100:a:d::',
'fc:100:a:d:1::',
'fc:100:a:d:1:e::',
- 'fc:100:a:d:1:e:ac::'], function( i, addy ){
+ 'fc:100:a:d:1:e:ac::'], function ( i, addy ){
assertTrueIPv6( addy, addy + ' is a valid IP' );
});
@@ -253,7 +238,7 @@ test( 'isIPv6Address', function() {
'::fc:100:a:d:1:e',
'::fc:100:a:d:1:e:ac',
- 'fc:100:a:d:1:e:ac:0'], function( i, addy ){
+ 'fc:100:a:d:1:e:ac:0'], function ( i, addy ){
assertTrueIPv6( addy, addy + ' is a valid IP' );
});
@@ -278,16 +263,14 @@ test( 'isIPv6Address', function() {
assertFalseIPv6( 'fc::100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
});
-test( 'isIPv4Address', function() {
- expect(11);
-
+QUnit.test( 'isIPv4Address', 11, function ( assert ) {
// Shortcuts
- var assertFalseIPv4 = function( addy, summary ) {
- return strictEqual( mw.util.isIPv4Address( addy ), false, summary );
- },
- assertTrueIPv4 = function( addy, summary ) {
- return strictEqual( mw.util.isIPv4Address( addy ), true, summary );
- };
+ function assertFalseIPv4( addy, summary ) {
+ assert.strictEqual( mw.util.isIPv4Address( addy ), false, summary );
+ }
+ function assertTrueIPv4( addy, summary ) {
+ assert.strictEqual( mw.util.isIPv4Address( addy ), true, summary );
+ }
// Based on IPTest.php > testisIPv4
assertFalseIPv4( false, 'Boolean false is not an IP' );