From 6c1faaaccf41907a5c5ea3b39f96c9ba981c6154 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 3 May 2011 21:57:33 +0000 Subject: [PATCH] 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 ($.isDomElement( document.getElementById('notexist') ); 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. --- .../mediawiki.util/mediawiki.util.test.js | 60 ++++++++++++++----- resources/mediawiki/mediawiki.js | 8 +-- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/resources/mediawiki.util/mediawiki.util.test.js b/resources/mediawiki.util/mediawiki.util.test.js index 7e2eed6b9a..be06a632fc 100644 --- a/resources/mediawiki.util/mediawiki.util.test.js +++ b/resources/mediawiki.util/mediawiki.util.test.js @@ -89,8 +89,7 @@ ); mw.util.addCSS( - '#mw-mwutiltest-table tr td { padding:0 !important; }' + // Override wikitable padding for - '.mw-mwutiltest-head:hover { cursor: pointer; } ' // Header-clicks hide/show the below rows + '#mw-mwutiltest-table tr td { padding:0 !important; }' // Override wikitable padding for ); mw.test.$table = $( 'table#mw-mwutiltest-table' ); @@ -150,6 +149,30 @@ mw.test.addTest( '$.escapeRE( "0123456789" )', '0123456789 (string)' ); + mw.test.addTest( '$.isDomElement( document.getElementById("mw-mwutiltest-table") )', + 'true (boolean)' ); + + mw.test.addTest( '$.isDomElement( document.getElementById("not-existant-id") )', + 'false (boolean)' ); // returns null + + mw.test.addTest( '$.isDomElement( document.getElementsByClassName("wikitable") )', + 'false (boolean)' ); // returns an array + + mw.test.addTest( '$.isDomElement( document.getElementsByClassName("wikitable")[0] )', + 'true (boolean)' ); + + mw.test.addTest( '$.isDomElement( jQuery( "#mw-mwutiltest-table" ) )', + 'false (boolean)' ); // returns jQuery object + + mw.test.addTest( '$.isDomElement( jQuery( "#mw-mwutiltest-table" ).get(0) )', + 'true (boolean)' ); + + mw.test.addTest( '$.isDomElement( document.createElement( "div" ) )', + 'true (boolean)' ); + + mw.test.addTest( '$.isDomElement( {some: "thing" } )', + 'false (boolean)' ); + mw.test.addTest( 'typeof $.isEmpty', 'function (string)' ); @@ -192,11 +215,11 @@ mw.test.addTest( 'mw.config.exists( ["wgSomeName", "wgTitle"] )', 'false (boolean)' ); - mw.test.addTest( 'mw.config.get( "wgTitle" )', - 'BlankPage (string)' ); + mw.test.addTest( 'mw.config.get( "wgCanonicalNamespace" )', + 'Special (string)' ); - mw.test.addTest( 'var a = mw.config.get( ["wgTitle"] ); a.wgTitle', - 'BlankPage (string)' ); + mw.test.addTest( 'var a = mw.config.get( ["wgCanonicalNamespace"] ); a.wgCanonicalNamespace', + 'Special (string)' ); mw.test.addTest( 'typeof mw.html', 'object (string)' ); @@ -246,10 +269,13 @@ mw.test.addTest( 'typeof mw.util.addCSS', 'function (string)' ); - mw.test.addTest( 'var a = mw.util.addCSS( ".plainlinks { color:green; }" ); a.disabled;', + mw.test.addTest( 'var a = mw.util.addCSS( "#mw-js-message { background-color: #AFA !important; }" ); a.disabled;', 'false (boolean)', '(boolean)' ); + mw.test.addTest( 'typeof mw.util.toggleToc', + 'function (string)' ); + mw.test.addTest( 'typeof mw.util.wikiGetlink', 'function (string)' ); @@ -262,6 +288,9 @@ mw.test.addTest( 'mw.util.getParamValue( "foo", "http://mw.org/?foo=wrong&foo=right#&foo=bad" )', 'right (string)' ); + mw.test.addTest( 'typeof mw.util.tooltipAccessKeyPrefix', + 'string (string)' ); + mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name', 'RegExp (string)' ); @@ -274,6 +303,9 @@ mw.test.addTest( 'mw.util.$content.size()', '1 (number)' ); + mw.test.addTest( 'mw.util.isMainPage()', + 'false (boolean)' ); + mw.test.addTest( 'typeof mw.util.addPortletLink', 'function (string)' ); @@ -408,7 +440,11 @@ numberOfTests++; headNumberOfTests++; - var doesReturn = eval( exec ); + try { + var doesReturn = eval( exec ); + } catch (e){ + mw.log ('mw.util.test> ' + e ); + } doesReturn = doesReturn + ' (' + typeof doesReturn + ')'; var $thisrow = $testrows.eq( i - numberOfHeaders ); // since headers are rows as well $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesReturn ).replace(/ /g, '  ' ) ); @@ -424,7 +460,7 @@ headNumberOfPartials++; } } else { - $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' ); + $thisrow.css( 'background', '#FAA' ).find( '> td' ).eq(3).text( 'ERROR' ); numberOfErrors++; headNumberOfErrors++; } @@ -434,12 +470,6 @@ numberOfPasseds + ' passed test(s). ' + numberOfErrors + ' error(s). ' + numberOfPartials + ' partially passed test(s).

' ); - // hide all tests. TODO hide only OK? - mw.test.$table.find( '.mw-mwutiltest-test' ).hide(); - // clickable header to show/hide the tests - mw.test.$table.find( '.mw-mwutiltest-head' ).click(function() { - $(this).nextUntil( '.mw-mwutiltest-head' ).toggle(); - }); } } ); } diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 18cf906ae1..1d8ea23e4f 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -16,14 +16,8 @@ jQuery.extend({ escapeRE : function( str ) { return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" ); }, - // $.isDomElement( document.getElementById('content') ) === true - // $.isDomElement( document.getElementsByClassName('portal') ) === false (array) - // $.isDomElement( document.getElementsByClassName('portal')[0] ) === true - // $.isDomElement( $('#content') ) === false (jQuery object) - // $.isDomElement( $('#content').get(0) ) === true - // $.isDomElement( 'hello world' ) === false isDomElement : function( el ) { - return !!el.nodeType; + return !!el && !!el.nodeType; }, isEmpty : function( v ) { var key; -- 2.20.1