2 * mediaWiki.util Test Suit
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.isBrowser( \'safari\' )',
83 mw
.test
.addTest('typeof mw.util.isLayout( \'webKit\' )',
85 mw
.test
.addTest('typeof mw.util.isPlatform( \'MAC\' )',
87 mw
.test
.addTest('typeof mw.util.isBrowserVersion( \'5\' )',
89 mw
.test
.addTest('typeof mw.util.rawurlencode',
91 mw
.test
.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )',
92 'Test%3A%20A%26B%2FHere (string)');
93 mw
.test
.addTest('typeof mw.util.wfGetlink',
95 mw
.test
.addTest('typeof mw.util.getParamValue',
97 mw
.test
.addTest('mw.util.getParamValue( \'action\' )',
98 'mwutiltest (string)');
99 mw
.test
.addTest('typeof mw.util.htmlEscape',
100 'function (string)');
101 mw
.test
.addTest('mw.util.htmlEscape( \'<a href="http://mw.org/?a=b&c=d">link</a>\' )',
102 '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
103 mw
.test
.addTest('typeof mw.util.htmlUnescape',
104 'function (string)');
105 mw
.test
.addTest('mw.util.htmlUnescape( \'<a href="http://mw.org/?a=b&c=d">link</a>\' )',
106 '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
107 mw
.test
.addTest('mw.util.tooltipAccessKeyRegexp.constructor.name',
109 mw
.test
.addTest('typeof mw.util.updateTooltipAccessKeys',
110 'function (string)');
111 mw
.test
.addTest('typeof mw.util.addPortletLink',
112 'function (string)');
113 mw
.test
.addTest('typeof mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print")',
115 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();',
116 'MediaWiki.org (string)');
118 // Run tests and compare results
124 numberofpartials
= 0,
127 $testrows
= mw
.test
.$table
.find('tr');
128 $.each(mw
.test
.addedTests
, (function ( i
) {
131 exec
= mw
.test
.addedTests
[i
][0];
132 shouldreturn
= mw
.test
.addedTests
[i
][1];
133 shouldcontain
= mw
.test
.addedTests
[i
][2];
134 doesreturn
= eval(exec
);
135 doesreturn
= doesreturn
+ ' (' + typeof doesreturn
+ ')';
136 $thisrow
= $testrows
.eq(i
+ 1);
137 $thisrow
.find('> td').eq(2).text(doesreturn
);
139 if (doesreturn
.indexOf(shouldcontain
) !== -1) {
140 if (doesreturn
== shouldreturn
){
141 $thisrow
.find('> td').eq(3).css('background', '#EFE').text('OK');
144 $thisrow
.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
148 $thisrow
.find('> td').eq(3).css('background', '#FEE').text('ERROR');
154 mw
.test
.$table
.before('<p><strong>Ran ' + numberoftests
+ ' tests. ' + numberofpasseds
+ ' passed test(s). ' + numberoferrors
+ ' error(s). ' + numberofpartials
+ ' partially passed test(s). </p>');
162 mediaWiki
.test
.init();
164 })(jQuery
, mediaWiki
);