2 * mediaWiki.util Test Suite
4 * Available on "/Special:BlankPage?action=mwutiltest&debug=true")
6 * @author Krinkle <krinklemail@gmail.com>
20 * Adds a row to the test-table
22 * @param String code Code of the test to be executed
23 * @param String result Expected result in 'var (vartype)' form
24 * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
26 'addTest' : function( code
, result
, contain
) {
30 this.addedTests
.push([code
, result
, contain
]);
31 this.$table
.append('<tr><td>' + mw
.html
.escape(code
) + '</td><td>' + mw
.html
.escape(result
) + '<td></td></td><td>?</td></tr>');
35 'initialised' : false,
36 'init' : function () {
37 if (this.initialised
=== false) {
38 this.initialised
= true;
40 if (wgCanonicalSpecialPageName
== 'Blankpage' && mw
.util
.getParamValue('action') === 'mwutiltest') {
43 document
.title
= 'mediaWiki.util JavaScript Test - ' + wgSiteName
;
44 $('#firstHeading').text('mediaWiki.util JavaScript Test');
45 mw
.util
.$content
.html(
46 '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
48 '<table id="mw-mwutiltest-table" class="wikitable sortable"><tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr></table>'
50 mw
.test
.$table
= $('table#mw-mwutiltest-table');
53 mw
.test
.addTest('typeof String.prototype.trim',
55 mw
.test
.addTest('typeof String.prototype.trimLeft',
57 mw
.test
.addTest('typeof String.prototype.trimRight',
59 mw
.test
.addTest('typeof Array.prototype.compare',
61 mw
.test
.addTest('typeof Array.prototype.indexOf',
65 mw
.test
.addTest('typeof mediaWiki',
67 mw
.test
.addTest('typeof mw',
69 mw
.test
.addTest('typeof mw.util',
71 mw
.test
.addTest('typeof mw.html',
73 mw
.test
.addTest('typeof String.prototype.ucFirst',
75 mw
.test
.addTest('\'mediawiki\'.ucFirst()',
76 'Mediawiki (string)');
77 mw
.test
.addTest('typeof String.prototype.escapeRE',
79 mw
.test
.addTest('\'.st{e}$st\'.escapeRE()',
80 '\\.st\\{e\\}\\$st (string)');
81 mw
.test
.addTest('typeof $.fn.checkboxShiftClick',
83 mw
.test
.addTest('typeof mw.util.rawurlencode',
85 mw
.test
.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )',
86 'Test%3A%20A%26B%2FHere (string)');
87 mw
.test
.addTest('typeof mw.util.wikiGetlink',
89 mw
.test
.addTest('typeof mw.util.getParamValue',
91 mw
.test
.addTest('mw.util.getParamValue( \'action\' )',
92 'mwutiltest (string)');
93 mw
.test
.addTest('mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
95 mw
.test
.addTest('mw.util.tooltipAccessKeyRegexp.constructor.name',
97 mw
.test
.addTest('typeof mw.util.updateTooltipAccessKeys',
99 mw
.test
.addTest('typeof mw.util.addPortletLink',
100 'function (string)');
101 mw
.test
.addTest('typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
103 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();',
104 'MediaWiki.org (string)');
105 mw
.test
.addTest('mw.html.element( \'hr\' )',
107 mw
.test
.addTest('mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
108 '<img src="http://mw.org/?title=Main page&action=edit"/> (string)');
110 // Run tests and compare results
116 numberofpartials
= 0,
119 $testrows
= mw
.test
.$table
.find('tr');
120 $.each(mw
.test
.addedTests
, (function ( i
) {
123 exec
= mw
.test
.addedTests
[i
][0];
124 shouldreturn
= mw
.test
.addedTests
[i
][1];
125 shouldcontain
= mw
.test
.addedTests
[i
][2];
126 doesreturn
= eval(exec
);
127 doesreturn
= doesreturn
+ ' (' + typeof doesreturn
+ ')';
128 $thisrow
= $testrows
.eq(i
+ 1);
129 $thisrow
.find('> td').eq(2).text(doesreturn
);
131 if (doesreturn
.indexOf(shouldcontain
) !== -1) {
132 if (doesreturn
== shouldreturn
){
133 $thisrow
.find('> td').eq(3).css('background', '#EFE').text('OK');
136 $thisrow
.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
140 $thisrow
.find('> td').eq(3).css('background', '#FEE').text('ERROR');
146 mw
.test
.$table
.before('<p><strong>Ran ' + numberoftests
+ ' tests. ' + numberofpasseds
+ ' passed test(s). ' + numberoferrors
+ ' error(s). ' + numberofpartials
+ ' partially passed test(s). </p>');
154 mediaWiki
.test
.init();
156 })(jQuery
, mediaWiki
);