r89845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89844‎ | r89845 | r89846 >
Date:19:55, 10 June 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Review of unit test suites
* There's more than ok(), equal() and deepEqual(). Using the others as appropriate.
** Considered: strictEqual(a,b) tests the same as ok(a===b). But the latter doesn't include the values in the report when it fails. So strictEqual saves a lot of time in debugging (especially on TestSwarm where the report is all you have, there "not okay" or "Expected { foo: 500 }, Given: ['bar', '250']" is a big saver.
* Adding an "expect" to every test.
* Applying whitespace conventions and bringing consistency in the use of mw, mediaWiki, $, $j, jQuery. (except in the initial test where the aliases are being checked)
* Added cleanup for added CSSStyleSheet
* Making IPtest more complete (Based on IPTest.php)
Modified paths:
  • /trunk/phase3/tests/qunit/sample/awesome.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.client.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.colorUtil.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.user.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/sample/awesome.js
@@ -1,4 +1,4 @@
22 window.mw.loader.testCallback = function(){
33 start();
4 - deepEqual( true, true, 'Implementing a module, is the callback timed properly ?');
 4+ ok( true, 'Implementing a module, is the callback timed properly ?');
55 };
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.colorUtil.js
@@ -1,73 +1,71 @@
22 module( 'jquery.colorUtil.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
55 expect(1);
6 - ok( jQuery.colorUtil, 'jQuery.colorUtil defined' );
 6+ ok( $.colorUtil, '$.colorUtil defined' );
77 });
88
9 -test( 'getRGB', function(){
 9+test( 'getRGB', function() {
1010 expect(18);
1111
12 - equal( typeof jQuery.colorUtil.getRGB(), 'undefined', 'No arguments' );
13 - equal( typeof jQuery.colorUtil.getRGB( '' ), 'undefined', 'Empty string' );
14 - deepEqual( jQuery.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Array' );
15 - deepEqual( jQuery.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple string' );
16 - deepEqual( jQuery.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple string (whitespace)' );
17 - deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse percentages string' );
18 - deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse percentages string (whitespace)' );
19 - deepEqual( jQuery.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
20 - deepEqual( jQuery.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
21 - deepEqual( jQuery.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
22 - deepEqual( jQuery.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
23 - deepEqual( jQuery.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
24 - deepEqual( jQuery.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
25 - deepEqual( jQuery.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
26 - // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep track
27 - // would that ever change
28 - equal( typeof jQuery.colorUtil.getRGB( 'rgba(0,0,0,0)' ), 'undefined', 'Zero rgba without whitespace' );
29 -
30 - deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
31 - deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
32 - equal( typeof jQuery.colorUtil.getRGB( 'mediaWiki' ), 'undefined', 'Inexisting color name' );
 12+ strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' );
 13+ strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' );
 14+ deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' );
 15+ deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' );
 16+ deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' );
 17+ deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' );
 18+ deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' );
 19+ deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
 20+ deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
 21+ deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
 22+ deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
 23+ deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
 24+ deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
 25+ deepEqual( $.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
3326
 27+ // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep
 28+ // track of it, so we will know in case it would ever change.
 29+ strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' );
 30+
 31+ deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
 32+ deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
 33+ strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
3434 });
3535
36 -test( 'rgbToHsl', function(){
37 - expect(4);
 36+test( 'rgbToHsl', function() {
 37+ expect(1);
3838
39 - var hsl = jQuery.colorUtil.rgbToHsl( 144, 238, 144 );
 39+ var hsl = $.colorUtil.rgbToHsl( 144, 238, 144 );
 40+
 41+ // Cross-browser differences in decimals...
 42+ // Round to two decimals so they can be more reliably checked.
4043 var dualDecimals = function(a,b){
4144 return Math.round(a*100)/100;
4245 };
 46+ // Re-create the rgbToHsl return array items, limited to two decimals.
 47+ var ret = [dualDecimals(hsl[0]), dualDecimals(hsl[1]), dualDecimals(hsl[2])];
4348
44 - ok( hsl, 'Basic return evaluation' );
45 - deepEqual( dualDecimals(hsl[0]) , 0.33, 'rgb(144, 238, 144): H 0.33' );
46 - deepEqual( dualDecimals(hsl[1]) , 0.73, 'rgb(144, 238, 144): S 0.73' );
47 - deepEqual( dualDecimals(hsl[2]) , 0.75, 'rgb(144, 238, 144): L 0.75' );
48 -
 49+ deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' );
4950 });
5051
51 -test( 'hslToRgb', function(){
52 - expect(4);
 52+test( 'hslToRgb', function() {
 53+ expect(1);
5354
54 - var rgb = jQuery.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
 55+ var rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
5556
56 - ok( rgb, 'Basic return evaluation' );
57 - deepEqual( Math.round(rgb[0]) , 183, 'hsl(0.3, 0.7, 0.8): R 183' );
58 - deepEqual( Math.round(rgb[1]) , 240, 'hsl(0.3, 0.7, 0.8): G 240' );
59 - deepEqual( Math.round(rgb[2]) , 168, 'hsl(0.3, 0.7, 0.8): B 168' );
 57+ // Cross-browser differences in decimals...
 58+ // Re-create the hslToRgb return array items, rounded to whole numbers.
 59+ var ret = [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])];
6060
 61+ deepEqual( ret ,[183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' );
6162 });
6263
63 -test( 'getColorBrightness', function(){
 64+test( 'getColorBrightness', function() {
6465 expect(2);
6566
66 - var a = jQuery.colorUtil.getColorBrightness( 'red', +0.1 );
 67+ var a = $.colorUtil.getColorBrightness( 'red', +0.1 );
 68+ equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' );
6769
68 - equal( a, 'rgb(255,50,50)', 'Start with named color, brighten 10%' );
69 -
70 - var b = jQuery.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
71 -
72 - equal( b, 'rgb(118,29,29)', 'Start with rgb string, darken 10%' );
73 -
 70+ var b = $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
 71+ equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' );
7472 });
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js
@@ -1,58 +1,56 @@
22 module( 'jquery.mwPrototypes.js' );
33
4 -test( 'String functions', function(){
 4+test( 'String functions', function() {
55
6 - equal( $j.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
7 - equal( $j.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
8 - equal( $j.ucFirst( 'foo'), 'Foo', 'ucFirst' );
 6+ equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
 7+ equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
 8+ equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
99
10 - equal( $j.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
 10+ equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
1111 '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
12 - equal( $j.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
 12+ equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
1313 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
14 - equal( $j.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
 14+ equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
1515 'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
16 - equal( $j.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
17 -
 16+ equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
1817 });
1918
20 -test( 'Is functions', function(){
 19+test( 'Is functions', function() {
2120
22 - deepEqual( $j.isDomElement( document.getElementById( 'qunit-header' ) ), true,
 21+ strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
2322 'isDomElement: #qunit-header Node' );
24 - deepEqual( $j.isDomElement( document.getElementById( 'random-name' ) ), false,
 23+ strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
2524 'isDomElement: #random-name (null)' );
26 - deepEqual( $j.isDomElement( document.getElementsByTagName( 'div' ) ), false,
 25+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
2726 'isDomElement: getElementsByTagName Array' );
28 - deepEqual( $j.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
 27+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
2928 'isDomElement: getElementsByTagName(..)[0] Node' );
30 - deepEqual( $j.isDomElement( $j( 'div' ) ), false,
 29+ strictEqual( $.isDomElement( $( 'div' ) ), false,
3130 'isDomElement: jQuery object' );
32 - deepEqual( $j.isDomElement( $j( 'div' ).get(0) ), true,
 31+ strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
3332 'isDomElement: jQuery object > Get node' );
34 - deepEqual( $j.isDomElement( document.createElement( 'div' ) ), true,
 33+ strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
3534 'isDomElement: createElement' );
36 - deepEqual( $j.isDomElement( { foo: 1 } ), false,
 35+ strictEqual( $.isDomElement( { foo: 1 } ), false,
3736 'isDomElement: Object' );
3837
39 - equal( $j.isEmpty( 'string' ), false, 'isEmptry: "string"' );
40 - equal( $j.isEmpty( '0' ), true, 'isEmptry: "0"' );
41 - equal( $j.isEmpty( [] ), true, 'isEmptry: []' );
42 - equal( $j.isEmpty( {} ), true, 'isEmptry: {}' );
43 - // Documented behaviour
44 - equal( $j.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
 38+ strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
 39+ strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
 40+ strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
 41+ strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
4542
 43+ // Documented behaviour
 44+ strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
4645 });
4746
48 -test( 'Comparison functions', function(){
 47+test( 'Comparison functions', function() {
4948
50 - ok( $j.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
 49+ ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
5150 'compareArray: Two deep arrays that are excactly the same' );
52 - ok( !$j.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
 51+ ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
5352
54 - ok( $j.compareObject( {}, {} ), 'compareObject: Two empty objects' );
55 - ok( $j.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
56 - ok( !$j.compareObject( { bar: true }, { baz: false } ),
 53+ ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
 54+ ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
 55+ ok( !$.compareObject( { bar: true }, { baz: false } ),
5756 'compareObject: Two different objects (false)' );
58 -
59 -});
\ No newline at end of file
 57+});
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js
@@ -1,8 +1,8 @@
22 module( 'jquery.autoEllipsis.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
55 expect(1);
6 - ok( jQuery.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
 6+ ok( $.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
77 });
88
99 function createWrappedDiv( text ) {
@@ -31,11 +31,11 @@
3232
3333 // Verify that, and only one, span element was created
3434 var $span = $wrapper.find( '> span' );
35 - deepEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
 35+ strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
3636
3737 // Check that the text fits by turning on word wrapping
3838 $span.css( 'whiteSpace', 'nowrap' );
39 - deepEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
 39+ strictEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
4040
4141 // Add one character using scary black magic
4242 var spanText = $span.text();
@@ -44,7 +44,7 @@
4545
4646 // Put this text in the span and verify it doesn't fit
4747 $span.text( spanText );
48 - deepEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
 48+ strictEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
4949
5050 // Clean up
5151 $wrapper.remove();
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.client.js
@@ -1,28 +1,27 @@
22 module( 'jquery.client.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
55 expect(1);
66 ok( jQuery.client, 'jQuery.client defined' );
77 });
88
9 -test( 'profile', function(){
 9+test( 'profile', function() {
1010 expect(7);
1111 var p = $.client.profile();
12 - var unk = 'unknown';
13 - var unkOrType = function( val, type ) {
14 - return typeof val === type || val === unk;
 12+ var unknownOrType = function( val, type, summary ) {
 13+ return ok( typeof val === type || val === 'unknown', summary );
1514 };
1615
17 - equal( typeof p, 'object', 'profile() returns an object' );
18 - ok( unkOrType( p.layout, 'string' ), 'p.layout is a string (or "unknown")' );
19 - ok( unkOrType( p.layoutVersion, 'number' ), 'p.layoutVersion is a number (or "unknown")' );
20 - ok( unkOrType( p.platform, 'string' ), 'p.platform is a string (or "unknown")' );
21 - ok( unkOrType( p.version, 'string' ), 'p.version is a string (or "unknown")' );
22 - ok( unkOrType( p.versionBase, 'string' ), 'p.versionBase is a string (or "unknown")' );
 16+ equal( typeof p, 'object', 'profile returns an object' );
 17+ unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
 18+ unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
 19+ unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
 20+ unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
 21+ unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
2322 equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
2423 });
2524
26 -test( 'test', function(){
 25+test( 'test', function() {
2726 expect(1);
2827
2928 // Example from WikiEditor
@@ -54,6 +53,6 @@
5554 // then do a basic return value type check
5655 var testMatch = $.client.test( testMap );
5756
58 - equal( typeof testMatch, 'boolean', 'test() returns a boolean value' );
 57+ equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
5958
6059 });
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js
@@ -1,53 +1,50 @@
22 module( 'jquery.tabIndex.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
55 expect(2);
66
77 ok( $.fn.firstTabIndex, '$.fn.firstTabIndex defined' );
88 ok( $.fn.lastTabIndex, '$.fn.lastTabIndex defined' );
9 -
109 });
1110
12 -test( 'firstTabIndex', function(){
 11+test( 'firstTabIndex', function() {
1312 expect(2);
1413
15 - var testEnvironment =
 14+ var testEnvironment =
1615 '<form>' +
1716 '<input tabindex="7" />' +
1817 '<input tabindex="9" />' +
1918 '<textarea tabindex="2">Foobar</textarea>' +
2019 '<textarea tabindex="5">Foobar</textarea>' +
2120 '</form>';
22 - var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
2321
24 - deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
 22+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
 23+ strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
2524
26 - var $testB = $( '<div />' );
 25+ var $testB = $( '<div>' );
 26+ strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
2727
28 - deepEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
29 -
3028 // Clean up
31 - $testA.add( $testB).remove();
 29+ $testA.add( $testB ).remove();
3230 });
3331
34 -test( 'lastTabIndex', function(){
 32+test( 'lastTabIndex', function() {
3533 expect(2);
3634
37 - var testEnvironment =
 35+ var testEnvironment =
3836 '<form>' +
3937 '<input tabindex="7" />' +
4038 '<input tabindex="9" />' +
4139 '<textarea tabindex="2">Foobar</textarea>' +
4240 '<textarea tabindex="5">Foobar</textarea>' +
4341 '</form>';
44 - var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
4542
46 - deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
 43+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
 44+ strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
4745
48 - var $testB = $( '<div />' );
 46+ var $testB = $( '<div>' );
 47+ strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
4948
50 - deepEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
51 -
5249 // Clean up
53 - $testA.add( $testB).remove();
54 -});
\ No newline at end of file
 50+ $testA.add( $testB ).remove();
 51+});
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
@@ -1,39 +1,38 @@
22 module( 'mediawiki.util.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
 5+ expect(1);
56
67 ok( mw.util, 'mw.util defined' );
7 -
88 });
99
10 -test( 'rawurlencode', function(){
 10+test( 'rawurlencode', function() {
 11+ expect(1);
1112
1213 equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
13 -
1414 });
1515
16 -test( 'wikiUrlencode', function(){
 16+test( 'wikiUrlencode', function() {
 17+ expect(1);
1718
1819 equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
19 -
2020 });
2121
22 -test( 'wikiGetlink', function(){
 22+test( 'wikiGetlink', function() {
 23+ expect(2);
2324
2425 // Not part of startUp module
2526 mw.config.set( 'wgArticlePath', '/wiki/$1' );
2627
2728 var hrefA = mw.util.wikiGetlink( 'Sandbox' );
28 -
2929 equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
3030
3131 var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
32 -
33 - 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"' );
34 -
 32+ equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
 33+ 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
3534 });
3635
37 -test( 'wikiScript', function(){
 36+test( 'wikiScript', function() {
3837 expect(2);
3938
4039 mw.config.set({
@@ -43,26 +42,28 @@
4443 });
4544
4645 equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
47 - deepEqual( mw.util.wikiScript( 'api' ), '/w/api.php' );
 46+ equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
4847
4948 });
5049
51 -test( 'addCSS', function(){
 50+test( 'addCSS', function() {
5251 expect(3);
5352
5453 var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' );
55 - ok( a, 'function works' );
56 - deepEqual( a.disabled, false, 'property "disabled" is available and set to false' );
 54+ ok( a instanceof CSSStyleSheet, 'Object is an instance of CSSStyleSheet' );
 55+ strictEqual( a.disabled, false, 'property "disabled" is available and set to false' );
5756
5857 var $b = $('#bodyContent');
5958 equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect' );
6059
 60+ // Clean up
 61+ $( a.ownerNode ).remove();
6162 });
6263
63 -test( 'toggleToc', function(){
 64+test( 'toggleToc', function() {
6465 expect(3);
6566
66 - deepEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
 67+ strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
6768
6869 var tocHtml =
6970 '<table id="toc" class="toc"><tr><td>' +
@@ -71,7 +72,7 @@
7273 '<span class="toctoggle">&nbsp;[<a href="#" class="internal" id="togglelink">Hide</a>&nbsp;]</span>' +
7374 '</div>' +
7475 '<ul><li></li></ul>' +
75 - '</td></tr></table>';
 76+ '</td></tr></table>';
7677 var $toc = $(tocHtml).appendTo( 'body' );
7778 var $toggleLink = $( '#togglelink' );
7879
@@ -79,49 +80,48 @@
8081 // QUnit should not finish this test() untill they are all done
8182 stop();
8283
83 - var actionC = function(){
 84+ var actionC = function() {
8485 start();
8586
8687 // Clean up
8788 $toc.remove();
8889 };
89 - var actionB = function(){
90 - deepEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
 90+ var actionB = function() {
 91+ strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
9192 };
92 - var actionA = function(){
93 - deepEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
 93+ var actionA = function() {
 94+ strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
9495 };
95 -
 96+
9697 actionA();
97 -
98 -
9998 });
10099
101 -test( 'getParamValue', function(){
 100+test( 'getParamValue', function() {
 101+ expect(2);
102102
103103 var url = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
104104
105105 equal( mw.util.getParamValue( 'foo', url ), 'right', 'Use latest one, ignore hash' );
106 - deepEqual( mw.util.getParamValue( 'bar', url ), null, 'Return null when not found' );
107 -
 106+ strictEqual( mw.util.getParamValue( 'bar', url ), null, 'Return null when not found' );
108107 });
109108
110 -test( 'tooltipAccessKey', function(){
 109+test( 'tooltipAccessKey', function() {
 110+ expect(3);
111111
112112 equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
113113 ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
114114 ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' );
115 -
116115 });
117116
118 -test( '$content', function(){
 117+test( '$content', function() {
 118+ expect(2);
119119
120120 ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' );
121 - deepEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
122 -
 121+ strictEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
123122 });
124123
125 -test( 'addPortletLink', function(){
 124+test( 'addPortletLink', function() {
 125+ expect(5);
126126
127127 var A = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/wiki/ResourceLoader',
128128 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l', '#t-specialpages' );
@@ -142,55 +142,124 @@
143143
144144 // Clean up
145145 $( [A, B, C] ).remove();
146 -
147146 });
148147
149 -test( 'jsMessage', function(){
 148+test( 'jsMessage', function() {
 149+ expect(1);
150150
151151 var a = mw.util.jsMessage( "MediaWiki is <b>Awesome</b>." );
152 -
153152 ok( a, 'Basic checking of return value' );
154153
155154 // Clean up
156155 $( '#mw-js-message' ).remove();
157 -
158156 });
159157
160 -test( 'validateEmail', function(){
 158+test( 'validateEmail', function() {
161159 expect(6);
162160
163 - deepEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
164 - deepEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
 161+ strictEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
 162+ strictEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
165163
166164 // testEmailWithCommasAreInvalids
167 - deepEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
168 - deepEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
 165+ strictEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
 166+ strictEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
169167
170168 // testEmailWithHyphens
171 - deepEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
172 - deepEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
173 -
 169+ strictEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
 170+ strictEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
174171 });
175172
176 -test( 'isIPv6Address', function(){
177 - expect(6);
 173+test( 'isIPv6Address', function() {
 174+ expect(40);
178175
179 - // Based on IPTest.php > IPv6
180 - deepEqual( mw.util.isIPv6Address( "" ), false, 'Empty string is not an IP' );
181 - deepEqual( mw.util.isIPv6Address( ":fc:100::" ), false, 'IPv6 starting with lone ":"' );
182 - deepEqual( mw.util.isIPv6Address( "fc:100::" ), true );
183 - deepEqual( mw.util.isIPv6Address( "fc:100:a:d:1:e:ac::" ), true );
184 - deepEqual( mw.util.isIPv6Address( ":::" ), false );
185 - deepEqual( mw.util.isIPv6Address( "::0:" ), false );
 176+ // Shortcuts
 177+ var assertFalseIPv6 = function( addy, summary ) {
 178+ return strictEqual( mw.util.isIPv6Address( addy ), false, summary );
 179+ },
 180+ assertTrueIPv6 = function( addy, summary ) {
 181+ return strictEqual( mw.util.isIPv6Address( addy ), true, summary );
 182+ };
186183
 184+ // Based on IPTest.php > testisIPv6
 185+ assertFalseIPv6( ':fc:100::', 'IPv6 starting with lone ":"' );
 186+ assertFalseIPv6( 'fc:100:::', 'IPv6 ending with a ":::"' );
 187+ assertFalseIPv6( 'fc:300', 'IPv6 with only 2 words' );
 188+ assertFalseIPv6( 'fc:100:300', 'IPv6 with only 3 words' );
 189+
 190+ $.each(
 191+ ['fc:100::',
 192+ 'fc:100:a::',
 193+ 'fc:100:a:d::',
 194+ 'fc:100:a:d:1::',
 195+ 'fc:100:a:d:1:e::',
 196+ 'fc:100:a:d:1:e:ac::'], function( i, addy ){
 197+ assertTrueIPv6( addy, addy + ' is a valid IP' );
 198+ });
 199+
 200+ assertFalseIPv6( 'fc:100:a:d:1:e:ac:0::', 'IPv6 with 8 words ending with "::"' );
 201+ assertFalseIPv6( 'fc:100:a:d:1:e:ac:0:1::', 'IPv6 with 9 words ending with "::"' );
 202+
 203+ assertFalseIPv6( ':::' );
 204+ assertFalseIPv6( '::0:', 'IPv6 ending in a lone ":"' );
 205+
 206+ assertTrueIPv6( '::', 'IPv6 zero address' );
 207+ $.each(
 208+ ['::0',
 209+ '::fc',
 210+ '::fc:100',
 211+ '::fc:100:a',
 212+ '::fc:100:a:d',
 213+ '::fc:100:a:d:1',
 214+ '::fc:100:a:d:1:e',
 215+ '::fc:100:a:d:1:e:ac',
 216+
 217+ 'fc:100:a:d:1:e:ac:0'], function( i, addy ){
 218+ assertTrueIPv6( addy, addy + ' is a valid IP' );
 219+ });
 220+
 221+ assertFalseIPv6( '::fc:100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
 222+ assertFalseIPv6( '::fc:100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
 223+
 224+ assertFalseIPv6( ':fc::100', 'IPv6 starting with lone ":"' );
 225+ assertFalseIPv6( 'fc::100:', 'IPv6 ending with lone ":"' );
 226+ assertFalseIPv6( 'fc:::100', 'IPv6 with ":::" in the middle' );
 227+
 228+ assertTrueIPv6( 'fc::100', 'IPv6 with "::" and 2 words' );
 229+ assertTrueIPv6( 'fc::100:a', 'IPv6 with "::" and 3 words' );
 230+ assertTrueIPv6( 'fc::100:a:d', 'IPv6 with "::" and 4 words' );
 231+ assertTrueIPv6( 'fc::100:a:d:1', 'IPv6 with "::" and 5 words' );
 232+ assertTrueIPv6( 'fc::100:a:d:1:e', 'IPv6 with "::" and 6 words' );
 233+ assertTrueIPv6( 'fc::100:a:d:1:e:ac', 'IPv6 with "::" and 7 words' );
 234+ assertTrueIPv6( '2001::df', 'IPv6 with "::" and 2 words' );
 235+ assertTrueIPv6( '2001:5c0:1400:a::df', 'IPv6 with "::" and 5 words' );
 236+ assertTrueIPv6( '2001:5c0:1400:a::df:2', 'IPv6 with "::" and 6 words' );
 237+
 238+ assertFalseIPv6( 'fc::100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
 239+ assertFalseIPv6( 'fc::100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
187240 });
188241
189 -test( 'isIPv4Address', function(){
190 - expect(3);
 242+test( 'isIPv4Address', function() {
 243+ expect(11);
191244
192 - // Based on IPTest.php > IPv4
193 - deepEqual( mw.util.isIPv4Address( "" ), false, 'Empty string is not an IP' );
194 - deepEqual( mw.util.isIPv4Address( "...." ), false );
195 - deepEqual( mw.util.isIPv4Address( "1.24.52.13" ), true );
 245+ // Shortcuts
 246+ var assertFalseIPv4 = function( addy, summary ) {
 247+ return strictEqual( mw.util.isIPv4Address( addy ), false, summary );
 248+ },
 249+ assertTrueIPv4 = function( addy, summary ) {
 250+ return strictEqual( mw.util.isIPv4Address( addy ), true, summary );
 251+ };
196252
 253+ // Based on IPTest.php > testisIPv4
 254+ assertFalseIPv4( false, 'Boolean false is not an IP' );
 255+ assertFalseIPv4( true, 'Boolean true is not an IP' );
 256+ assertFalseIPv4( '', 'Empty string is not an IP' );
 257+ assertFalseIPv4( 'abc', '"abc" is not an IP' );
 258+ assertFalseIPv4( ':', 'Colon is not an IP' );
 259+ assertFalseIPv4( '124.24.52', 'IPv4 not enough quads' );
 260+ assertFalseIPv4( '24.324.52.13', 'IPv4 out of range' );
 261+ assertFalseIPv4( '.24.52.13', 'IPv4 starts with period' );
 262+
 263+ assertTrueIPv4( '124.24.52.13', '124.24.52.134 is a valid IP' );
 264+ assertTrueIPv4( '1.24.52.13', '1.24.52.13 is a valid IP' );
 265+ assertFalseIPv4( '74.24.52.13/20', 'IPv4 ranges are not recogzized as valid IPs' );
197266 });
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.user.js
@@ -1,30 +1,29 @@
22 module( 'mediawiki.user.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
 5+ expect(1);
56
67 ok( mw.user, 'mw.user defined' );
7 -
88 });
99
1010
11 -test( 'options', function(){
 11+test( 'options', function() {
 12+ expect(1);
1213
1314 ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
14 -
1515 });
1616
17 -test( 'User login status', function(){
 17+test( 'User login status', function() {
 18+ expect(5);
1819
19 - deepEqual( mw.user.name(), null, 'user.name() When anonymous' );
20 - ok( mw.user.anonymous(), 'user.anonymous() When anonymous' );
 20+ strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' );
 21+ ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' );
2122
2223 // Not part of startUp module
2324 mw.config.set( 'wgUserName', 'John' );
2425
25 - equal( mw.user.name(), 'John', 'user.name() When logged-in as John' );
26 - ok( !mw.user.anonymous(), 'user.anonymous() When logged-in' );
 26+ equal( mw.user.name(), 'John', 'user.name returns username when logged-in' );
 27+ ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' );
2728
28 - equal( mw.user.id(), 'John', 'user.id() When logged-in as John' );
29 -
30 -
31 -});
\ No newline at end of file
 29+ equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
 30+});
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js
@@ -1,86 +1,80 @@
22 module( 'mediawiki.js' );
33
4 -test( '-- Initial check', function(){
 4+test( '-- Initial check', function() {
 5+ expect(8);
56
67 ok( window.jQuery, 'jQuery defined' );
 8+ ok( window.$, '$j defined' );
79 ok( window.$j, '$j defined' );
8 - equal( window.$j, window.jQuery, '$j alias to jQuery' );
 10+ strictEqual( window.$, window.jQuery, '$ alias to jQuery' );
 11+ strictEqual( window.$j, window.jQuery, '$j alias to jQuery' );
912
1013 ok( window.mediaWiki, 'mediaWiki defined' );
1114 ok( window.mw, 'mw defined' );
12 - equal( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
13 -
 15+ strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
1416 });
1517
16 -test( 'mw.Map', function(){
17 - expect(20);
 18+test( 'mw.Map', function() {
 19+ expect(15);
1820
1921 ok( mw.Map, 'mw.Map defined' );
20 - ok( mw.Map.prototype.get, 'get prototype defined' );
21 - ok( mw.Map.prototype.set, 'set prototype defined' );
22 - ok( mw.Map.prototype.exists, 'exists prototype defined' );
2322
24 - var conf = new mw.Map();
 23+ var conf = new mw.Map(),
 24+ funky = function() {},
 25+ arry = [],
 26+ nummy = 7;
2527
26 - var funky = function(){};
27 - var arry = [];
28 - var nummy = 7;
 28+ strictEqual( conf.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' );
 29+ strictEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' );
 30+ strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
 31+ strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
 32+ strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
 33+ equal( conf.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' );
2934
30 - deepEqual( conf.get( 'inexistantKey' ), null, 'Map.get() returns null if selection was a string and the key was not found' );
31 - deepEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set() returns boolean true if a value was set for a valid key string' );
32 - deepEqual( conf.set( funky, 'Funky' ), false, 'Map.set() returns boolean false if key was invalid (Function)' );
33 - deepEqual( conf.set( arry, 'Arry' ), false, 'Map.set() returns boolean false if key was invalid (Array)' );
34 - deepEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set() returns boolean false if key was invalid (Number)' );
35 - equal( conf.get( 'myKey' ), 'myValue', 'Map.get() returns a single value value correctly' );
36 -
3735 var someValues = {
3836 'foo': 'bar',
3937 'lorem': 'ipsum',
4038 'MediaWiki': true
4139 };
42 - deepEqual( conf.set( someValues ), true, 'Map.set() returns boolean true if multiple values were set by passing an object' );
 40+ strictEqual( conf.set( someValues ), true, 'Map.set returns boolean true if multiple values were set by passing an object' );
4341 deepEqual( conf.get( ['foo', 'lorem'] ), {
4442 'foo': 'bar',
4543 'lorem': 'ipsum'
46 - }, 'Map.get() returns multiple values correctly as an object' );
 44+ }, 'Map.get returns multiple values correctly as an object' );
4745
4846 deepEqual( conf.get( ['foo', 'notExist'] ), {
4947 'foo': 'bar',
5048 'notExist': null
51 - }, 'Map.get() return includes keys that were not found as null values' );
 49+ }, 'Map.get return includes keys that were not found as null values' );
5250
53 - deepEqual( conf.exists( 'foo' ), true, 'Map.exists() returns boolean true if a key exists' );
54 - deepEqual( conf.exists( 'notExist' ), false, 'Map.exists() returns boolean false if a key does not exists' );
55 - deepEqual( conf.get() === conf.values, true, 'Map.get() returns the entire values object by reference (if called without arguments)' );
 51+ strictEqual( conf.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' );
 52+ strictEqual( conf.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' );
 53+ strictEqual( conf.get() === conf.values, true, 'Map.get returns the entire values object by reference (if called without arguments)' );
5654
5755 conf.set( 'globalMapChecker', 'Hi' );
5856
59 - deepEqual( 'globalMapChecker' in window, false, 'new mw.Map() did not store its values in the global window object by default' );
60 - ok( !window.globalMapChecker, 'new mw.Map() did not store its values in the global window object by default' );
 57+ ok( false === 'globalMapChecker' in window, 'new mw.Map did not store its values in the global window object by default' );
6158
6259 var globalConf = new mw.Map( true );
6360 globalConf.set( 'anotherGlobalMapChecker', 'Hello' );
6461
65 - deepEqual( 'anotherGlobalMapChecker' in window, true, 'new mw.Map( true ) did store its values in the global window object' );
66 - ok( window.anotherGlobalMapChecker, 'new mw.Map( true ) did store its values in the global window object' );
 62+ ok( 'anotherGlobalMapChecker' in window, 'new mw.Map( true ) did store its values in the global window object' );
6763
68 - // Whitelist this global variable for QUnit 'noglobal' mode
 64+ // Whitelist this global variable for QUnit's 'noglobal' mode
6965 if ( QUnit.config.noglobals ) {
7066 QUnit.config.pollution.push( 'anotherGlobalMapChecker' );
7167 }
7268 });
7369
74 -test( 'mw.config', function(){
 70+test( 'mw.config', function() {
7571 expect(1);
7672
77 - deepEqual( mw.config instanceof mw.Map, true, 'mw.config instance of mw.Map' );
 73+ ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
7874 });
7975
80 -test( 'mw.messages / mw.message / mw.msg', function(){
81 - expect(18);
 76+test( 'mw.message & mw.messages', function() {
 77+ expect(16);
8278
83 - ok( mw.message, 'mw.message defined' );
84 - ok( mw.msg, 'mw.msg defined' );
8579 ok( mw.messages, 'messages defined' );
8680 ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
8781 ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
@@ -88,7 +82,7 @@
8983 var hello = mw.message( 'hello' );
9084
9185 equal( hello.format, 'parse', 'Message property "format" defaults to "parse"' );
92 - deepEqual( hello.map === mw.messages, true, 'Message property "map" defaults to the global instance in mw.messages' );
 86+ strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' );
9387 equal( hello.key, 'hello', 'Message property "key" (currect key)' );
9488 deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' );
9589
@@ -96,34 +90,34 @@
9791 ok( hello.params, 'Message prototype "params"' );
9892
9993 hello.format = 'plain';
100 - equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString() returns the message as a string with the current "format"' );
 94+ equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' );
10195
102 - equal( hello.escaped(), 'Hello &lt;b&gt;awesome&lt;/b&gt; world', 'Message.escaped() returns the escaped message' );
103 - equal( hello.format, 'escaped', 'Message.escaped() correctly updated the "format" property' );
 96+ equal( hello.escaped(), 'Hello &lt;b&gt;awesome&lt;/b&gt; world', 'Message.escaped returns the escaped message' );
 97+ equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' );
10498
10599 hello.parse();
106 - equal( hello.format, 'parse', 'Message.parse() correctly updated the "format" property' );
 100+ equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' );
107101
108102 hello.plain();
109 - equal( hello.format, 'plain', 'Message.plain() correctly updated the "format" property' );
 103+ equal( hello.format, 'plain', 'Message.plain correctly updated the "format" property' );
110104
111 - deepEqual( hello.exists(), true, 'Message.exists() returns true for existing messages' );
 105+ strictEqual( hello.exists(), true, 'Message.exists returns true for existing messages' );
112106
113107 var goodbye = mw.message( 'goodbye' );
114 - deepEqual( goodbye.exists(), false, 'Message.exists() returns false for inexisting messages' );
 108+ strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' );
115109
116 - equal( goodbye.toString(), '<goodbye>', 'Message.toString() returns <key> if key does not exist' );
 110+ equal( goodbye.toString(), '<goodbye>', 'Message.toString returns <key> if key does not exist' );
117111
118112 });
119113
120 -test( 'mw.msg', function(){
 114+test( 'mw.msg', function() {
121115 expect(2);
122116
123117 equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
124118 equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' );
125119 });
126120
127 -test( 'mw.loader', function(){
 121+test( 'mw.loader', function() {
128122 expect(5);
129123
130124 // Regular expression to extract the path for the QUnit tests
@@ -154,62 +148,74 @@
155149 );
156150
157151 // Asynchronous ahead
158 - stop();
 152+ stop(1500);
159153
160154 // Extract path
161155 var tests_path = rePath.exec( location.href );
162156
163157 mw.loader.implement( 'is.awesome', [tests_path + 'sample/awesome.js'], {}, {} );
164158
165 - mw.loader.using( 'is.awesome', function(){
 159+ mw.loader.using( 'is.awesome', function() {
166160
167 - // awesome.js declares this function
 161+ // /sample/awesome.js declares the "mw.loader.testCallback" function
 162+ // which contains a call to start() and ok()
168163 mw.loader.testCallback();
169164
170 - }, function(){
 165+ }, function() {
171166 start();
172 - deepEqual( true, false, 'Implementing a module, error callback fired!' );
 167+ ok( false, 'Error callback fired while implementing "is.awesome" module' );
173168 });
174169
175170 });
176171
177172 test( 'mw.loader.bug29107' , function() {
178 - expect( 1 );
 173+ expect(2);
179174
180 - // Async! Include a timeout, as failure on this bug lead to neither the
 175+ // Message doesn't exist already
 176+ ok( !mw.messages.exists( 'bug29107' ) );
 177+
 178+ // Async! Include a timeout, as failure in this test leads to neither the
181179 // success nor failure callbacks getting called.
182180 stop(1500);
183181
184182 mw.loader.implement( 'bug29107.messages-only', [], {}, {'bug29107': 'loaded'} );
185183 mw.loader.using( 'bug29107.messages-only', function() {
186184 start();
187 - ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should load ok' );
188 - }, function(){
 185+ ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should implement ok' );
 186+ }, function() {
189187 start();
190 - deepEqual( true, false, 'Implementing a module, error callback fired!' );
 188+ ok( false, 'Error callback fired while implementing "bug29107.messages-only" module' );
191189 });
192190 });
193191
194 -test( 'mw.html', function(){
 192+test( 'mw.html', function() {
 193+ expect(7);
195194
 195+ raises( function(){
 196+ mw.html.escape();
 197+ }, TypeError, 'html.escape throws a TypeError if argument given is not a string' );
 198+
196199 equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
197 - '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'html.escape()' );
 200+ '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'html.escape escapes html snippet' );
198201
199 - equal( mw.html.element( 'div' ), '<div/>', 'mw.html.element() DIV (simple)' );
 202+ equal( mw.html.element(),
 203+ '<undefined/>', 'html.element Always return a valid html string (even without arguments)' );
200204
 205+ equal( mw.html.element( 'div' ), '<div/>', 'html.element DIV (simple)' );
 206+
201207 equal( mw.html.element( 'div',
202208 { id: 'foobar' } ),
203209 '<div id="foobar"/>',
204 - 'mw.html.element() DIV (attribs)' );
 210+ 'html.element DIV (attribs)' );
205211
206212 equal( mw.html.element( 'div',
207213 null, 'a' ),
208214 '<div>a</div>',
209 - 'mw.html.element() DIV (content)' );
 215+ 'html.element DIV (content)' );
210216
211217 equal( mw.html.element( 'a',
212218 { href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
213219 '<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
214 - 'mw.html.element() DIV (attribs + content)' );
 220+ 'html.element DIV (attribs + content)' );
215221
216222 });

Follow-up revisions

RevisionCommit summaryAuthorDate
r89848Follow-up: r89845: Forgot to commit changes in the other directorykrinkle20:08, 10 June 2011
r89853Added jquery.qunit.completenessTest.js (A jQuery/QUnit test coverage utility)...krinkle22:15, 10 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89082Adding or adjusting front-end function and variable documentation per our con...krinkle02:54, 29 May 2011

Comments

#Comment by Hashar (talk | contribs)   10:03, 11 August 2011

You should probably have broken this commit in smaller ones :-) DeepEquals is great

Status & tagging log