mw.util.test fixes
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 3 May 2011 21:57:33 +0000 (21:57 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 3 May 2011 21:57:33 +0000 (21:57 +0000)
* 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.

resources/mediawiki.util/mediawiki.util.test.js
resources/mediawiki/mediawiki.js

index 7e2eed6..be06a63 100644 (file)
@@ -89,8 +89,7 @@
                                                );
 
                                                mw.util.addCSS(
-                                                       '#mw-mwutiltest-table tr td { padding:0 !important; }' +        // Override wikitable padding for <td>
-                                                       '.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 <td>
                                                );
 
                                                mw.test.$table = $( 'table#mw-mwutiltest-table' );
                                                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)' );
 
                                                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)' );
                                                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)' );
 
                                                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)' );
 
                                                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)' );
 
 
                                                        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, '&nbsp;&nbsp;' ) );
                                                                        headNumberOfPartials++;
                                                                }
                                                        } else {
-                                                               $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' );
+                                                               $thisrow.css( 'background', '#FAA' ).find( '> td' ).eq(3).text( 'ERROR' );
                                                                numberOfErrors++;
                                                                headNumberOfErrors++;
                                                        }
                                                        numberOfPasseds + ' passed test(s). ' + numberOfErrors + ' error(s). ' +
                                                        numberOfPartials + ' partially passed test(s). </p>' );
 
-                                               // 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();
-                                               });
                                        }
                                } );
                        }
index 18cf906..1d8ea23 100644 (file)
@@ -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;