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
.util
.htmlEscape(code
) + '</td><td>' + mw
.util
.htmlEscape(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 String.prototype.ucFirst',
73 mw
.test
.addTest('\'mediawiki\'.ucFirst()',
74 'Mediawiki (string)');
75 mw
.test
.addTest('typeof String.prototype.escapeRE',
77 mw
.test
.addTest('\'.st{e}$st\'.escapeRE()',
78 '\\.st\\{e\\}\\$st (string)');
79 mw
.test
.addTest('typeof $.fn.checkboxShiftClick',
81 mw
.test
.addTest('typeof mw.util.rawurlencode',
83 mw
.test
.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )',
84 'Test%3A%20A%26B%2FHere (string)');
85 mw
.test
.addTest('typeof mw.util.wikiGetlink',
87 mw
.test
.addTest('typeof mw.util.getParamValue',
89 mw
.test
.addTest('mw.util.getParamValue( \'action\' )',
90 'mwutiltest (string)');
91 mw
.test
.addTest('typeof mw.util.htmlEscape',
93 mw
.test
.addTest('mw.util.htmlEscape( \'<a href="http://mw.org/?a=b&c=d">link</a>\' )',
94 '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
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)');
106 // Run tests and compare results
112 numberofpartials
= 0,
115 $testrows
= mw
.test
.$table
.find('tr');
116 $.each(mw
.test
.addedTests
, (function ( i
) {
119 exec
= mw
.test
.addedTests
[i
][0];
120 shouldreturn
= mw
.test
.addedTests
[i
][1];
121 shouldcontain
= mw
.test
.addedTests
[i
][2];
122 doesreturn
= eval(exec
);
123 doesreturn
= doesreturn
+ ' (' + typeof doesreturn
+ ')';
124 $thisrow
= $testrows
.eq(i
+ 1);
125 $thisrow
.find('> td').eq(2).text(doesreturn
);
127 if (doesreturn
.indexOf(shouldcontain
) !== -1) {
128 if (doesreturn
== shouldreturn
){
129 $thisrow
.find('> td').eq(3).css('background', '#EFE').text('OK');
132 $thisrow
.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
136 $thisrow
.find('> td').eq(3).css('background', '#FEE').text('ERROR');
142 mw
.test
.$table
.before('<p><strong>Ran ' + numberoftests
+ ' tests. ' + numberofpasseds
+ ' passed test(s). ' + numberoferrors
+ ' error(s). ' + numberofpartials
+ ' partially passed test(s). </p>');
150 mediaWiki
.test
.init();
152 })(jQuery
, mediaWiki
);