r80786 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80785‎ | r80786 | r80787 >
Date:01:42, 23 January 2011
Author:krinkle
Status:ok
Tags:
Comment:
Updating mw.util.test.js + fixing minor bugs that were discovered through it
Updating mw.util.test.js
* Adding tests for modules now loaded by default [[RL/DM]]. Still not all of them, but it's getting there
* Changing order to either alphabetical order or order from source code (instead of random or chronological)
* adding addHead() function
* Fixing a bug caused by addHead() with (which selected all rows instead of rows that contain actual tests) - also removed the need for the "+1" adjustment later on in the code (which was needed since contained the first row with the column headings)
Fixed bugs that were found through testing:
* No title attribute was set for skins without portlets. (it was after the portlet-presence check).
Now older skins get the title attribute as well.
* Modern's article-container ('#mw_contentholder') is added to the definition for mw.util. in mw.util.init()
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -29,11 +29,25 @@
3030 contain = result;
3131 }
3232 this.addedTests.push( [code, result, contain] );
33 - this.$table.append( '<tr><td>' + mw.html.escape( code ).replace(/ /g, '&nbsp;&nbsp;' )
34 - + '</td><td>' + mw.html.escape( result ).replace(/ /g, '&nbsp;&nbsp;' )
 33+ this.$table.append( '<tr><td>' + mw.html.escape( code ).replace( / /g, '&nbsp;&nbsp;' )
 34+ + '</td><td>' + mw.html.escape( result ).replace( / /g, '&nbsp;&nbsp;' )
3535 + '</td><td></td><td>?</td></tr>' );
 36+ return true;
3637 },
3738
 39+ /**
 40+ * Adds a heading to the test-table
 41+ *
 42+ * @param title String Title of the section
 43+ */
 44+ 'addHead' : function( title ) {
 45+ if ( !title ) {
 46+ return false;
 47+ }
 48+ this.$table.append( '<tr><th colspan="4">' + mw.html.escape( title ).replace( / /g, '&nbsp;&nbsp;' ) + '</th></tr>' );
 49+ return true;
 50+ },
 51+
3852 /* Initialisation */
3953 'initialised' : false,
4054 'init' : function() {
@@ -56,76 +70,204 @@
5771 );
5872 mw.test.$table = $( 'table#mw-mwutiltest-table' );
5973
60 - // Populate tests
 74+ /* Populate tests */
 75+
 76+ // Main modules and their aliases
 77+ mw.test.addHead( 'Main modules and their aliases' );
 78+
 79+ mw.test.addTest( 'typeof mediaWiki',
 80+ 'object (string)' );
 81+
 82+ mw.test.addTest( 'typeof mw',
 83+ 'object (string)' );
 84+
 85+ mw.test.addTest( 'typeof jQuery',
 86+ 'function (string)' );
 87+
 88+ mw.test.addTest( 'typeof $',
 89+ 'function (string)' );
 90+
 91+ // Prototype functions added by MediaWiki
 92+ mw.test.addHead( 'Prototype functions added by MediaWiki' );
 93+
