Update formatting

9 of n.

Change-Id: Ide20743a2e84ff68549286120e6cff9d9f396f54
This commit is contained in:
Siebrand Mazeland 2013-02-15 12:10:19 +01:00 committed by Gerrit Code Review
parent 454d92fb7c
commit 1963fcf279
16 changed files with 1796 additions and 1760 deletions

View file

@ -52,7 +52,7 @@
/**
* CompletenessTest
*/
// Adds toggle checkbox to header
// Adds toggle checkbox to header
QUnit.config.urlConfig.push( {
id: 'completenesstest',
label: 'Run CompletenessTest',
@ -92,7 +92,7 @@
/**
* Test environment recommended for all QUnit test modules
*/
// Whether to log environment changes to the console
// Whether to log environment changes to the console
QUnit.config.urlConfig.push( 'mwlogenv' );
/**
@ -118,7 +118,7 @@
}
function freshMessagesCopy( custom ) {
return $.extend( /*deep=*/true, {}, liveMessages, custom );
return $.extend( /*deep=*/true, {}, liveMessages, custom );
}
log = QUnit.urlParams.mwlogenv ? mw.log : function () {};
@ -172,7 +172,7 @@
// Whether this one fails or not, forwards it to
// the 'done' (resolve) callback of the alternative promise.
arg.always( alt.resolve );
});
} );
return $.when.apply( $, altPromises );
};
@ -221,7 +221,7 @@
* initializations defined above in this file.
*/
envExecCount = 0;
QUnit.module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment({
QUnit.module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment( {
setup: function () {
envExecCount += 1;
this.mwHtmlLive = mw.html;
@ -240,7 +240,7 @@
messages: {
testMsg: 'Foo.'
}
}) );
} ) );
QUnit.test( 'Setup', 3, function ( assert ) {
assert.equal( mw.html.escape( 'foo' ), 'mocked-1', 'extra setup() callback was ran.' );
@ -249,13 +249,13 @@
mw.config.set( 'testVar', 'bar' );
mw.messages.set( 'testMsg', 'Bar.' );
});
} );
QUnit.test( 'Teardown', 3, function ( assert ) {
assert.equal( mw.html.escape( 'foo' ), 'mocked-2', 'extra setup() callback was re-ran.' );
assert.equal( mw.config.get( 'testVar' ), 'foo', 'config object restored and re-applied after test()' );
assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object restored and re-applied after test()' );
});
} );
QUnit.module( 'mediawiki.tests.qunit.testrunner-after', QUnit.newMwEnvironment() );
@ -263,6 +263,6 @@
assert.equal( mw.html.escape( '<' ), '&lt;', 'extra teardown() callback was ran.' );
assert.equal( mw.config.get( 'testVar' ), null, 'config object restored to live in next module()' );
assert.equal( mw.messages.get( 'testMsg' ), null, 'messages object restored to live in next module()' );
});
} );
}( jQuery, mediaWiki, QUnit ) );

View file

@ -15,10 +15,12 @@
// Basic sendkey-implementation
function addChars( $input, charstr ) {
var c, len;
function x( $input, i ) {
// Add character to the value
return $input.val() + charstr.charAt( i );
}
for ( c = 0, len = charstr.length; c < len; c += 1 ) {
$input
.val( x( $input, c ) )
@ -35,72 +37,72 @@
* The limit should be less than 20 (the sample data's length)
*/
function byteLimitTest( options ) {
var opt = $.extend({
var opt = $.extend( {
description: '',
$input: null,
sample: '',
hasLimit: false,
expected: '',
limit: null
}, options);
}, options );
QUnit.asyncTest( opt.description, opt.hasLimit ? 3 : 2, function ( assert ) {
setTimeout( function () {
var rawVal, fn, effectiveVal;
setTimeout( function () {
var rawVal, fn, effectiveVal;
opt.$input.appendTo( '#qunit-fixture' );
opt.$input.appendTo( '#qunit-fixture' );
// Simulate pressing keys for each of the sample characters
addChars( opt.$input, opt.sample );
// Simulate pressing keys for each of the sample characters
addChars( opt.$input, opt.sample );
rawVal = opt.$input.val();
fn = opt.$input.data( 'byteLimit.callback' );
effectiveVal = fn ? fn( rawVal ) : rawVal;
rawVal = opt.$input.val();
fn = opt.$input.data( 'byteLimit.callback' );
effectiveVal = fn ? fn( rawVal ) : rawVal;
if ( opt.hasLimit ) {
assert.ltOrEq(
$.byteLength( effectiveVal ),
opt.limit,
'Prevent keypresses after byteLimit was reached, length never exceeded the limit'
);
assert.equal(
$.byteLength( rawVal ),
$.byteLength( opt.expected ),
'Not preventing keypresses too early, length has reached the expected length'
);
assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
if ( opt.hasLimit ) {
assert.ltOrEq(
$.byteLength( effectiveVal ),
opt.limit,
'Prevent keypresses after byteLimit was reached, length never exceeded the limit'
);
assert.equal(
$.byteLength( rawVal ),
$.byteLength( opt.expected ),
'Not preventing keypresses too early, length has reached the expected length'
);
assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
} else {
assert.equal(
$.byteLength( effectiveVal ),
$.byteLength( opt.expected ),
'Unlimited scenarios are not affected, expected length reached'
);
assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
}
QUnit.start();
}, 10 );
} else {
assert.equal(
$.byteLength( effectiveVal ),
$.byteLength( opt.expected ),
'Unlimited scenarios are not affected, expected length reached'
);
assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
}
QUnit.start();
}, 10 );
} );
}
byteLimitTest({
byteLimitTest( {
description: 'Plain text input',
$input: $( '<input type="text"/>' ),
sample: simpleSample,
hasLimit: false,
expected: simpleSample
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Plain text input. Calling byteLimit with no parameters and no maxlength attribute (bug 36310)',
$input: $( '<input type="text"/>' )
.byteLimit(),
sample: simpleSample,
hasLimit: false,
expected: simpleSample
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using the maxlength attribute',
$input: $( '<input type="text"/>' )
.attr( 'maxlength', '10' )
@ -109,9 +111,9 @@
hasLimit: true,
limit: 10,
expected: '1234567890'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using a custom value',
$input: $( '<input type="text"/>' )
.byteLimit( 10 ),
@ -119,9 +121,9 @@
hasLimit: true,
limit: 10,
expected: '1234567890'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using a custom value, overriding maxlength attribute',
$input: $( '<input type="text"/>' )
.attr( 'maxlength', '10' )
@ -130,9 +132,9 @@
hasLimit: true,
limit: 15,
expected: '123456789012345'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using a custom value (multibyte)',
$input: $( '<input type="text"/>' )
.byteLimit( 14 ),
@ -140,9 +142,9 @@
hasLimit: true,
limit: 14,
expected: '1234567890' + U_20AC + '1'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using a custom value (multibyte) overlapping a byte',
$input: $( '<input type="text"/>' )
.byteLimit( 12 ),
@ -150,9 +152,9 @@
hasLimit: true,
limit: 12,
expected: '1234567890' + '12'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Pass the limit and a callback as input filter',
$input: $( '<input type="text"/>' )
.byteLimit( 6, function ( val ) {
@ -168,9 +170,9 @@
hasLimit: true,
limit: 6, // 'Sample' length
expected: 'User:Sample'
});
} );
byteLimitTest({
byteLimitTest( {
description: 'Limit using the maxlength attribute and pass a callback as input filter',
$input: $( '<input type="text"/>' )
.attr( 'maxlength', '6' )
@ -187,7 +189,7 @@
hasLimit: true,
limit: 6, // 'Sample' length
expected: 'User:Sample'
});
} );
QUnit.test( 'Confirm properties and attributes set', 4, function ( assert ) {
var $el, $elA, $elB;
@ -230,7 +232,7 @@
assert.strictEqual( $el.length, 2, 'Verify that there are no other elements clashing with this test suite' );
$el.byteLimit();
});
} );
QUnit.test( 'Trim from insertion when limit exceeded', 2, function ( assert ) {
var $el;
@ -252,6 +254,5 @@
.val( 'azbc' ).trigger( 'change' );
assert.strictEqual( $el.val(), 'abc', 'Trim from the insertion point (at 1), not the end' );
});
} );
}( jQuery, mediaWiki ) );

