r87360 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87359‎ | r87360 | r87361 >
Date:21:57, 3 May 2011
Author:krinkle
Status:deferred (Comments)
Tags:
Comment:
mw.util.test fixes
* Remove hiding of rows after the test, in almost all cases someone will want to unhide these, especially in case of an error; Plus, there were some inconsistencies in firefox with the hovering of the last (non-collapsible) row.
* Changing mw.util.addCSS to a style that is actually visible on the action=mwutiltest page.
* Making the entire row red in case of errors (easier finding of the error)
* Moving $.isDomElement tests to mw.util.test instead of in comments
* Adding missing tests for all mw.util properties
* Fix bug where $.isDomElement fails if the passed argument isn't an object at all (eg. null or undefined). Check variable first before checking object property (<code>$.isDomElement( document.getElementById('notexist') );</code> returned TypeError: Result of expression 'el' [null] is not an object.)
** Adding test for this
* Try/Catch the evaluation
** Reports catched exceptions through mw.log instead of using throw. This way non-consoled browsers can be easily debugged through mw.log's console.
** Fixes: (bug 28803) mw.util.test doesn't handle exceptions
* Using a canonical variable instead of a localized one in the tests.
** Fixes: (bug 28788) 2 tests related to wgTitle in mediawiki.util.test are broken for non-English wikis.
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -89,8 +89,7 @@
9090 );
9191
9292 mw.util.addCSS(
93 - '#mw-mwutiltest-table tr td { padding:0 !important; }' + // Override wikitable padding for <td>
94 - '.mw-mwutiltest-head:hover { cursor: pointer; } ' // Header-clicks hide/show the below rows
 93+ '#mw-mwutiltest-table tr td { padding:0 !important; }' // Override wikitable padding for <td>
9594 );
9695
9796 mw.test.$table = $( 'table#mw-mwutiltest-table' );
@@ -150,6 +149,30 @@
151150 mw.test.addTest( '$.escapeRE( "0123456789" )',
152151 '0123456789 (string)' );
153152
 153+ mw.test.addTest( '$.isDomElement( document.getElementById("mw-mwutiltest-table") )',
 154+ 'true (boolean)' );
 155+
 156+ mw.test.addTest( '$.isDomElement( document.getElementById("not-existant-id") )',
 157+ 'false (boolean)' ); // returns null
 158+
 159+ mw.test.addTest( '$.isDomElement( document.getElementsByClassName("wikitable") )',
 160+ 'false (boolean)' ); // returns an array
 161+
 162+ mw.test.addTest( '$.isDomElement( document.getElementsByClassName("wikitable")[0] )',
 163+ 'true (boolean)' );
 164+
 165+ mw.test.addTest( '$.isDomElement( jQuery( "#mw-mwutiltest-table" ) )',
 166+ 'false (boolean)' ); // returns jQuery object
 167+
 168+ mw.test.addTest( '$.isDomElement( jQuery( "#mw-mwutiltest-table" ).get(0) )',
 169+ 'true (boolean)' );
 170+
 171+ mw.test.addTest( '$.isDomElement( document.createElement( "div" ) )',
 172+ 'true (boolean)' );
 173+
 174+ mw.test.addTest( '$.isDomElement( {some: "thing" } )',
 175+ 'false (boolean)' );
 176+
154177 mw.test.addTest( 'typeof $.isEmpty',
155178 'function (string)' );
156179
@@ -192,11 +215,11 @@
193216 mw.test.addTest( 'mw.config.exists( ["wgSomeName", "wgTitle"] )',
194217 'false (boolean)' );
195218
196 - mw.test.addTest( 'mw.config.get( "wgTitle" )',
197 - 'BlankPage (string)' );
 219+ mw.test.addTest( 'mw.config.get( "wgCanonicalNamespace" )',
 220+ 'Special (string)' );
198221
199 - mw.test.addTest( 'var a = mw.config.get( ["wgTitle"] ); a.wgTitle',
200 - 'BlankPage (string)' );
 222+ mw.test.addTest( 'var a = mw.config.get( ["wgCanonicalNamespace"] ); a.wgCanonicalNamespace',
 223+ 'Special (string)' );
