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 code String Code of the test to be executed
23 * @param result String Expected result in 'var (vartype)' form
24 * @param contain String Important part of the result,
25 * if result is different but does contain this it will not return ERROR but PARTIALLY
27 'addTest' : function( code
, result
, contain
) {
31 this.addedTests
.push( [code
, result
, contain
] );
32 this.$table
.append( '<tr><td>' + mw
.html
.escape(code
).replace(/ /g
, ' ' )
33 + '</td><td>' + mw
.html
.escape(result
).replace(/ /g
, ' ' )
34 + '</td><td></td><td>?</td></tr>' );
38 'initialised' : false,
39 'init' : function () {
40 if ( this.initialised
=== false ) {
41 this.initialised
= true;
43 if ( wgCanonicalSpecialPageName
== 'Blankpage'
44 && mw
.util
.getParamValue( 'action' ) === 'mwutiltest' ) {
47 document
.title
= 'mediaWiki.util JavaScript Test - ' + wgSiteName
;
48 $( '#firstHeading' ).text( 'mediaWiki.util JavaScript Test' );
49 mw
.util
.$content
.html(
50 '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>'
52 + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">'
53 + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>'
56 mw
.test
.$table
= $( 'table#mw-mwutiltest-table' );
59 mw
.test
.addTest( 'typeof $.trimLeft',
60 'function (string)' );
61 mw
.test
.addTest( '$.trimLeft(\' foo bar \')',
63 mw
.test
.addTest( 'typeof $.trimRight',
64 'function (string)' );
65 mw
.test
.addTest( '$.trimRight(\' foo bar \')',
66 ' foo bar (string)' );
67 mw
.test
.addTest( 'typeof $.isEmpty',
68 'function (string)' );
69 mw
.test
.addTest( '$.isEmpty(\'string\')',
71 mw
.test
.addTest( '$.isEmpty(\'0\')',
73 mw
.test
.addTest( '$.isEmpty([])',
75 mw
.test
.addTest( 'typeof $.compareArray',
76 'function (string)' );
77 mw
.test
.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
79 mw
.test
.addTest( '$.compareArray( [1], [2] )',
83 mw
.test
.addTest( 'typeof mediaWiki',
85 mw
.test
.addTest( 'typeof mw',
87 mw
.test
.addTest( 'typeof mw.util',
89 mw
.test
.addTest( 'typeof mw.html',
91 mw
.test
.addTest( 'typeof $.ucFirst',
92 'function (string)' );
93 mw
.test
.addTest( '$.ucFirst( \'mediawiki\' )',
94 'Mediawiki (string)' );
95 mw
.test
.addTest( 'typeof $.escapeRE',
96 'function (string)' );
97 mw
.test
.addTest( '$.escapeRE( \'.st{e}$st\' )',
98 '\\.st\\{e\\}\\$st (string)' );
99 mw
.test
.addTest( 'typeof $.fn.checkboxShiftClick',
100 'function (string)' );
101 mw
.test
.addTest( 'typeof mw.util.rawurlencode',
102 'function (string)' );
103 mw
.test
.addTest( 'mw.util.rawurlencode( \'Test: A&B/Here\' )',
104 'Test%3A%20A%26B%2FHere (string)' );
105 mw
.test
.addTest( 'typeof mw.util.wikiGetlink',
106 'function (string)' );
107 mw
.test
.addTest( 'typeof mw.util.getParamValue',
108 'function (string)' );
109 mw
.test
.addTest( 'mw.util.getParamValue( \'action\' )',
110 'mwutiltest (string)' );
111 mw
.test
.addTest( 'mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
113 mw
.test
.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name',
115 mw
.test
.addTest( 'typeof mw.util.updateTooltipAccessKeys',
116 'function (string)' );
117 mw
.test
.addTest( 'typeof mw.util.addPortletLink',
118 'function (string)' );
119 mw
.test
.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
121 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();',
122 'MediaWiki.org (string)' );
123 mw
.test
.addTest( 'mw.html.element( \'hr\' )',
125 mw
.test
.addTest( 'mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
126 '<img src="http://mw.org/?title=Main page&action=edit"/> (string)' );
128 // Run tests and compare results
134 numberofpartials
= 0,
137 $testrows
= mw
.test
.$table
.find( 'tr' );
138 $.each( mw
.test
.addedTests
, function( i
) {
141 exec
= mw
.test
.addedTests
[i
][0];
142 shouldreturn
= mw
.test
.addedTests
[i
][1];
143 shouldcontain
= mw
.test
.addedTests
[i
][2];
144 doesreturn
= eval( exec
);
145 doesreturn
= doesreturn
+ ' (' + typeof doesreturn
+ ')';
146 $thisrow
= $testrows
.eq( i
+ 1 );
147 $thisrow
.find( '> td' ).eq(2).html( mw
.html
.escape( doesreturn
).replace(/ /g
, ' ' ) );
149 if (doesreturn
.indexOf(shouldcontain
) !== -1) {
150 if (doesreturn
== shouldreturn
){
151 $thisrow
.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' );
154 $thisrow
.find( '> td' ).eq(3).css( 'background', '#FFE' ).html( '<small>PARTIALLY</small>' );
158 $thisrow
.find( '> td' ).eq(3).css( 'background', '#FEE' ).text( 'ERROR' );
163 mw
.test
.$table
.before( '<p><strong>Ran ' + numberoftests
+ ' tests. ' +
164 numberofpasseds
+ ' passed test(s). ' + numberoferrors
+ ' error(s). ' +
165 numberofpartials
+ ' partially passed test(s). </p>' );
173 mediaWiki
.test
.init();
175 })(jQuery
, mediaWiki
);