View file

@ -278,13 +278,13 @@
};
$.each( uas, function () {
uacount++;
});
} );
return uas;
}() );
QUnit.test( 'profile userAgent support', uacount, function ( assert ) {
// Generate a client profile object and compare recursively
var uaTest = function( rawUserAgent, data ) {
var uaTest = function ( rawUserAgent, data ) {
var ret = $.client.profile( {
userAgent: rawUserAgent,
platform: data.platform
@ -298,6 +298,7 @@
QUnit.test( 'profile return validation for current user agent', 7, function ( assert ) {
var p = $.client.profile();
function unknownOrType( val, type, summary ) {
assert.ok( typeof val === type || val === 'unknown', summary );
}
@ -309,7 +310,7 @@
unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
});
} );
// Example from WikiEditor
// Make sure to use raw numbers, a string like "7.0" would fail on a
@ -346,10 +347,10 @@
assert.equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
});
} );
QUnit.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount * 2, function ( assert ) {
var $body = $( 'body' ),
var $body = $( 'body' ),
bodyClasses = $body.attr( 'class' );
// Loop through and run tests
@ -365,10 +366,10 @@
$body.removeClass( dir );
assert.equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
});
});
} );
} );
// Restore body classes
$body.attr( 'class', bodyClasses );
});
} );
}( jQuery ) );

View file

@ -2,38 +2,36 @@
QUnit.module( 'jquery.mwExtension', QUnit.newMwEnvironment() );
QUnit.test( 'String functions', function ( assert ) {
assert.equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
assert.equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
assert.equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' );
assert.equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
'<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
'<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
assert.equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
assert.equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
assert.equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
});
} );
QUnit.test( 'Is functions', function ( assert ) {
assert.strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
'isDomElement: #qunit-header Node' );
'isDomElement: #qunit-header Node' );
assert.strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
'isDomElement: #random-name (null)' );
'isDomElement: #random-name (null)' );
assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
'isDomElement: getElementsByTagName Array' );
'isDomElement: getElementsByTagName Array' );
assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
'isDomElement: getElementsByTagName(..)[0] Node' );
'isDomElement: getElementsByTagName(..)[0] Node' );
assert.strictEqual( $.isDomElement( $( 'div' ) ), false,
'isDomElement: jQuery object' );
assert.strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
'isDomElement: jQuery object > Get node' );
'isDomElement: jQuery object' );
assert.strictEqual( $.isDomElement( $( 'div' ).get( 0 ) ), true,
'isDomElement: jQuery object > Get node' );
assert.strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
'isDomElement: createElement' );
'isDomElement: createElement' );
assert.strictEqual( $.isDomElement( { foo: 1 } ), false,
'isDomElement: Object' );
'isDomElement: Object' );
assert.strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
assert.strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
@ -44,17 +42,16 @@
// Documented behaviour
assert.strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
});
} );
QUnit.test( 'Comparison functions', function ( assert ) {
assert.ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, 'a', [], [2, 'b'] ] ),
'compareArray: Two deep arrays that are excactly the same' );
'compareArray: Two deep arrays that are excactly the same' );
assert.ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
assert.ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
assert.ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
assert.ok( !$.compareObject( { bar: true }, { baz: false } ),
'compareObject: Two different objects (false)' );
});
'compareObject: Two different objects (false)' );
} );
}( jQuery ) );

View file

@ -3,35 +3,33 @@
QUnit.test( 'firstTabIndex', 2, function ( assert ) {
var html, $testA, $testB;
html =
'<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
html = '<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
$testA = $( '<div>' ).html( html ).appendTo( '#qunit-fixture' );
assert.strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
$testB = $( '<div>' );
assert.strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
});
} );
QUnit.test( 'lastTabIndex', 2, function ( assert ) {
var html, $testA, $testB;
html =
'<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
html = '<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
$testA = $( '<div>' ).html( html ).appendTo( '#qunit-fixture' );
assert.strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
$testB = $( '<div>' );
assert.strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
});
} );
}( jQuery ) );

View file