6194 mw.test.addTest( 'typeof $.trimLeft',
6295 'function (string)' );
63 - mw.test.addTest( '$.trimLeft(\' foo bar \')',
 96+
 97+ mw.test.addTest( '$.trimLeft( " foo bar " )',
6498 'foo bar (string)' );
 99+
65100 mw.test.addTest( 'typeof $.trimRight',
66101 'function (string)' );
67 - mw.test.addTest( '$.trimRight(\' foo bar \')',
 102+
 103+ mw.test.addTest( '$.trimRight( " foo bar " )',
68104 ' foo bar (string)' );
 105+
 106+ mw.test.addTest( 'typeof $.ucFirst',
 107+ 'function (string)' );
 108+
 109+ mw.test.addTest( '$.ucFirst( "mediawiki" )',
 110+ 'Mediawiki (string)' );
 111+
 112+ mw.test.addTest( 'typeof $.escapeRE',
 113+ 'function (string)' );
 114+
 115+ mw.test.addTest( '$.escapeRE( ".st{e}$st" )',
 116+ '\\.st\\{e\\}\\$st (string)' );
 117+
69118 mw.test.addTest( 'typeof $.isEmpty',
70119 'function (string)' );
71 - mw.test.addTest( '$.isEmpty(\'string\')',
 120+
 121+ mw.test.addTest( '$.isEmpty( "string" )',
72122 'false (boolean)' );
73 - mw.test.addTest( '$.isEmpty(\'0\')',
 123+
 124+ mw.test.addTest( '$.isEmpty( "0" )',
74125 'true (boolean)' );
 126+
75127 mw.test.addTest( '$.isEmpty([])',
76128 'true (boolean)' );
 129+
77130 mw.test.addTest( 'typeof $.compareArray',
78131 'function (string)' );
79 - mw.test.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
 132+
 133+ mw.test.addTest( '$.compareArray( [1, "a", [], [2, "b"] ], [1, "a", [], [2, "b"] ] )',
80134 'true (boolean)' );
 135+
81136 mw.test.addTest( '$.compareArray( [1], [2] )',
82137 'false (boolean)' );
83 - mw.test.addTest( '4',
84 - '4 (number)' );
85 - mw.test.addTest( 'typeof mediaWiki',
 138+
 139+ mw.test.addTest( 'typeof $.compareObject',
 140+ 'function (string)' );
 141+
 142+ // mediawiki.js
 143+ mw.test.addHead( 'mediawiki.js' );
 144+
 145+ mw.test.addTest( 'mw.config instanceof mw.Map',
 146+ 'true (boolean)' );
 147+
 148+ mw.test.addTest( 'mw.config.exists()',
 149+ 'true (boolean)' );
 150+
 151+ mw.test.addTest( 'mw.config.exists( "wgSomeName" )',
 152+ 'false (boolean)' );
 153+
 154+ mw.test.addTest( 'mw.config.exists( ["wgCanonicalNamespace", "wgTitle"] )',
 155+ 'true (boolean)' );
 156+
 157+ mw.test.addTest( 'mw.config.exists( ["wgSomeName", "wgTitle"] )',
 158+ 'false (boolean)' );
 159+
 160+ mw.test.addTest( 'mw.config.get( "wgTitle" )',
 161+ 'BlankPage (string)' );
 162+
 163+ mw.test.addTest( 'var a = mw.config.get( ["wgTitle"] ); a.wgTitle',
 164+ 'BlankPage (string)' );
 165+
 166+ mw.test.addTest( 'typeof mw.html',
86167 'object (string)' );
87 - mw.test.addTest( 'typeof mw',
 168+
 169+ mw.test.addTest( 'mw.html.escape( \'<mw awesome="awesome">\' )',
 170+ '&lt;mw awesome=&quot;awesome&quot;&gt; (string)' );
 171+
 172+ mw.test.addTest( 'mw.html.element( "hr" )',
 173+ '<hr/> (string)' );
 174+
 175+ mw.test.addTest( 'mw.html.element( "img", { "src": "http://mw.org/?title=Main page&action=edit" } )',
 176+ '<img src="http://mw.org/?title=Main page&amp;action=edit"/> (string)' );
 177+
 178+ mw.test.addTest( 'typeof mw.loader',
88179 'object (string)' );
 180+
 181+ mw.test.addTest( 'typeof mw.loader.using',
 182+ 'function (string)' );
 183+
 184+ mw.test.addTest( 'typeof mw.Map',
 185+ 'function (string)' );
 186+
 187+ mw.test.addTest( 'typeof mw.user',
 188+ 'object (string)' );
 189+
 190+ mw.test.addTest( 'typeof mw.user.anonymous()',
 191+ 'boolean (string)' );
 192+
 193+ // mediawiki.util.js
 194+ mw.test.addHead( 'mediawiki.util.js' );
 195+
89196 mw.test.addTest( 'typeof mw.util',
90197 'object (string)' );
91 - mw.test.addTest( 'typeof mw.html',
92 - 'object (string)' );
93 - mw.test.addTest( 'typeof $.ucFirst',
 198+
 199+ mw.test.addTest( 'typeof mw.util.rawurlencode',
94200 'function (string)' );
95 - mw.test.addTest( '$.ucFirst( \'mediawiki\' )',
96 - 'Mediawiki (string)' );
97 - mw.test.addTest( 'typeof $.escapeRE',
 201+
 202+ mw.test.addTest( 'mw.util.rawurlencode( "Test:A & B/Here" )',
 203+ 'Test%3AA%20%26%20B%2FHere (string)' );
 204+
 205+ mw.test.addTest( 'typeof mw.util.wikiUrlencode',
98206 'function (string)' );
99 - mw.test.addTest( '$.escapeRE( \'.st{e}$st\' )',
100 - '\\.st\\{e\\}\\$st (string)' );
101 - mw.test.addTest( 'typeof $.fn.checkboxShiftClick',
 207+
 208+ mw.test.addTest( 'mw.util.wikiUrlencode( "Test:A & B/Here" )',
 209+ 'Test:A_%26_B/Here (string)' );
 210+
 211+ mw.test.addTest( 'typeof mw.util.addCSS',
102212 'function (string)' );
103 - mw.test.addTest( 'typeof mw.util.rawurlencode',
104 - 'function (string)' );
105 - mw.test.addTest( 'mw.util.rawurlencode( \'Test: A&B/Here\' )',
106 - 'Test%3A%20A%26B%2FHere (string)' );
 213+
 214+ mw.test.addTest( 'var a = mw.util.addCSS( ".plainlinks { color:green; }" ); a.disabled;',
 215+ 'false (boolean)',
 216+ '(boolean)' );
 217+
107218 mw.test.addTest( 'typeof mw.util.wikiGetlink',
108219 'function (string)' );
 220+
109221 mw.test.addTest( 'typeof mw.util.getParamValue',
110222 'function (string)' );
111 - mw.test.addTest( 'mw.util.getParamValue( \'action\' )',
 223+
 224+ mw.test.addTest( 'mw.util.getParamValue( "action" )',
112225 'mwutiltest (string)' );
113 - mw.test.addTest( 'mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
 226+
 227+ mw.test.addTest( 'mw.util.getParamValue( "foo", "http://mw.org/?foo=wrong&foo=right#&foo=bad" )',
114228 'right (string)' );
 229+
115230 mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name',
116231 'RegExp (string)' );
 232+
117233 mw.test.addTest( 'typeof mw.util.updateTooltipAccessKeys',
118234 'function (string)' );
 235+
 236+ mw.test.addTest( 'mw.util.$content instanceof jQuery',
 237+ 'true (boolean)' );
 238+
 239+ mw.test.addTest( 'mw.util.$content.size()',
 240+ '1 (number)' );
 241+
119242 mw.test.addTest( 'typeof mw.util.addPortletLink',
120243 'function (string)' );
121 - mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
 244+
 245+ mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/wiki/ResourceLoader", "ResourceLoader", "t-rl", "More info about ResourceLoader on MediaWiki.org ", "l", "#t-specialpages" )',
122246 'object (string)' );
123 - mw.test.addTest( 'a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" ); $(a).text();',
 247+
 248+ mw.test.addTest( 'var a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-rl" ); $(a).text();',
124249 'MediaWiki.org (string)' );
125 - mw.test.addTest( 'mw.html.element( \'hr\' )',
126 - '<hr/> (string)' );
127 - mw.test.addTest( 'mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
128 - '<img src="http://mw.org/?title=Main page&amp;action=edit"/> (string)' );
129250
 251+ mw.test.addTest( 'typeof mw.util.jsMessage',
 252+ 'function (string)' );
 253+
 254+ mw.test.addTest( 'mw.util.jsMessage( mw.config.get( "wgSiteName" ) + " is <b>Awesome</b>." )',
 255+ 'true (boolean)' );
 256+
 257+ // jQuery plugins
 258+ mw.test.addHead( 'jQuery plugins' );
 259+
 260+ mw.test.addTest( 'typeof $.client',
 261+ 'object (string)' );
 262+
 263+ mw.test.addTest( 'typeof $.client.profile',
 264+ 'function (string)' );
 265+
 266+ mw.test.addTest( 'var a = $.client.profile(); typeof a.name',
 267+ 'string (string)' );
 268+
 269+ mw.test.addTest( 'typeof $.fn.makeCollapsible',
 270+ 'function (string)' );
 271+
130272 // Run tests and compare results
131273 var exec,
132274 result,
@@ -134,7 +276,7 @@
135277 numberofpasseds = 0,
136278 numberofpartials = 0,
137279 numberoferrors = 0,
138 - $testrows = mw.test.$table.find( 'tr' );
 280+ $testrows = mw.test.$table.find( 'tr:has(td)' );
139281
140282 $.each( mw.test.addedTests, function( i ) {
141283 numberoftests++;
@@ -144,11 +286,11 @@
145287 shouldcontain = mw.test.addedTests[i][2];
146288 doesreturn = eval( exec );
147289 doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
148 - $thisrow = $testrows.eq( i + 1 );
 290+ $thisrow = $testrows.eq( i );
149291 $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, '&nbsp;&nbsp;' ) );
150292
151293 if ( doesreturn.indexOf( shouldcontain ) !== -1 ) {
152 - if (doesreturn == shouldreturn){
 294+ if ( doesreturn == shouldreturn ) {
153295 $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' );
154296 numberofpasseds++;
155297 } else {
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -59,10 +59,22 @@
6060
6161 /* Fill $content var */
6262 if ( $( '#bodyContent' ).length ) {
 63+ // Vector, Monobook, Chick etc.
6364 mw.util.$content = $( '#bodyContent' );
 65+
 66+ } else if ( $( '#mw_contentholder' ).length ) {
 67+ // Modern
 68+ mw.util.$content = $( '#mw_contentholder' );
 69+
6470 } else if ( $( '#article' ).length ) {
 71+ // Standard, CologneBlue
6572 mw.util.$content = $( '#article' );
 73+
6674 } else {
 75+ // #content is present on almost all if not all skins. Most skins (the above cases)
 76+ // have #content too, but as a outer wrapper instead of the article text container.
 77+ // The skins that don't have an outer wrapper have #content for everything
 78+ // so it's a good fallback
6779 mw.util.$content = $( '#content' );
6880 }
6981
@@ -299,6 +311,9 @@
300312 }
301313 // Setup the anchor tag
302314 var $link = $( '<a />' ).attr( 'href', href ).text( text );
 315+ if ( tooltip ) {
 316+ $link.attr( 'title', tooltip );
 317+ }
303318
304319 // Some skins don't have any portlets
305320 // just add it to the bottom of their 'sidebar' element as a fallback
@@ -352,8 +367,6 @@
353368 if ( accesskey ) {
354369 $link.attr( 'accesskey', accesskey );
355370 tooltip += ' [' + accesskey + ']';
356 - }
357 - if ( tooltip ) {
358371 $link.attr( 'title', tooltip );
359372 }
360373 if ( accesskey && tooltip ) {

Status & tagging log