201224
202225 mw.test.addTest( 'typeof mw.html',
203226 'object (string)' );
@@ -246,10 +269,13 @@
247270 mw.test.addTest( 'typeof mw.util.addCSS',
248271 'function (string)' );
249272
250 - mw.test.addTest( 'var a = mw.util.addCSS( ".plainlinks { color:green; }" ); a.disabled;',
 273+ mw.test.addTest( 'var a = mw.util.addCSS( "#mw-js-message { background-color: #AFA !important; }" ); a.disabled;',
251274 'false (boolean)',
252275 '(boolean)' );
253276
 277+ mw.test.addTest( 'typeof mw.util.toggleToc',
 278+ 'function (string)' );
 279+
254280 mw.test.addTest( 'typeof mw.util.wikiGetlink',
255281 'function (string)' );
256282
@@ -262,6 +288,9 @@
263289 mw.test.addTest( 'mw.util.getParamValue( "foo", "http://mw.org/?foo=wrong&foo=right#&foo=bad" )',
264290 'right (string)' );
265291
 292+ mw.test.addTest( 'typeof mw.util.tooltipAccessKeyPrefix',
 293+ 'string (string)' );
 294+
266295 mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name',
267296 'RegExp (string)' );
268297
@@ -274,6 +303,9 @@
275304 mw.test.addTest( 'mw.util.$content.size()',
276305 '1 (number)' );
277306
 307+ mw.test.addTest( 'mw.util.isMainPage()',
 308+ 'false (boolean)' );
 309+
278310 mw.test.addTest( 'typeof mw.util.addPortletLink',
279311 'function (string)' );
280312
@@ -408,7 +440,11 @@
409441
410442 numberOfTests++;
411443 headNumberOfTests++;
412 - var doesReturn = eval( exec );
 444+ try {
 445+ var doesReturn = eval( exec );
 446+ } catch (e){
 447+ mw.log ('mw.util.test> ' + e );
 448+ }
413449 doesReturn = doesReturn + ' (' + typeof doesReturn + ')';
414450 var $thisrow = $testrows.eq( i - numberOfHeaders ); // since headers are rows as well
415451 $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesReturn ).replace(/ /g, '&nbsp;&nbsp;' ) );
@@ -424,7 +460,7 @@
425461 headNumberOfPartials++;
426462 }
427463 } else {
428 - $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' );
 464+ $thisrow.css( 'background', '#FAA' ).find( '> td' ).eq(3).text( 'ERROR' );
429465 numberOfErrors++;
430466 headNumberOfErrors++;
431467 }
@@ -434,12 +470,6 @@
435471 numberOfPasseds + ' passed test(s). ' + numberOfErrors + ' error(s). ' +
436472 numberOfPartials + ' partially passed test(s). </p>' );
437473
438 - // hide all tests. TODO hide only OK?
439 - mw.test.$table.find( '.mw-mwutiltest-test' ).hide();
440 - // clickable header to show/hide the tests
441 - mw.test.$table.find( '.mw-mwutiltest-head' ).click(function() {
442 - $(this).nextUntil( '.mw-mwutiltest-head' ).toggle();
443 - });
444474 }
445475 } );
446476 }
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -16,14 +16,8 @@
1717 escapeRE : function( str ) {
1818 return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" );
1919 },
20 - // $.isDomElement( document.getElementById('content') ) === true
21 - // $.isDomElement( document.getElementsByClassName('portal') ) === false (array)
22 - // $.isDomElement( document.getElementsByClassName('portal')[0] ) === true
23 - // $.isDomElement( $('#content') ) === false (jQuery object)
24 - // $.isDomElement( $('#content').get(0) ) === true
25 - // $.isDomElement( 'hello world' ) === false
2620 isDomElement : function( el ) {
27 - return !!el.nodeType;
 21+ return !!el && !!el.nodeType;
2822 },
2923 isEmpty : function( v ) {
3024 var key;

Follow-up revisions

RevisionCommit summaryAuthorDate
r87684mw.util.test update...krinkle13:22, 8 May 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82028Adding a convenience function to check if a variable is a dom element (instea...krinkle20:40, 12 February 2011

Comments

#Comment by Krinkle (talk | contribs)   01:28, 3 June 2011

Note that mediawiki.util.test.js was deleted in favour of the new QUnit testing framework in /tests/qunit. Any changes to it are redundant now.

Status & tagging log