@ -8,7 +8,7 @@
wgContentLanguage: 'en'
};
QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment({ config: config }) );
QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment( { config: config } ) );
/**
* Create an HTML table from an array of row arrays containing text strings.
@ -18,7 +18,7 @@
* @param {String[][]} data
* @return jQuery
*/
function tableCreate( header, data ) {
function tableCreate( header, data ) {
var i,
$table = $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
$thead = $table.find( 'thead' ),
@ -28,7 +28,7 @@
$.each( header, function ( i, str ) {
var $th = $( '<th>' );
$th.text( str ).appendTo( $tr );
});
} );
$tr.appendTo( $thead );
for ( i = 0; i < data.length; i++ ) {
@ -37,7 +37,7 @@
$.each( data[i], function ( j, str ) {
var $td = $( '<td>' );
$td.text( str ).appendTo( $tr );
});
} );
$tr.appendTo( $tbody );
}
return $table;
@ -52,13 +52,13 @@
function tableExtract( $table ) {
var data = [];
$table.find( 'tbody' ).find( 'tr' ).each( function( i, tr ) {
$table.find( 'tbody' ).find( 'tr' ).each( function ( i, tr ) {
var row = [];
$( tr ).find( 'td,th' ).each( function( i, td ) {
$( tr ).find( 'td,th' ).each( function ( i, td ) {
row.push( $( td ).text() );
});
} );
data.push( row );
});
} );
return data;
}
@ -83,12 +83,12 @@
// to asynchronous, we'll need a timeout or a callback here.
var extracted = tableExtract( $table );
assert.deepEqual( extracted, expected, msg );
});
} );
}
function reversed(arr) {
function reversed( arr ) {
// Clone array
var arr2 = arr.slice(0);
var arr2 = arr.slice( 0 );
arr2.reverse();
@ -96,17 +96,17 @@
}
// Sample data set using planets named and their radius
var header = [ 'Planet' , 'Radius (km)'],
var header = [ 'Planet' , 'Radius (km)'],
mercury = [ 'Mercury', '2439.7' ],
venus = [ 'Venus' , '6051.8' ],
earth = [ 'Earth' , '6371.0' ],
mars = [ 'Mars' , '3390.0' ],
jupiter = [ 'Jupiter', '69911' ],
saturn = [ 'Saturn' , '58232' ];
venus = [ 'Venus' , '6051.8' ],
earth = [ 'Earth' , '6371.0' ],
mars = [ 'Mars' , '3390.0' ],
jupiter = [ 'Jupiter', '69911' ],
saturn = [ 'Saturn' , '58232' ];
// Initial data set
var planets = [mercury, venus, earth, mars, jupiter, saturn];
var ascendingName = [earth, jupiter, mars, mercury, saturn, venus];
var planets = [mercury, venus, earth, mars, jupiter, saturn];
var ascendingName = [earth, jupiter, mars, mercury, saturn, venus];
var ascendingRadius = [mercury, mars, venus, earth, saturn, jupiter];
tableTest(
@ -115,16 +115,20 @@
planets,
ascendingName,
function ( $table ) {
$table.tablesorter( { sortList: [ { 0: 'asc' } ] } );
$table.tablesorter( { sortList: [
{ 0: 'asc' }
] } );
}
);
tableTest(
'Basic planet table: sorting initially - descending by radius',
header,
planets,
reversed(ascendingRadius),
reversed( ascendingRadius ),
function ( $table ) {
$table.tablesorter( { sortList: [ { 1: 'desc' } ] } );
$table.tablesorter( { sortList: [
{ 1: 'desc' }
] } );
}
);
tableTest(
@ -151,7 +155,7 @@
'Basic planet table: descending by name',
header,
planets,
reversed(ascendingName),
reversed( ascendingName ),
function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click().click();
@ -171,7 +175,7 @@
'Basic planet table: descending radius',
header,
planets,
reversed(ascendingRadius),
reversed( ascendingRadius ),
function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(1)' ).click().click();
@ -198,7 +202,10 @@
asc,
function ( $table ) {
$table.tablesorter(
{ sortList: [ { 0: 'asc' }, { 1: 'asc' } ] }
{ sortList: [
{ 0: 'asc' },
{ 1: 'asc' }
] }
);
}
);
@ -210,7 +217,10 @@
function ( $table ) {
$table.tablesorter();
$table.data( 'tablesorter' ).sort(
[ { 0: 'desc' }, { 1: 'asc' } ]
[
{ 0: 'desc' },
{ 1: 'asc' }
]
);
}
);
@ -221,10 +231,16 @@
asc,
function ( $table ) {
$table.tablesorter(
{ sortList: [ { 0: 'asc' }, { 1: 'asc' } ] }
{ sortList: [
{ 0: 'asc' },
{ 1: 'asc' }
] }
);
$table.data( 'tablesorter' ).sort(
[ { 0: 'desc' }, { 1: 'asc' } ]
[
{ 0: 'desc' },
{ 1: 'asc' }
]
);
$table.data( 'tablesorter' ).sort();
}
@ -232,7 +248,10 @@
QUnit.test( 'Reset sorting making table appear unsorted', 3, function ( assert ) {
var $table = tableCreate( header, initial );
$table.tablesorter(
{ sortList: [ { 0: 'desc' }, { 1: 'asc' } ] }
{ sortList: [
{ 0: 'desc' },
{ 1: 'asc' }
] }
);
$table.data( 'tablesorter' ).sort( [] );
@ -296,14 +315,16 @@
tableTest(
'Bug 28775: German-style (dmy) short numeric dates',
['Date'],
[ // German-style dates are day-month-year
[
// German-style dates are day-month-year
['11.11.2011'],
['01.11.2011'],
['02.10.2011'],
['03.08.2011'],
['09.11.2011']
],
[ // Sorted by ascending date
[
// Sorted by ascending date
['03.08.2011'],
['02.10.2011'],
['01.11.2011'],
@ -322,14 +343,16 @@
tableTest(
'Bug 28775: American-style (mdy) short numeric dates',
['Date'],
[ // American-style dates are month-day-year
[
// American-style dates are month-day-year
['11.11.2011'],
['01.11.2011'],
['02.10.2011'],
['03.08.2011'],
['09.11.2011']
],
[ // Sorted by ascending date
[
// Sorted by ascending date
['01.11.2011'],
['02.10.2011'],
['03.08.2011'],
@ -381,7 +404,7 @@
'Bug 17141: IPv4 address sorting (reverse)',
['IP'],
ipv4,
reversed(ipv4Sorted),
reversed( ipv4Sorted ),
function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click().click();
@ -422,7 +445,7 @@
'ä': 'ae',
'ö': 'oe',
'ß': 'ss',
'ü':'ue'
'ü': 'ue'
} );
$table.tablesorter();
@ -447,9 +470,16 @@
3,
'Rowspan not exploded'
);
});
} );
var planetsRowspan = [ [ 'Earth', '6051.8' ], jupiter, [ 'Mars', '6051.8' ], mercury, saturn, venus ];
var planetsRowspan = [
[ 'Earth', '6051.8' ],
jupiter,
[ 'Mars', '6051.8' ],
mercury,
saturn,
venus
];
var planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ];
tableTest(
@ -482,7 +512,9 @@
// This covers the removed cell in the 4th and 5th row.
$table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
$table.tablesorter( { sortList: [ { 0: 'asc' } ] } );
$table.tablesorter( { sortList: [
{ 0: 'asc' }
] } );
}
);
tableTest(
@ -566,7 +598,7 @@
}
);
var ascendingNameLegacy = ascendingName.slice(0);
var ascendingNameLegacy = ascendingName.slice( 0 );
ascendingNameLegacy[4] = ascendingNameLegacy[5];
ascendingNameLegacy.pop();
@ -575,7 +607,7 @@
header,
planets,
ascendingNameLegacy,
function( $table ) {
function ( $table ) {
$table.find( 'tr:last' ).addClass( 'sortbottom' );
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
@ -586,11 +618,11 @@
var $table;
$table = $(
'<table class="sortable">' +
'<caption>CAPTION</caption>' +
'<tr><th>THEAD</th></tr>' +
'<tr><td>1</td></tr>' +
'<tr class="sortbottom"><td>text</td></tr>' +
'</table>'
'<caption>CAPTION</caption>' +
'<tr><th>THEAD</th></tr>' +
'<tr><td>1</td></tr>' +
'<tr class="sortbottom"><td>text</td></tr>' +
'</table>'
);
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
@ -607,21 +639,21 @@
var $table;
$table = $(
'<table class="sortable">' +
'<caption>CAPTION</caption>' +
'<tr><th>THEAD</th></tr>' +
'<tr><td>A</td></tr>' +
'<tr><td>B</td></tr>' +
'<tr class="sortbottom"><td>TFOOT</td></tr>' +
'</table>'
);
'<caption>CAPTION</caption>' +
'<tr><th>THEAD</th></tr>' +
'<tr><td>A</td></tr>' +
'<tr><td>B</td></tr>' +
'<tr class="sortbottom"><td>TFOOT</td></tr>' +
'</table>'
);
$table.tablesorter();
assert.equal(
$table.children( ).get( 0 ).nodeName,
$table.children().get( 0 ).nodeName,
'CAPTION',
'First element after <thead> must be <caption> (bug 32047)'
);
});
} );
QUnit.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert ) {
var $table, data;
@ -636,34 +668,38 @@
'<tr><td data-sort-value="Bananna">Ferret</td></tr>' +
'<tr><td data-sort-value="Drupe">Elephant</td></tr>' +
'<tr><td data-sort-value="Cherry">Dolphin</td></tr>' +
'</tbody></table>'
'</tbody></table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
data = [];
$table.find( 'tbody > tr' ).each( function( i, tr ) {
$( tr ).find( 'td' ).each( function( i, td ) {
$table.find( 'tbody > tr' ).each( function ( i, tr ) {
$( tr ).find( 'td' ).each( function ( i, td ) {
data.push( {
data: $( td ).data( 'sortValue' ),
text: $( td ).text()
} );
});
});
} );
} );
assert.deepEqual( data, [
{
data: 'Apple',
text: 'Bird'
}, {
},
{
data: 'Bananna',
text: 'Ferret'
}, {
},
{
data: undefined,
text: 'Cheetah'
}, {
},
{
data: 'Cherry',
text: 'Dolphin'
}, {
},
{
data: 'Drupe',
text: 'Elephant'
}
@ -678,7 +714,7 @@
'<tr><td>B</td></tr>' +
'<tr><td>G</td></tr>' +
'<tr><td data-sort-value="F">C</td></tr>' +
'</tbody></table>'
'</tbody></table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
@ -689,23 +725,27 @@
data: $( td ).data( 'sortValue' ),
text: $( td ).text()
} );
});
});
} );
} );
assert.deepEqual( data, [
{
data: undefined,
text: 'B'
}, {
},
{
data: undefined,
text: 'D'
}, {
},
{
data: 'E',
text: 'A'
}, {
},
{
data: 'F',
text: 'C'
}, {
},
{
data: undefined,
text: 'G'
}
@ -721,7 +761,7 @@
'<tr><td>B</td></tr>' +
'<tr><td data-sort-value="2">G</td></tr>' +
'<tr><td>C</td></tr>' +
'</tbody></table>'
'</tbody></table>'
);
// initialize table sorter and sort once
$table
@ -741,35 +781,39 @@
$table.find( '.headerSort:eq(0)' ).click();
data = [];
$table.find( 'tbody > tr' ).each( function( i, tr ) {
$( tr ).find( 'td' ).each( function( i, td ) {
$table.find( 'tbody > tr' ).each( function ( i, tr ) {
$( tr ).find( 'td' ).each( function ( i, td ) {
data.push( {
data: $( td ).data( 'sortValue' ),
text: $( td ).text()
} );
});
});
} );
} );
assert.deepEqual( data, [
{
data: 1,
text: 'B'
}, {
},
{
data: 2,
text: 'G'
}, {
},
{
data: 3,
text: 'A'
}, {
},
{
data: undefined,
text: 'C'
}, {
},
{
data: undefined,
text: 'D'
}
], 'Order matches expected order, using the current sortValue in $.data()' );
});
} );
var numbers = [
[ '12' ],
@ -790,15 +834,15 @@
tableTest( 'bug 8115: sort numbers with commas (ascending)',
['Numbers'], numbers, numbersAsc,
function( $table ) {
function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
}
);
tableTest( 'bug 8115: sort numbers with commas (descending)',
['Numbers'], numbers, reversed(numbersAsc),
function( $table ) {
['Numbers'], numbers, reversed( numbersAsc ),
function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click().click();
}
@ -809,26 +853,26 @@
var $table;
$table = $(
'<table class="sortable" id="mw-bug-32888">' +
'<tr><th>header<table id="mw-bug-32888-2">'+
'<tr><th>header<table id="mw-bug-32888-2">' +
'<tr><th>1</th><th>2</th></tr>' +
'</table></th></tr>' +
'<tr><td>A</td></tr>' +
'<tr><td>B</td></tr>' +
'</table>'
);
'</table></th></tr>' +
'<tr><td>A</td></tr>' +
'<tr><td>B</td></tr>' +
'</table>'
);
$table.tablesorter();
assert.equal(
$table.find('> thead:eq(0) > tr > th.headerSort').length,
$table.find( '> thead:eq(0) > tr > th.headerSort' ).length,
1,
'Child tables inside a headercell should not interfere with sortable headers (bug 32888)'
);
assert.equal(
$( '#mw-bug-32888-2' ).find('th.headerSort').length,
$( '#mw-bug-32888-2' ).find( 'th.headerSort' ).length,
0,
'The headers of child tables inside a headercell should not be sortable themselves (bug 32888)'
);
});
} );
var correctDateSorting1 = [
@ -881,61 +925,60 @@
}
);
QUnit.test( 'Sorting images using alt text', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="2"/></td></tr>' +
'<tr><td>1</td></tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
QUnit.test( 'Sorting images using alt text', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="2"/></td></tr>' +
'<tr><td>1</td></tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
assert.equal(
$table.find( 'td' ).first().text(),
'1',
'Applied correct sorting order'
);
} );
assert.equal(
$table.find( 'td' ).first().text(),
'1',
'Applied correct sorting order'
);
} );
QUnit.test( 'Sorting images using alt text (complex)', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="D" />A</td></tr>' +
'<tr><td>CC</td></tr>' +
'<tr><td><a><img alt="A" /></a>F</tr>' +
'<tr><td><img alt="A" /><strong>E</strong></tr>' +
'<tr><td><strong><img alt="A" />D</strong></tr>' +
'<tr><td><img alt="A" />C</tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
QUnit.test( 'Sorting images using alt text (complex)', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="D" />A</td></tr>' +
'<tr><td>CC</td></tr>' +
'<tr><td><a><img alt="A" /></a>F</tr>' +
'<tr><td><img alt="A" /><strong>E</strong></tr>' +
'<tr><td><strong><img alt="A" />D</strong></tr>' +
'<tr><td><img alt="A" />C</tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
assert.equal(
$table.find( 'td' ).text(),
'CDEFCCA',
'Applied correct sorting order'
);
} );
assert.equal(
$table.find( 'td' ).text(),
'CDEFCCA',
'Applied correct sorting order'
);
} );
QUnit.test( 'Sorting images using alt text (with format autodetection)', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="1" />7</td></tr>' +
'<tr><td>1<img alt="6" /></td></tr>' +
'<tr><td>5</td></tr>' +
'<tr><td>4</td></tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
assert.equal(
$table.find( 'td' ).text(),
'4517',
'Applied correct sorting order'
);
} );
QUnit.test( 'Sorting images using alt text (with format autodetection)', function ( assert ) {
var $table = $(
'<table class="sortable">' +
'<tr><th>THEAD</th></tr>' +
'<tr><td><img alt="1" />7</td></tr>' +
'<tr><td>1<img alt="6" /></td></tr>' +
'<tr><td>5</td></tr>' +
'<tr><td>4</td></tr>' +
'</table>'
);
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
assert.equal(
$table.find( 'td' ).text(),
'4517',
'Applied correct sorting order'
);
} );
}( jQuery, mediaWiki ) );

