Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -21,105 +21,109 @@ |
22 | 22 | * |
23 | 23 | * @param code String Code of the test to be executed |
24 | 24 | * @param result String Expected result in 'var (vartype)' form |
25 | | - * @param contain String Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY |
| 25 | + * @param contain String Important part of the result, |
| 26 | + * if result is different but does contain this it will not return ERROR but PARTIALLY |
26 | 27 | */ |
27 | 28 | 'addTest' : function( code, result, contain ) { |
28 | 29 | if (!contain) { |
29 | 30 | contain = result; |
30 | 31 | } |
31 | | - this.addedTests.push([code, result, contain]); |
32 | | - this.$table.append('<tr><td>' + mw.html.escape(code).replace(/ /g, ' ') + '</td><td>' + mw.html.escape(result).replace(/ /g, ' ') + '</td><td></td><td>?</td></tr>'); |
| 32 | + this.addedTests.push( [code, result, contain] ); |
| 33 | + this.$table.append( '<tr><td>' + mw.html.escape(code).replace(/ /g, ' ' ) |
| 34 | + + '</td><td>' + mw.html.escape(result).replace(/ /g, ' ' ) |
| 35 | + + '</td><td></td><td>?</td></tr>' ); |
33 | 36 | }, |
34 | 37 | |
35 | 38 | /* Initialisation */ |
36 | 39 | 'initialised' : false, |
37 | 40 | 'init' : function () { |
38 | | - if (this.initialised === false) { |
| 41 | + if ( this.initialised === false ) { |
39 | 42 | this.initialised = true; |
40 | 43 | $(function () { |
41 | | - if (wgCanonicalSpecialPageName == 'Blankpage' && mw.util.getParamValue('action') === 'mwutiltest') { |
| 44 | + if ( wgCanonicalSpecialPageName == 'Blankpage' |
| 45 | + && mw.util.getParamValue( 'action' ) === 'mwutiltest' ) { |
42 | 46 | |
43 | 47 | // Build page |
44 | 48 | document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName; |
45 | | - $('#firstHeading').text('mediaWiki.util JavaScript Test'); |
| 49 | + $( '#firstHeading' ).text( 'mediaWiki.util JavaScript Test' ); |
46 | 50 | mw.util.$content.html( |
47 | | - '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' + |
48 | | - '<hr />' + |
49 | | - '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">' + |
50 | | - '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>' + |
51 | | - '</table>' |
| 51 | + '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' |
| 52 | + + '<hr />' |
| 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>' |
| 55 | + + '</table>' |
52 | 56 | ); |
53 | | - mw.test.$table = $('table#mw-mwutiltest-table'); |
| 57 | + mw.test.$table = $( 'table#mw-mwutiltest-table' ); |
54 | 58 | |
55 | 59 | // Populate tests |
56 | | - mw.test.addTest('typeof $.trimLeft', |
57 | | - 'function (string)'); |
58 | | - mw.test.addTest('$.trimLeft(\' foo bar \')', |
59 | | - 'foo bar (string)'); |
60 | | - mw.test.addTest('typeof $.trimRight', |
61 | | - 'function (string)'); |
62 | | - mw.test.addTest('$.trimRight(\' foo bar \')', |
63 | | - ' foo bar (string)'); |
64 | | - mw.test.addTest('typeof $.isEmpty', |
65 | | - 'function (string)'); |
66 | | - mw.test.addTest('$.isEmpty(\'string\')', |
67 | | - 'false (boolean)'); |
68 | | - mw.test.addTest('$.isEmpty(\'0\')', |
69 | | - 'true (boolean)'); |
70 | | - mw.test.addTest('$.isEmpty([])', |
71 | | - 'true (boolean)'); |
72 | | - mw.test.addTest('typeof $.compareArray', |
73 | | - 'function (string)'); |
74 | | - mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )', |
75 | | - 'true (boolean)'); |
76 | | - mw.test.addTest('$.compareArray( [1], [2] )', |
77 | | - 'false (boolean)'); |
78 | | - mw.test.addTest('4', |
79 | | - '4 (number)'); |
80 | | - mw.test.addTest('typeof mediaWiki', |
81 | | - 'object (string)'); |
82 | | - mw.test.addTest('typeof mw', |
83 | | - 'object (string)'); |
84 | | - mw.test.addTest('typeof mw.util', |
85 | | - 'object (string)'); |
86 | | - mw.test.addTest('typeof mw.html', |
87 | | - 'object (string)'); |
88 | | - mw.test.addTest('typeof $.ucFirst', |
89 | | - 'function (string)'); |
90 | | - mw.test.addTest('$.ucFirst( \'mediawiki\' )', |
91 | | - 'Mediawiki (string)'); |
92 | | - mw.test.addTest('typeof $.escapeRE', |
93 | | - 'function (string)'); |
94 | | - mw.test.addTest('$.escapeRE( \'.st{e}$st\' )', |
95 | | - '\\.st\\{e\\}\\$st (string)'); |
96 | | - mw.test.addTest('typeof $.fn.checkboxShiftClick', |
97 | | - 'function (string)'); |
98 | | - mw.test.addTest('typeof mw.util.rawurlencode', |
99 | | - 'function (string)'); |
100 | | - mw.test.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )', |
101 | | - 'Test%3A%20A%26B%2FHere (string)'); |
102 | | - mw.test.addTest('typeof mw.util.wikiGetlink', |
103 | | - 'function (string)'); |
104 | | - mw.test.addTest('typeof mw.util.getParamValue', |
105 | | - 'function (string)'); |
106 | | - mw.test.addTest('mw.util.getParamValue( \'action\' )', |
107 | | - 'mwutiltest (string)'); |
108 | | - mw.test.addTest('mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )', |
109 | | - 'right (string)'); |
110 | | - mw.test.addTest('mw.util.tooltipAccessKeyRegexp.constructor.name', |
111 | | - 'RegExp (string)'); |
112 | | - mw.test.addTest('typeof mw.util.updateTooltipAccessKeys', |
113 | | - 'function (string)'); |
114 | | - mw.test.addTest('typeof mw.util.addPortletLink', |
115 | | - 'function (string)'); |
116 | | - mw.test.addTest('typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )', |
117 | | - 'object (string)'); |
118 | | - 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();', |
119 | | - 'MediaWiki.org (string)'); |
120 | | - mw.test.addTest('mw.html.element( \'hr\' )', |
121 | | - '<hr/> (string)'); |
122 | | - mw.test.addTest('mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )', |
123 | | - '<img src="http://mw.org/?title=Main page&action=edit"/> (string)'); |
| 60 | + mw.test.addTest( 'typeof $.trimLeft', |
| 61 | + 'function (string)' ); |
| 62 | + mw.test.addTest( '$.trimLeft(\' foo bar \')', |
| 63 | + 'foo bar (string)' ); |
| 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\')', |
| 71 | + 'false (boolean)' ); |
| 72 | + mw.test.addTest( '$.isEmpty(\'0\')', |
| 73 | + 'true (boolean)' ); |
| 74 | + mw.test.addTest( '$.isEmpty([])', |
| 75 | + 'true (boolean)' ); |
| 76 | + mw.test.addTest( 'typeof $.compareArray', |
| 77 | + 'function (string)' ); |
| 78 | + mw.test.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )', |
| 79 | + 'true (boolean)' ); |
| 80 | + mw.test.addTest( '$.compareArray( [1], [2] )', |
| 81 | + 'false (boolean)' ); |
| 82 | + mw.test.addTest( '4', |
| 83 | + '4 (number)' ); |
| 84 | + mw.test.addTest( 'typeof mediaWiki', |
| 85 | + 'object (string)' ); |
| 86 | + mw.test.addTest( 'typeof mw', |
| 87 | + 'object (string)' ); |
| 88 | + mw.test.addTest( 'typeof mw.util', |
| 89 | + 'object (string)' ); |
| 90 | + mw.test.addTest( 'typeof mw.html', |
| 91 | + 'object (string)' ); |
| 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\' )', |
| 113 | + 'right (string)' ); |
| 114 | + mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name', |
| 115 | + 'RegExp (string)' ); |
| 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" )', |
| 121 | + 'object (string)' ); |
| 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\' )', |
| 125 | + '<hr/> (string)' ); |
| 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)' ); |
124 | 128 | |
125 | 129 | // Run tests and compare results |
126 | 130 | var exec, |
— | — | @@ -130,34 +134,35 @@ |
131 | 135 | numberofpartials = 0, |
132 | 136 | numberoferrors = 0, |
133 | 137 | $testrows; |
134 | | - $testrows = mw.test.$table.find('tr'); |
135 | | - $.each(mw.test.addedTests, (function ( i ) { |
136 | | - numberoftests++; |
| 138 | + $testrows = mw.test.$table.find( 'tr' ); |
| 139 | + $.each( mw.test.addedTests, function( i ) { |
| 140 | + numberoftests++; |
137 | 141 | |
138 | | - exec = mw.test.addedTests[i][0]; |
139 | | - shouldreturn = mw.test.addedTests[i][1]; |
140 | | - shouldcontain = mw.test.addedTests[i][2]; |
141 | | - doesreturn = eval(exec); |
142 | | - doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
143 | | - $thisrow = $testrows.eq(i + 1); |
144 | | - $thisrow.find('> td').eq(2).html( mw.html.escape(doesreturn).replace(/ /g, ' ') ); |
| 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, ' ' ) ); |
145 | 149 | |
146 | | - if (doesreturn.indexOf(shouldcontain) !== -1) { |
147 | | - if (doesreturn == shouldreturn){ |
148 | | - $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); |
149 | | - numberofpasseds++; |
150 | | - } else { |
151 | | - $thisrow.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>'); |
152 | | - numberofpartials++; |
153 | | - } |
| 150 | + if (doesreturn.indexOf(shouldcontain) !== -1) { |
| 151 | + if (doesreturn == shouldreturn){ |
| 152 | + $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' ); |
| 153 | + numberofpasseds++; |
154 | 154 | } else { |
155 | | - $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR'); |
156 | | - numberoferrors++; |
| 155 | + $thisrow.find( '> td' ).eq(3).css( 'background', '#FFE' ).html( '<small>PARTIALLY</small>' ); |
| 156 | + numberofpartials++; |
157 | 157 | } |
| 158 | + } else { |
| 159 | + $thisrow.find( '> td' ).eq(3).css( 'background', '#FEE' ).text( 'ERROR' ); |
| 160 | + numberoferrors++; |
| 161 | + } |
158 | 162 | |
159 | | - }) |
160 | | - ); |
161 | | - mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s). </p>'); |
| 163 | + } ); |
| 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>' ); |
162 | 167 | |
163 | 168 | } |
164 | 169 | }); |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -292,11 +292,16 @@ |
293 | 293 | this.log = function() { }; |
294 | 294 | |
295 | 295 | /* |
| 296 | + * Make the Map-class publicly available |
| 297 | + */ |
| 298 | + this.Map = Map; |
| 299 | + |
| 300 | + /* |
296 | 301 | * List of configuration values |
297 | 302 | * |
298 | 303 | * In legacy mode the values this object wraps will be in the global space |
299 | 304 | */ |
300 | | - this.config = new Map( LEGACY_GLOBALS ); |
| 305 | + this.config = new this.Map( LEGACY_GLOBALS ); |
301 | 306 | |
302 | 307 | /* |
303 | 308 | * Information about the current user |
— | — | @@ -306,7 +311,7 @@ |
307 | 312 | /* |
308 | 313 | * Localization system |
309 | 314 | */ |
310 | | - this.messages = new Map(); |
| 315 | + this.messages = new this.Map(); |
311 | 316 | |
312 | 317 | /* Public Methods */ |
313 | 318 | |