Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -29,11 +29,25 @@ |
30 | 30 | contain = result; |
31 | 31 | } |
32 | 32 | this.addedTests.push( [code, result, contain] ); |
33 | | - this.$table.append( '<tr><td>' + mw.html.escape( code ).replace(/ /g, ' ' ) |
34 | | - + '</td><td>' + mw.html.escape( result ).replace(/ /g, ' ' ) |
| 33 | + this.$table.append( '<tr><td>' + mw.html.escape( code ).replace( / /g, ' ' ) |
| 34 | + + '</td><td>' + mw.html.escape( result ).replace( / /g, ' ' ) |
35 | 35 | + '</td><td></td><td>?</td></tr>' ); |
| 36 | + return true; |
36 | 37 | }, |
37 | 38 | |
| 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, ' ' ) + '</th></tr>' ); |
| 49 | + return true; |
| 50 | + }, |
| 51 | + |
38 | 52 | /* Initialisation */ |
39 | 53 | 'initialised' : false, |
40 | 54 | 'init' : function() { |
— | — | @@ -56,76 +70,204 @@ |
57 | 71 | ); |
58 | 72 | mw.test.$table = $( 'table#mw-mwutiltest-table' ); |
59 | 73 | |
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 | + |
61 | 94 | mw.test.addTest( 'typeof $.trimLeft', |
62 | 95 | 'function (string)' ); |
63 | | - mw.test.addTest( '$.trimLeft(\' foo bar \')', |
| 96 | + |
| 97 | + mw.test.addTest( '$.trimLeft( " foo bar " )', |
64 | 98 | 'foo bar (string)' ); |
| 99 | + |
65 | 100 | mw.test.addTest( 'typeof $.trimRight', |
66 | 101 | 'function (string)' ); |
67 | | - mw.test.addTest( '$.trimRight(\' foo bar \')', |
| 102 | + |
| 103 | + mw.test.addTest( '$.trimRight( " foo bar " )', |
68 | 104 | ' 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 | + |
69 | 118 | mw.test.addTest( 'typeof $.isEmpty', |
70 | 119 | 'function (string)' ); |
71 | | - mw.test.addTest( '$.isEmpty(\'string\')', |
| 120 | + |
| 121 | + mw.test.addTest( '$.isEmpty( "string" )', |
72 | 122 | 'false (boolean)' ); |
73 | | - mw.test.addTest( '$.isEmpty(\'0\')', |
| 123 | + |
| 124 | + mw.test.addTest( '$.isEmpty( "0" )', |
74 | 125 | 'true (boolean)' ); |
| 126 | + |
75 | 127 | mw.test.addTest( '$.isEmpty([])', |
76 | 128 | 'true (boolean)' ); |
| 129 | + |
77 | 130 | mw.test.addTest( 'typeof $.compareArray', |
78 | 131 | '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"] ] )', |
80 | 134 | 'true (boolean)' ); |
| 135 | + |
81 | 136 | mw.test.addTest( '$.compareArray( [1], [2] )', |
82 | 137 | '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', |
86 | 167 | 'object (string)' ); |
87 | | - mw.test.addTest( 'typeof mw', |
| 168 | + |
| 169 | + mw.test.addTest( 'mw.html.escape( \'<mw awesome="awesome">\' )', |
| 170 | + '<mw awesome="awesome"> (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&action=edit"/> (string)' ); |
| 177 | + |
| 178 | + mw.test.addTest( 'typeof mw.loader', |
88 | 179 | '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 | + |
89 | 196 | mw.test.addTest( 'typeof mw.util', |
90 | 197 | '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', |
94 | 200 | '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', |
98 | 206 | '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', |
102 | 212 | '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 | + |
107 | 218 | mw.test.addTest( 'typeof mw.util.wikiGetlink', |
108 | 219 | 'function (string)' ); |
| 220 | + |
109 | 221 | mw.test.addTest( 'typeof mw.util.getParamValue', |
110 | 222 | 'function (string)' ); |
111 | | - mw.test.addTest( 'mw.util.getParamValue( \'action\' )', |
| 223 | + |
| 224 | + mw.test.addTest( 'mw.util.getParamValue( "action" )', |
112 | 225 | '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" )', |
114 | 228 | 'right (string)' ); |
| 229 | + |
115 | 230 | mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name', |
116 | 231 | 'RegExp (string)' ); |
| 232 | + |
117 | 233 | mw.test.addTest( 'typeof mw.util.updateTooltipAccessKeys', |
118 | 234 | '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 | + |
119 | 242 | mw.test.addTest( 'typeof mw.util.addPortletLink', |
120 | 243 | '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" )', |
122 | 246 | '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();', |
124 | 249 | '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&action=edit"/> (string)' ); |
129 | 250 | |
| 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 | + |
130 | 272 | // Run tests and compare results |
131 | 273 | var exec, |
132 | 274 | result, |
— | — | @@ -134,7 +276,7 @@ |
135 | 277 | numberofpasseds = 0, |
136 | 278 | numberofpartials = 0, |
137 | 279 | numberoferrors = 0, |
138 | | - $testrows = mw.test.$table.find( 'tr' ); |
| 280 | + $testrows = mw.test.$table.find( 'tr:has(td)' ); |
139 | 281 | |
140 | 282 | $.each( mw.test.addedTests, function( i ) { |
141 | 283 | numberoftests++; |
— | — | @@ -144,11 +286,11 @@ |
145 | 287 | shouldcontain = mw.test.addedTests[i][2]; |
146 | 288 | doesreturn = eval( exec ); |
147 | 289 | doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
148 | | - $thisrow = $testrows.eq( i + 1 ); |
| 290 | + $thisrow = $testrows.eq( i ); |
149 | 291 | $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, ' ' ) ); |
150 | 292 | |
151 | 293 | if ( doesreturn.indexOf( shouldcontain ) !== -1 ) { |
152 | | - if (doesreturn == shouldreturn){ |
| 294 | + if ( doesreturn == shouldreturn ) { |
153 | 295 | $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' ); |
154 | 296 | numberofpasseds++; |
155 | 297 | } else { |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -59,10 +59,22 @@ |
60 | 60 | |
61 | 61 | /* Fill $content var */ |
62 | 62 | if ( $( '#bodyContent' ).length ) { |
| 63 | + // Vector, Monobook, Chick etc. |
63 | 64 | mw.util.$content = $( '#bodyContent' ); |
| 65 | + |
| 66 | + } else if ( $( '#mw_contentholder' ).length ) { |
| 67 | + // Modern |
| 68 | + mw.util.$content = $( '#mw_contentholder' ); |
| 69 | + |
64 | 70 | } else if ( $( '#article' ).length ) { |
| 71 | + // Standard, CologneBlue |
65 | 72 | mw.util.$content = $( '#article' ); |
| 73 | + |
66 | 74 | } 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 |
67 | 79 | mw.util.$content = $( '#content' ); |
68 | 80 | } |
69 | 81 | |
— | — | @@ -299,6 +311,9 @@ |
300 | 312 | } |
301 | 313 | // Setup the anchor tag |
302 | 314 | var $link = $( '<a />' ).attr( 'href', href ).text( text ); |
| 315 | + if ( tooltip ) { |
| 316 | + $link.attr( 'title', tooltip ); |
| 317 | + } |
303 | 318 | |
304 | 319 | // Some skins don't have any portlets |
305 | 320 | // just add it to the bottom of their 'sidebar' element as a fallback |
— | — | @@ -352,8 +367,6 @@ |
353 | 368 | if ( accesskey ) { |
354 | 369 | $link.attr( 'accesskey', accesskey ); |
355 | 370 | tooltip += ' [' + accesskey + ']'; |
356 | | - } |
357 | | - if ( tooltip ) { |
358 | 371 | $link.attr( 'title', tooltip ); |
359 | 372 | } |
360 | 373 | if ( accesskey && tooltip ) { |