View file

@ -14,22 +14,22 @@
* params {object} add'l parameters for $().textSelection( 'encapsulateText' )
*/
function encapsulateTest( options ) {
var opt = $.extend({
var opt = $.extend( {
description: '',
before: {},
after: {},
replace: {}
}, options);
}, options );
opt.before = $.extend({
opt.before = $.extend( {
text: '',
start: 0,
end: 0
}, opt.before);
opt.after = $.extend({
}, opt.before );
opt.after = $.extend( {
text: '',
selected: null
}, opt.after);
}, opt.after );
QUnit.test( opt.description, function ( assert ) {
/*jshint onevar: false */
@ -46,11 +46,11 @@
//$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
$textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
var start = opt.before.start,
var start = opt.before.start,
end = opt.before.end;
if ( window.opera ) {
// Compensate for Opera's craziness converting \n to \r\n and counting that as two chars
var newLinesBefore = opt.before.text.substring( 0, start ).split( '\n' ).length - 1,
var newLinesBefore = opt.before.text.substring( 0, start ).split( '\n' ).length - 1,
newLinesInside = opt.before.text.substring( start, end ).split( '\n' ).length - 1;
start += newLinesBefore;
end += newLinesBefore + newLinesInside;
@ -98,7 +98,7 @@
splitlines: true
};
encapsulateTest({
encapsulateTest( {
description: 'Adding sig to end of text',
before: {
text: 'Wikilove dude! ',
@ -110,9 +110,9 @@
selected: ''
},
replace: sig
});
} );
encapsulateTest({
encapsulateTest( {
description: 'Adding bold to empty',
before: {
text: '',
@ -124,9 +124,9 @@
selected: 'Bold text' // selected because it's the default
},
replace: bold
});
} );
encapsulateTest({
encapsulateTest( {
description: 'Adding bold to existing text',
before: {
text: 'Now is the time for all good men to come to the aid of their country',
@ -138,12 +138,12 @@
selected: '' // empty because it's not the default'
},
replace: bold
});
} );
encapsulateTest({
encapsulateTest( {
description: 'ownline option: adding new h2',
before: {
text:'Before\nAfter',
text: 'Before\nAfter',
start: 7,
end: 7
},
@ -152,12 +152,12 @@
selected: 'Heading 2'
},
replace: h2
});
} );
encapsulateTest({
encapsulateTest( {
description: 'ownline option: turn a whole line into new h2',
before: {
text:'Before\nMy heading\nAfter',
text: 'Before\nMy heading\nAfter',
start: 7,
end: 17
},
@ -166,13 +166,13 @@
selected: ''
},
replace: h2
});
} );
encapsulateTest({
encapsulateTest( {
description: 'ownline option: turn a partial line into new h2',
before: {
text:'BeforeMy headingAfter',
text: 'BeforeMy headingAfter',
start: 6,
end: 16
},
@ -181,10 +181,10 @@
selected: ''
},
replace: h2
});
} );
encapsulateTest({
encapsulateTest( {
description: 'splitlines option: no selection, insert new list item',
before: {
text: 'Before\nAfter',
@ -195,9 +195,9 @@
text: 'Before\n* Bulleted list item\nAfter'
},
replace: ulist
});
} );
encapsulateTest({
encapsulateTest( {
description: 'splitlines option: single partial line selection, insert new list item',
before: {
text: 'BeforeMy List ItemAfter',
@ -208,9 +208,9 @@
text: 'Before\n* My List Item\nAfter'
},
replace: ulist
});
} );
encapsulateTest({
encapsulateTest( {
description: 'splitlines option: multiple lines',
before: {
text: 'Before\nFirst\nSecond\nThird\nAfter',
@ -221,7 +221,7 @@
text: 'Before\n* First\n* Second\n* Third\nAfter'
},
replace: ulist
});
} );
function caretTest( options ) {
@ -231,52 +231,52 @@
$( '#qunit-fixture' ).append( $textarea );
if ( options.mode === 'set' ) {
$textarea.textSelection('setSelection', {
$textarea.textSelection( 'setSelection', {
start: options.start,
end: options.end
});
} );
}
function among( actual, expected, message ) {
if ( $.isArray( expected ) ) {
assert.ok( $.inArray( actual, expected ) !== -1 , message + ' (got ' + actual + '; expected one of ' + expected.join(', ') + ')' );
assert.ok( $.inArray( actual, expected ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
} else {
assert.equal( actual, expected, message );
}
}
pos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true });
among(pos[0], options.start, 'Caret start should be where we set it.');
among(pos[1], options.end, 'Caret end should be where we set it.');
});
pos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
among( pos[0], options.start, 'Caret start should be where we set it.' );
among( pos[1], options.end, 'Caret end should be where we set it.' );
} );
}
caretSample = 'Some big text that we like to work with. Nothing fancy... you know what I mean?';
/*
// @broken: Disabled per bug 34820
caretTest({
description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8',
text: caretSample,
start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length)
end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
mode: 'get'
});
*/
// @broken: Disabled per bug 34820
caretTest({
description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8',
text: caretSample,
start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length)
end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
mode: 'get'
});
*/
caretTest({
caretTest( {
description: 'set/getCaretPosition with forced empty selection',
text: caretSample,
start: 7,
end: 7,
mode: 'set'
});
} );
caretTest({
caretTest( {
description: 'set/getCaretPosition with small selection',
text: caretSample,
start: 6,
end: 11,
mode: 'set'
});
} );
}( jQuery ) );

