2 * mediaWiki Debug Test Suit.
3 * Available on "/Special:BlankPage?action=mwutiltest&debug=true")
17 * Adds a row to the test-table
19 * @param String code Code of the test to be executed
20 * @param String result Expected result in 'var (vartype)' form
21 * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
23 'addTest' : function (code, result, contain) {
27 this.addedTests.push([code, result, contain]);
28 this.$table.append('<tr><td>' + mw.util.htmlEscape(code) + '</td><td>' + mw.util.htmlEscape(result) + '<td></td></td><td>?</td></tr>');
32 'initialised' : false,
33 'init' : function () {
34 if (this.initialised === false) {
35 this.initialised = true;
37 if (wgCanonicalSpecialPageName == 'Blankpage' && mw.util.getParamValue('action') === 'mwutiltest') {
40 document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName;
41 $('#firstHeading').text('mediaWiki.util JavaScript Test');
42 mw.util.$content.html(
43 '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
45 '<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>'
47 mw.test.$table = $('table#mw-mwutiltest-table');
50 mw.test.addTest('typeof String.prototype.trim',
52 mw.test.addTest('typeof String.prototype.trimLeft',
54 mw.test.addTest('typeof String.prototype.trimRight',
56 mw.test.addTest('typeof Array.prototype.compare',
58 mw.test.addTest('typeof Array.prototype.indexOf',
62 mw.test.addTest('typeof mediaWiki',
64 mw.test.addTest('typeof mw',
66 mw.test.addTest('typeof mw.util',
68 mw.test.addTest('typeof String.prototype.ucFirst',
70 mw.test.addTest('\'mediawiki\'.ucFirst()',
71 'Mediawiki (string)');
72 mw.test.addTest('typeof $.fn.enableCheckboxShiftClick',
74 mw.test.addTest('typeof mw.util.rawurlencode',
76 mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')',
77 'Test%3A%20A%26B%2FHere (string)');
78 mw.test.addTest('typeof mw.util.getWikilink',
80 mw.test.addTest('typeof mw.util.getParamValue',
82 mw.test.addTest('mw.util.getParamValue(\'action\')',
83 'mwutiltest (string)');
84 mw.test.addTest('typeof mw.util.htmlEscape',
86 mw.test.addTest('mw.util.htmlEscape(\'<a href="http://mw.org/?a=b&c=d">link</a>\')',
87 '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
88 mw.test.addTest('typeof mw.util.htmlUnescape',
90 mw.test.addTest('mw.util.htmlUnescape(\'<a href="http://mw.org/?a=b&c=d">link</a>\')',
91 '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
92 mw.test.addTest('typeof mw.util.tooltipAccessKeyRegexp',
94 mw.test.addTest('typeof mw.util.updateTooltipAccessKeys',
96 mw.test.addTest('typeof mw.util.addPortletLink',
98 mw.test.addTest('typeof mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print")',
100 mw.test.addTest('a = mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print"); if(a){ a.outerHTML; }',
101 '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)',
102 'href="http://mediawiki.org/"');
104 // Run tests and compare results
110 numberofpartials = 0,
113 $testrows = mw.test.$table.find('tr');
114 $.each(mw.test.addedTests, (function (i) {
117 exec = mw.test.addedTests[i][0];
118 shouldreturn = mw.test.addedTests[i][1];
119 shouldcontain = mw.test.addedTests[i][2];
120 doesreturn = eval(exec);
121 doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
122 $thisrow = $testrows.eq(i + 1);
123 $thisrow.find('> td').eq(2).text(doesreturn);
125 if (doesreturn.indexOf(shouldcontain) !== -1) {
126 if (doesreturn == shouldreturn){
127 $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
130 $thisrow.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
134 $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR');
140 mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s). </p>');
148 mediaWiki.test.init();
150 })(jQuery, mediaWiki);