5da879e043a548f842b3d329baeff99d2d380313
2 * mediaWiki JavaScript library 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,
40 if ( this.initialised
=== false ) {
41 this.initialised
= true;
42 // jQuery document ready
44 if ( mw
.config
.get( 'wgCanonicalSpecialPageName' ) == 'Blankpage'
45 && mw
.util
.getParamValue( 'action' ) === 'mwutiltest' ) {
48 document
.title
= 'mediaWiki JavaScript library test suite - ' + mw
.config
.get( 'wgSiteName' );
49 $( '#firstHeading' ).text( 'mediaWiki JavaScript library test suite' );
50 mw
.util
.$content
.html(
51 '<p>Below is a list of tests to confirm proper functionality of the mediaWiki JavaScript library</p>'
53 + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">'
54 + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>'
57 mw
.test
.$table
= $( 'table#mw-mwutiltest-table' );
60 mw
.test
.addTest( 'typeof $.trimLeft',
61 'function (string)' );
62 mw
.test
.addTest( '$.trimLeft(\' foo bar \')',
64 mw
.test
.addTest( 'typeof $.trimRight',
65 'function (string)' );
66 mw
.test
.addTest( '$.trimRight(\' foo bar \')',
67 ' foo bar (string)' );
68 mw
.test
.addTest( 'typeof $.isEmpty',
69 'function (string)' );
70 mw
.test
.addTest( '$.isEmpty(\'string\')',
72 mw
.test
.addTest( '$.isEmpty(\'0\')',
74 mw
.test
.addTest( '$.isEmpty([])',
76 mw
.test
.addTest( 'typeof $.compareArray',
77 'function (string)' );
78 mw
.test
.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
80 mw
.test
.addTest( '$.compareArray( [1], [2] )',
84 mw
.test
.addTest( 'typeof mediaWiki',
86 mw
.test
.addTest( 'typeof mw',
88 mw
.test
.addTest( 'typeof mw.util',
90 mw
.test
.addTest( 'typeof mw.html',
92 mw
.test
.addTest( 'typeof $.ucFirst',
93 'function (string)' );
94 mw
.test
.addTest( '$.ucFirst( \'mediawiki\' )',
95 'Mediawiki (string)' );
96 mw
.test
.addTest( 'typeof $.escapeRE',
97 'function (string)' );
98 mw
.test
.addTest( '$.escapeRE( \'.st{e}$st\' )',
99 '\\.st\\{e\\}\\$st (string)' );
100 mw
.test
.addTest( 'typeof $.fn.checkboxShiftClick',
101 'function (string)' );
102 mw
.test
.addTest( 'typeof mw.util.rawurlencode',
103 'function (string)' );
104 mw
.test
.addTest( 'mw.util.rawurlencode( \'Test: A&B/Here\' )',
105 'Test%3A%20A%26B%2FHere (string)' );
106 mw
.test
.addTest( 'typeof mw.util.wikiGetlink',
107 'function (string)' );
108 mw
.test
.addTest( 'typeof mw.util.getParamValue',
109 'function (string)' );
110 mw
.test
.addTest( 'mw.util.getParamValue( \'action\' )',
111 'mwutiltest (string)' );
112 mw
.test
.addTest( 'mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
114 mw
.test
.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name',
116 mw
.test
.addTest( 'typeof mw.util.updateTooltipAccessKeys',
117 'function (string)' );
118 mw
.test
.addTest( 'typeof mw.util.addPortletLink',
119 'function (string)' );
120 mw
.test
.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
122 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();',
123 'MediaWiki.org (string)' );
124 mw
.test
.addTest( 'mw.html.element( \'hr\' )',
126 mw
.test
.addTest( 'mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
127 '<img src="http://mw.org/?title=Main page&action=edit"/> (string)' );
129 // Run tests and compare results
135 numberofpartials
= 0,
137 $testrows
= mw
.test
.$table
.find( 'tr' );
139 $.each( mw
.test
.addedTests
, function( i
) {
142 exec
= mw
.test
.addedTests
[i
][0];
143 shouldreturn
= mw
.test
.addedTests
[i
][1];
144 shouldcontain
= mw
.test
.addedTests
[i
][2];
145 doesreturn
= eval( exec
);
146 doesreturn
= doesreturn
+ ' (' + typeof doesreturn
+ ')';
147 $thisrow
= $testrows
.eq( i
+ 1 );
148 $thisrow
.find( '> td' ).eq(2).html( mw
.html
.escape( doesreturn
).replace(/ /g
, ' ' ) );
150 if ( doesreturn
.indexOf( shouldcontain
) !== -1 ) {
151 if (doesreturn
== shouldreturn
){
152 $thisrow
.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' );
155 $thisrow
.find( '> td' ).eq(3).css( 'background', '#FFE' ).html( '<small>PARTIALLY</small>' );
159 $thisrow
.find( '> td' ).eq(3).css( 'background', '#FEE' ).text( 'ERROR' );
164 mw
.test
.$table
.before( '<p><strong>Ran ' + numberoftests
+ ' tests. ' +
165 numberofpasseds
+ ' passed test(s). ' + numberoferrors
+ ' error(s). ' +
166 numberofpartials
+ ' partially passed test(s). </p>' );
174 mediaWiki
.test
.init();
176 } )(jQuery
, mediaWiki
);