View file

@ -10,25 +10,25 @@
d1 = api.get( {} )
.done( function ( data ) {
assert.deepEqual( data, [], 'If request succeeds without errors, resolve deferred' );
});
} );
d2 = api.get({
action: 'doesntexist'
})
d2 = api.get( {
action: 'doesntexist'
} )
.fail( function ( errorCode ) {
assert.equal( errorCode, 'unknown_action', 'API error (e.g. "unknown_action") should reject the deferred' );
});
} );
d3 = api.post( {} )
.done( function ( data ) {
assert.deepEqual( data, [], 'Simple POST request' );
});
} );
// After all are completed, continue the test suite.
QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
QUnit.start();
});
});
} );
} );
QUnit.asyncTest( 'Deprecated callback methods', function ( assert ) {
var api, d1, d2, d3;
@ -38,24 +38,24 @@
d1 = api.get( {}, function () {
assert.ok( true, 'Function argument treated as success callback.' );
});
} );
d2 = api.get( {}, {
ok: function () {
assert.ok( true, '"ok" property treated as success callback.' );
}
});
} );
d3 = api.get({
action: 'doesntexist'
}, {
d3 = api.get( {
action: 'doesntexist'
}, {
err: function () {
assert.ok( true, '"err" property treated as error callback.' );
}
});
} );
QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
QUnit.start();
});
});
} );
} );
}( mediaWiki ) );

View file

@ -7,23 +7,21 @@
var selectHtml, $env, $options;
// from Special:Recentchanges
selectHtml =
'<select id="namespace" name="namespace" class="namespaceselector">'
+ '<option value="" selected="selected">all</option>'
+ '<option value="0">(Main)</option>'
+ '<option value="1">Talk</option>'
+ '<option value="2">User</option>'
+ '<option value="3">User talk</option>'
+ '<option value="4">ProjectName</option>'
+ '<option value="5">ProjectName talk</option>'
+ '</select>'
+ '<input name="invert" type="checkbox" value="1" id="nsinvert" title="no title" />'
+ '<label for="nsinvert" title="no title">Invert selection</label>'
+ '<input name="associated" type="checkbox" value="1" id="nsassociated" title="no title" />'
+ '<label for="nsassociated" title="no title">Associated namespace</label>'
+ '<input type="submit" value="Go" />'
+ '<input type="hidden" value="Special:RecentChanges" name="title" />'
;
selectHtml = '<select id="namespace" name="namespace" class="namespaceselector">'
+ '<option value="" selected="selected">all</option>'
+ '<option value="0">(Main)</option>'
+ '<option value="1">Talk</option>'
+ '<option value="2">User</option>'
+ '<option value="3">User talk</option>'
+ '<option value="4">ProjectName</option>'
+ '<option value="5">ProjectName talk</option>'
+ '</select>'
+ '<input name="invert" type="checkbox" value="1" id="nsinvert" title="no title" />'
+ '<label for="nsinvert" title="no title">Invert selection</label>'
+ '<input name="associated" type="checkbox" value="1" id="nsassociated" title="no title" />'
+ '<label for="nsassociated" title="no title">Associated namespace</label>'
+ '<input type="submit" value="Go" />'
+ '<input type="hidden" value="Special:RecentChanges" name="title" />';
$env = $( '<div>' ).html( selectHtml ).appendTo( 'body' );
@ -42,8 +40,8 @@
// select second option...
$options = $( '#namespace' ).find( 'option' );
$options.eq(0).removeProp( 'selected' );
$options.eq(1).prop( 'selected', true );
$options.eq( 0 ).removeProp( 'selected' );
$options.eq( 1 ).prop( 'selected', true );
$( '#namespace' ).change();
// ... and checkboxes should be enabled again
@ -51,8 +49,8 @@
assert.strictEqual( $( '#nsassociated' ).prop( 'disabled' ), false );
// select first option ( 'all' namespace)...
$options.eq(1).removeProp( 'selected' );
$options.eq(0).prop( 'selected', true );
$options.eq( 1 ).removeProp( 'selected' );
$options.eq( 0 ).prop( 'selected', true );
$( '#namespace' ).change();
// ... and checkboxes should now be disabled
@ -61,5 +59,5 @@
// DOM cleanup
$env.remove();
});
} );
}( mediaWiki, jQuery ) );

View file

@ -1,201 +1,198 @@
( function ( mw ) {
// mw.Title relies on these three config vars
// Restore them after each test run
var config = {
wgFormattedNamespaces: {
'-2': 'Media',
'-1': 'Special',
0: '',
1: 'Talk',
2: 'User',
3: 'User talk',
4: 'Wikipedia',
5: 'Wikipedia talk',
6: 'File',
7: 'File talk',
8: 'MediaWiki',
9: 'MediaWiki talk',
10: 'Template',
11: 'Template talk',
12: 'Help',
13: 'Help talk',
14: 'Category',
15: 'Category talk',
// testing custom / localized namespace
100: 'Penguins'
},
wgNamespaceIds: {
/*jshint camelcase: false */
media: -2,
special: -1,
'': 0,
talk: 1,
user: 2,
user_talk: 3,
wikipedia: 4,
wikipedia_talk: 5,
file: 6,
file_talk: 7,
mediawiki: 8,
mediawiki_talk: 9,
template: 10,
template_talk: 11,
help: 12,
help_talk: 13,
category: 14,
category_talk: 15,
image: 6,
image_talk: 7,
project: 4,
project_talk: 5,
/* testing custom / alias */
penguins: 100,
antarctic_waterfowl: 100
},
wgCaseSensitiveNamespaces: []
};
// mw.Title relies on these three config vars
// Restore them after each test run
var config = {
wgFormattedNamespaces: {
'-2': 'Media',
'-1': 'Special',
0: '',
1: 'Talk',
2: 'User',
3: 'User talk',
4: 'Wikipedia',
5: 'Wikipedia talk',
6: 'File',
7: 'File talk',
8: 'MediaWiki',
9: 'MediaWiki talk',
10: 'Template',
11: 'Template talk',
12: 'Help',
13: 'Help talk',
14: 'Category',
15: 'Category talk',
// testing custom / localized namespace
100: 'Penguins'
},
wgNamespaceIds: {
/*jshint camelcase: false */
media: -2,
special: -1,
'': 0,
talk: 1,
user: 2,
user_talk: 3,
wikipedia: 4,
wikipedia_talk: 5,
file: 6,
file_talk: 7,
mediawiki: 8,
mediawiki_talk: 9,
template: 10,
template_talk: 11,
help: 12,
help_talk: 13,
category: 14,
category_talk: 15,
image: 6,
image_talk: 7,
project: 4,
project_talk: 5,
/* testing custom / alias */
penguins: 100,
antarctic_waterfowl: 100
},
wgCaseSensitiveNamespaces: []
};
QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment( { config: config } ) );
QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment({ config: config }) );
QUnit.test( 'Transformation', 8, function ( assert ) {
var title;
title = new mw.Title( 'File:quux pif.jpg' );
assert.equal( title.getName(), 'Quux_pif' );
QUnit.test( 'Transformation', 8, function ( assert ) {
var title;
title = new mw.Title( 'File:Glarg_foo_glang.jpg' );
assert.equal( title.getNameText(), 'Glarg foo glang' );
title = new mw.Title( 'File:quux pif.jpg' );
assert.equal( title.getName(), 'Quux_pif' );
title = new mw.Title( 'User:ABC.DEF' );
assert.equal( title.toText(), 'User:ABC.DEF' );
assert.equal( title.getNamespaceId(), 2 );
assert.equal( title.getNamespacePrefix(), 'User:' );
title = new mw.Title( 'File:Glarg_foo_glang.jpg' );
assert.equal( title.getNameText(), 'Glarg foo glang' );
title = new mw.Title( 'uSEr:hAshAr' );
assert.equal( title.toText(), 'User:HAshAr' );
assert.equal( title.getNamespaceId(), 2 );
title = new mw.Title( 'User:ABC.DEF' );
assert.equal( title.toText(), 'User:ABC.DEF' );
assert.equal( title.getNamespaceId(), 2 );
assert.equal( title.getNamespacePrefix(), 'User:' );
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
assert.equal( title.getName(), 'Foo_bar_.js', 'Merge multiple spaces to a single space.' );
} );
title = new mw.Title( 'uSEr:hAshAr' );
assert.equal( title.toText(), 'User:HAshAr' );
assert.equal( title.getNamespaceId(), 2 );
QUnit.test( 'Main text for filename', 8, function ( assert ) {
var title = new mw.Title( 'File:foo_bar.JPG' );
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
assert.equal( title.getName(), 'Foo_bar_.js', 'Merge multiple spaces to a single space.' );
});
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' );
} );
QUnit.test( 'Main text for filename', 8, function ( assert ) {
var title = new mw.Title( 'File:foo_bar.JPG' );
QUnit.test( 'Namespace detection and conversion', 6, function ( assert ) {
var title;
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' );
});
title = new mw.Title( 'something.PDF', 6 );
assert.equal( title.toString(), 'File:Something.PDF' );
QUnit.test( 'Namespace detection and conversion', 6, function ( assert ) {
var title;
title = new mw.Title( 'NeilK', 3 );
assert.equal( title.toString(), 'User_talk:NeilK' );
assert.equal( title.toText(), 'User talk:NeilK' );
title = new mw.Title( 'something.PDF', 6 );
assert.equal( title.toString(), 'File:Something.PDF' );
title = new mw.Title( 'Frobisher', 100 );
assert.equal( title.toString(), 'Penguins:Frobisher' );
title = new mw.Title( 'NeilK', 3 );
assert.equal( title.toString(), 'User_talk:NeilK' );
assert.equal( title.toText(), 'User talk:NeilK' );
title = new mw.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
title = new mw.Title( 'Frobisher', 100 );
assert.equal( title.toString(), 'Penguins:Frobisher' );
title = new mw.Title( 'Penguins:flightless_yet_cute.jpg' );
assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
} );
title = new mw.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
assert.throws( function () {
return new mw.Title( '' );
}, 'Throw error on empty string' );
} );
title = new mw.Title( 'Penguins:flightless_yet_cute.jpg' );
assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
});
QUnit.test( 'Case-sensivity', 3, function ( assert ) {
var title;
QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
assert.throws(function () {
return new mw.Title( '' );
}, 'Throw error on empty string' );
});
// Default config
mw.config.set( 'wgCaseSensitiveNamespaces', [] );
QUnit.test( 'Case-sensivity', 3, function ( assert ) {
var title;
title = new mw.Title( 'article' );
assert.equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
// Default config
mw.config.set( 'wgCaseSensitiveNamespaces', [] );
// $wgCapitalLinks = false;
mw.config.set( 'wgCaseSensitiveNamespaces', [0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15] );
title = new mw.Title( 'article' );
assert.equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
title = new mw.Title( 'article' );
assert.equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
// $wgCapitalLinks = false;
mw.config.set( 'wgCaseSensitiveNamespaces', [0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15] );
title = new mw.Title( 'john', 2 );
assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
} );
title = new mw.Title( 'article' );
assert.equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
QUnit.test( 'toString / toText', 2, function ( assert ) {
var title = new mw.Title( 'Some random page' );
title = new mw.Title( 'john', 2 );
assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
});
assert.equal( title.toString(), title.getPrefixedDb() );
assert.equal( title.toText(), title.getPrefixedText() );
} );
QUnit.test( 'toString / toText', 2, function ( assert ) {
var title = new mw.Title( 'Some random page' );
QUnit.test( 'getExtension', 7, function ( assert ) {
function extTest( pagename, ext, description ) {
var title = new mw.Title( pagename );
assert.equal( title.getExtension(), ext, description || pagename );
}
assert.equal( title.toString(), title.getPrefixedDb() );
assert.equal( title.toText(), title.getPrefixedText() );
});
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' );
QUnit.test( 'getExtension', 7, function ( assert ) {
// @broken: Throws an exception
// extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
} );
function extTest( pagename, ext, description ) {
var title = new mw.Title( pagename );
assert.equal( title.getExtension(), ext, description || pagename );
}
QUnit.test( 'exists', 3, function ( assert ) {
var title;
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' );
// Empty registry, checks default to null
// @broken: Throws an exception
// extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
});
title = new mw.Title( 'Some random page', 4 );
assert.strictEqual( title.exists(), null, 'Return null with empty existance registry' );
QUnit.test( 'exists', 3, function ( assert ) {
var title;
// 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 );
// Empty registry, checks default to null
title = new mw.Title( 'Project:Sandbox rules' );
assert.assertTrue( title.exists(), 'Return true for page titles marked as existing' );
title = new mw.Title( 'Foobar' );
assert.assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );
title = new mw.Title( 'Some random page', 4 );
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 );
QUnit.test( 'getUrl', 2, function ( assert ) {
var title;
title = new mw.Title( 'Project:Sandbox rules' );
assert.assertTrue( title.exists(), 'Return true for page titles marked as existing' );
title = new mw.Title( 'Foobar' );
assert.assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );
// Config
mw.config.set( 'wgArticlePath', '/wiki/$1' );
});
title = new mw.Title( 'Foobar' );
assert.equal( title.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
QUnit.test( 'getUrl', 2, function ( assert ) {
var title;
title = new mw.Title( 'John Doe', 3 );
assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
} );
// Config
mw.config.set( 'wgArticlePath', '/wiki/$1' );
title = new mw.Title( 'Foobar' );
assert.equal( title.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
title = new mw.Title( 'John Doe', 3 );
assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
});
}( mediaWiki ) );
}( mediaWiki ) );

View file

@ -1,5 +1,5 @@
( function ( mw, $ ) {
QUnit.module( 'mediawiki.Uri', QUnit.newMwEnvironment({
QUnit.module( 'mediawiki.Uri', QUnit.newMwEnvironment( {
setup: function () {
this.mwUriOrg = mw.Uri;
mw.Uri = mw.UriRelative( 'http://example.org/w/index.php' );
@ -8,7 +8,7 @@
mw.Uri = this.mwUriOrg;
delete this.mwUriOrg;
}
}) );
} ) );
$.each( [true, false], function ( i, strictMode ) {
QUnit.test( 'Basic construction and properties (' + ( strictMode ? '' : 'non-' ) + 'strict mode)', 2, function ( assert ) {
@ -16,7 +16,7 @@
uriString = 'http://www.ietf.org/rfc/rfc2396.txt';
uri = new mw.Uri( uriString, {
strictMode: strictMode
});
} );
assert.deepEqual(
{
@ -56,16 +56,15 @@
},
'construct composite components of URI on request'
);
});
});
} );
} );
QUnit.test( 'Constructor( String[, Object ] )', 10, function ( assert ) {
var uri;
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
overrideKeys: true
});
} );
// Strict comparison to assert that numerical values stay strings
assert.strictEqual( uri.query.n, '1', 'Simple parameter with overrideKeys:true' );
@ -73,7 +72,7 @@
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
overrideKeys: false
});
} );
assert.strictEqual( uri.query.n, '1', 'Simple parameter with overrideKeys:false' );
assert.strictEqual( uri.query.m[0], 'foo', 'Order of multi-value parameters with overrideKeys:true' );
@ -120,7 +119,7 @@
function () {
return new mw.Uri( 'foo.com/bar/baz', {
strictMode: true
});
} );
},
function ( e ) {
return e.message === 'Bad constructor arguments';
@ -130,33 +129,33 @@
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( 'Constructor( Object )', 3, function ( assert ) {
var uri = new mw.Uri({
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({
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 () {
return new mw.Uri({
return new mw.Uri( {
protocol: 'http',
host: 'www.foo.local'
});
} );
},
function ( e ) {
return e.message === 'Bad constructor arguments';
@ -208,13 +207,13 @@
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({
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' );
assert.ok( uri.toString().indexOf( 'pif=paf' ) >= 0, 'extend query arguments' );
} );
QUnit.test( '.getQueryString()', 2, function ( assert ) {
@ -280,7 +279,7 @@
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
overrideKeys: true
});
} );
uri.query.n = [ 'x', 'y', 'z' ];
@ -292,7 +291,7 @@
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
overrideKeys: false
});
} );
// Change query values
uri.query.n = [ 'x', 'y', 'z' ];

View file

@ -14,7 +14,7 @@
assert.deepEqual( ŝablono, orig, 'ŝablono' );
assert.deepEqual( \u015dablono, orig, '\\u015dablono' );
assert.deepEqual( \u015Dablono, orig, '\\u015Dablono' );
});
} );
/*
// Not that we need this. ;)
@ -58,13 +58,13 @@
}
for ( n = 0; n < maxn; n++ ) {
expected = repeat('\n', n) + 'some text';
expected = repeat( '\n', n ) + 'some text';
$textarea = $('<textarea>\n' + expected + '</textarea>');
$textarea = $( '<textarea>\n' + expected + '</textarea>' );
assert.equal( $textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + (n + 1) + ')' );
$textarea = $('<textarea>').val( expected );
$textarea = $( '<textarea>' ).val( expected );
assert.equal( $textarea.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')' );
}
});
} );
}( jQuery ) );

File diff suppressed because it is too large Load diff

View file

@ -1,55 +1,53 @@
( function ( mw, $ ) {
QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment() );
QUnit.test( 'options', 1, function ( assert ) {
assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
} );
QUnit.test( 'options', 1, function ( assert ) {
assert.ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
});
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.
* 2) Logged in on [[Special:JavaScriptTest/qunit]]
* 3) Anonymously at the same special page.
*/
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.
* 2) Logged in on [[Special:JavaScriptTest/qunit]]
* 3) Anonymously at the same special page.
*/
// Forge an anonymous user:
mw.config.set( 'wgUserName', null );
// Forge an anonymous user:
mw.config.set( 'wgUserName', null );
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' );
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' );
// Not part of startUp module
mw.config.set( 'wgUserName', 'John' );
assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
assert.equal( mw.user.name(), 'John', 'user.name() compatibility' );
assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
assert.assertFalse( mw.user.anonymous(), 'user.anonymous() compatibility' );
assert.equal( mw.user.getName(), 'John', 'user.getName() returns username when logged-in' );
assert.equal( mw.user.name(), 'John', 'user.name() compatibility' );
assert.assertFalse( mw.user.isAnon(), 'user.isAnon() returns false when logged-in' );
assert.assertFalse( mw.user.anonymous(), 'user.anonymous() compatibility' );
assert.equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
} );
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 ) {
assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
QUnit.start();
});
});
QUnit.asyncTest( 'getGroups', 3, function ( assert ) {
mw.user.getGroups( function ( groups ) {
// First group should always be '*'
assert.equal( $.type( groups ), 'array', 'Callback gets an array' );
assert.notStrictEqual( $.inArray( '*', groups ), -1, '"*"" is in the list' );
// Sort needed because of different methods if creating the arrays,
// only the content matters.
assert.deepEqual( groups.sort(), mw.config.get( 'wgUserGroups' ).sort(), 'Array contains all groups, just like wgUserGroups' );
QUnit.start();
} );
} );
QUnit.asyncTest( 'getRights', 1, function ( assert ) {
mw.user.getRights( function ( rights ) {
assert.equal( $.type( rights ), 'array', 'Callback gets an array' );
QUnit.start();
} );
} );
}( mediaWiki, jQuery ) );

View file

@ -3,11 +3,11 @@
QUnit.test( 'rawurlencode', 1, function ( assert ) {
assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
});
} );
QUnit.test( 'wikiUrlencode', 1, function ( assert ) {
assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
});
} );
QUnit.test( 'wikiGetlink', 3, function ( assert ) {
// Not part of startUp module
@ -23,15 +23,15 @@
href = mw.util.wikiGetlink();
assert.equal( href, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
});
} );
QUnit.test( 'wikiScript', 4, function ( assert ) {
mw.config.set({
mw.config.set( {
'wgScript': '/w/i.php', // customized wgScript for bug 39103
'wgLoadScript': '/w/l.php', // customized wgLoadScript for bug 39103
'wgScriptPath': '/w',
'wgScriptExtension': '.php'
});
} );
assert.equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ),
'wikiScript() returns wgScript'
@ -43,7 +43,7 @@
'wikiScript( load ) returns wgLoadScript'
);
assert.equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
});
} );
QUnit.test( 'addCSS', 3, function ( assert ) {
var $el, style;
@ -57,7 +57,7 @@
// Clean up
$( style.ownerNode ).remove();
});
} );
QUnit.asyncTest( 'toggleToc', 4, function ( assert ) {
var tocHtml, $toggleLink;
@ -76,24 +76,23 @@
assert.strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
tocHtml =
'<table id="toc" class="toc"><tr><td>' +
'<div id="toctitle">' +
'<h2>Contents</h2>' +
'<span class="toctoggle">&nbsp;[<a href="#" class="internal" id="togglelink">Hide</a>&nbsp;]</span>' +
'</div>' +
'<ul><li></li></ul>' +
tocHtml = '<table id="toc" class="toc"><tr><td>' +
'<div id="toctitle">' +
'<h2>Contents</h2>' +
'<span class="toctoggle">&nbsp;[<a href="#" class="internal" id="togglelink">Hide</a>&nbsp;]</span>' +
'</div>' +
'<ul><li></li></ul>' +
'</td></tr></table>';
$(tocHtml).appendTo( '#qunit-fixture' ),
$toggleLink = $( '#togglelink' );
$( tocHtml ).appendTo( '#qunit-fixture' ),
$toggleLink = $( '#togglelink' );
assert.strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
actionA();
});
} );
QUnit.test( 'getParamValue', 5, function ( assert ) {
var url;
var url;
url = 'http://example.org/?foo=wrong&foo=right#&foo=bad';
assert.equal( mw.util.getParamValue( 'foo', url ), 'right', 'Use latest one, ignore hash' );
@ -102,24 +101,23 @@
url = 'http://example.org/#&foo=bad';
assert.strictEqual( mw.util.getParamValue( 'foo', url ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' );
url = 'example.org?' + $.param({ 'TEST': 'a b+c' });
url = 'example.org?' + $.param( { 'TEST': 'a b+c' } );
assert.strictEqual( mw.util.getParamValue( 'TEST', url ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' );
url = 'example.org?' + $.param({ 'TEST': 'a b+c d' }); // check for sloppy code from r95332 :)
url = 'example.org?' + $.param( { 'TEST': 'a b+c d' } ); // check for sloppy code from r95332 :)
assert.strictEqual( mw.util.getParamValue( 'TEST', url ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' );
});
} );
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' );
});
} );
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' );
});
} );
/**
* Portlet names are prefixed with 'p-test' to avoid conflict with core
@ -170,7 +168,7 @@
assert.equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux' );
$cuQuux = $(cuQuux);
$cuQuux = $( cuQuux );
assert.equal(
$( '#p-test-custom #c-barmenu ul li' ).length,
@ -185,9 +183,9 @@
caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' );
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.' );
});
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>.' );
@ -195,7 +193,7 @@
// Clean up
$( '#mw-js-message' ).remove();
});
} );
QUnit.test( 'validateEmail', 6, function ( assert ) {
assert.strictEqual( mw.util.validateEmail( '' ), null, 'Should return null for empty string ' );
@ -208,13 +206,14 @@
// testEmailWithHyphens
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' );
});
} );
QUnit.test( 'isIPv6Address', 40, function ( assert ) {
// Shortcuts
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 );
}
@ -226,14 +225,14 @@
assertFalseIPv6( 'fc:100:300', 'IPv6 with only 3 words' );
$.each(
['fc:100::',
'fc:100:a::',
'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 ){
assertTrueIPv6( addy, addy + ' is a valid IP' );
});
['fc:100::',
'fc:100:a::',
'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 ) {
assertTrueIPv6( addy, addy + ' is a valid IP' );
} );
assertFalseIPv6( 'fc:100:a:d:1:e:ac:0::', 'IPv6 with 8 words ending with "::"' );
assertFalseIPv6( 'fc:100:a:d:1:e:ac:0:1::', 'IPv6 with 9 words ending with "::"' );
@ -243,18 +242,18 @@
assertTrueIPv6( '::', 'IPv6 zero address' );
$.each(
['::0',
'::fc',
'::fc:100',
'::fc:100:a',
'::fc:100:a:d',
'::fc:100:a:d:1',
'::fc:100:a:d:1:e',
'::fc:100:a:d:1:e:ac',
['::0',
'::fc',
'::fc:100',
'::fc:100:a',
'::fc:100:a:d',
'::fc:100:a:d:1',
'::fc:100:a:d:1:e',
'::fc:100:a:d:1:e:ac',
'fc:100:a:d:1:e:ac:0'], function ( i, addy ){
assertTrueIPv6( addy, addy + ' is a valid IP' );
});
'fc:100:a:d:1:e:ac:0'], function ( i, addy ) {
assertTrueIPv6( addy, addy + ' is a valid IP' );
} );
assertFalseIPv6( '::fc:100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
assertFalseIPv6( '::fc:100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
@ -275,13 +274,14 @@
assertFalseIPv6( 'fc::100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
assertFalseIPv6( 'fc::100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
});
} );
QUnit.test( 'isIPv4Address', 11, function ( assert ) {
// Shortcuts
function assertFalseIPv4( addy, summary ) {
assert.strictEqual( mw.util.isIPv4Address( addy ), false, summary );
}
function assertTrueIPv4( addy, summary ) {
assert.strictEqual( mw.util.isIPv4Address( addy ), true, summary );
}
@ -299,5 +299,5 @@
assertTrueIPv4( '124.24.52.13', '124.24.52.134 is a valid IP' );
assertTrueIPv4( '1.24.52.13', '1.24.52.13 is a valid IP' );
assertFalseIPv4( '74.24.52.13/20', 'IPv4 ranges are not recogzized as valid IPs' );
});
} );
}( mediaWiki, jQuery ) );