mediawiki.jqueryMsg: Fix 'asciiAlphabetLiteral' definition
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jqueryMsg.test.js
1 ( function ( mw, $ ) {
2 var formatText, formatParse, formatnumTests, specialCharactersPageName, expectedListUsers,
3 expectedListUsersSitename, expectedEntrypoints,
4 mwLanguageCache = {},
5 hasOwn = Object.hasOwnProperty;
6
7 // When the expected result is the same in both modes
8 function assertBothModes( assert, parserArguments, expectedResult, assertMessage ) {
9 assert.equal( formatText.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'text\'' );
10 assert.equal( formatParse.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'parse\'' );
11 }
12
13 QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( {
14 setup: function () {
15 this.originalMwLanguage = mw.language;
16 this.parserDefaults = mw.jqueryMsg.getParserDefaults();
17 mw.jqueryMsg.setParserDefaults( {
18 magic: {
19 SITENAME: 'Wiki'
20 }
21 } );
22
23 specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
24
25 expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
26 expectedListUsersSitename = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户' +
27 'Wiki</a>';
28
29 expectedEntrypoints = '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
30
31 formatText = mw.jqueryMsg.getMessageFunction( {
32 format: 'text'
33 } );
34
35 formatParse = mw.jqueryMsg.getMessageFunction( {
36 format: 'parse'
37 } );
38 },
39 teardown: function () {
40 mw.language = this.originalMwLanguage;
41 mw.jqueryMsg.setParserDefaults( this.parserDefaults );
42 },
43 config: {
44 wgArticlePath: '/wiki/$1',
45 // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
46 wgNamespaceIds: {
47 template: 10,
48 template_talk: 11,
49 // Localised
50 szablon: 10,
51 dyskusja_szablonu: 11
52 },
53 // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
54 wgFormattedNamespaces: {
55 // Localised
56 10: 'Szablon',
57 11: 'Dyskusja szablonu'
58 }
59 },
60 // Messages that are reused in multiple tests
61 messages: {
62 // The values for gender are not significant,
63 // what matters is which of the values is choosen by the parser
64 'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
65 'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
66
67 'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
68 // See https://phabricator.wikimedia.org/T71993
69 'plural-msg-explicit-forms-nested': 'Found {{PLURAL:$1|$1 results|0=no results in {{SITENAME}}|1=$1 result}}',
70 // Assume the grammar form grammar_case_foo is not valid in any language
71 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
72
73 'formatnum-msg': '{{formatnum:$1}}',
74
75 'portal-url': 'Project:Community portal',
76 'see-portal-url': '{{Int:portal-url}} is an important community page.',
77
78 'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
79 'jquerymsg-test-statistics-users-sitename': '注册[[Special:ListUsers|用户{{SITENAME}}]]',
80
81 'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
82
83 'external-link-replace': 'Foo [$1 bar]',
84 'external-link-plural': 'Foo {{PLURAL:$1|is [$2 one]|are [$2 some]|2=[$2 two]|3=three|4=a=b}} things.',
85 'plural-only-explicit-forms': 'It is a {{PLURAL:$1|1=single|2=double}} room.',
86 'plural-empty-explicit-form': 'There is me{{PLURAL:$1|0=| and other people}}.'
87 }
88 } ) );
89
90 /**
91 * Be careful to no run this in parallel as it uses a global identifier (mw.language)
92 * to transport the module back to the test. It musn't be overwritten concurrentely.
93 *
94 * This function caches the mw.language data to avoid having to request the same module
95 * multiple times. There is more than one test case for any given language.
96 */
97 function getMwLanguage( langCode ) {
98 if ( !hasOwn.call( mwLanguageCache, langCode ) ) {
99 mwLanguageCache[ langCode ] = $.ajax( {
100 url: mw.util.wikiScript( 'load' ),
101 data: {
102 skin: mw.config.get( 'skin' ),
103 lang: langCode,
104 debug: mw.config.get( 'debug' ),
105 modules: [
106 'mediawiki.language.data',
107 'mediawiki.language'
108 ].join( '|' ),
109 only: 'scripts'
110 },
111 dataType: 'script',
112 cache: true
113 } ).then( function () {
114 return mw.language;
115 } );
116 }
117 return mwLanguageCache[ langCode ];
118 }
119
120 /**
121 * @param {Function[]} tasks List of functions that perform tasks
122 * that may be asynchronous. Invoke the callback parameter when done.
123 */
124 function process( tasks ) {
125 /*jshint latedef:false */
126 function abort() {
127 tasks.splice( 0, tasks.length );
128 next();
129 }
130 function next() {
131 if ( !tasks ) {
132 // This happens if after the process is completed, one of our callbacks is
133 // invoked. This can happen if a test timed out but the process was still
134 // running. In that case, ignore it. Don't invoke complete() a second time.
135 return;
136 }
137 var task = tasks.shift();
138 if ( task ) {
139 task( next, abort );
140 } else {
141 // Remove tasks list to indicate the process is final.
142 tasks = null;
143 }
144 }
145 next();
146 }
147
148 QUnit.test( 'Replace', 15, function ( assert ) {
149 mw.messages.set( 'simple', 'Foo $1 baz $2' );
150
151 assert.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
152 assert.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
153 assert.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
154
155 mw.messages.set( 'plain-input', '<foo foo="foo">x$1y&lt;</foo>z' );
156
157 assert.equal(
158 formatParse( 'plain-input', 'bar' ),
159 '&lt;foo foo="foo"&gt;xbary&amp;lt;&lt;/foo&gt;z',
160 'Input is not considered html'
161 );
162
163 mw.messages.set( 'plain-replace', 'Foo $1' );
164
165 assert.equal(
166 formatParse( 'plain-replace', '<bar bar="bar">&gt;</bar>' ),
167 'Foo &lt;bar bar="bar"&gt;&amp;gt;&lt;/bar&gt;',
168 'Replacement is not considered html'
169 );
170
171 mw.messages.set( 'object-replace', 'Foo $1' );
172
173 assert.equal(
174 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ) ),
175 'Foo <div class="bar">&gt;</div>',
176 'jQuery objects are preserved as raw html'
177 );
178
179 assert.equal(
180 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ).get( 0 ) ),
181 'Foo <div class="bar">&gt;</div>',
182 'HTMLElement objects are preserved as raw html'
183 );
184
185 assert.equal(
186 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ).toArray() ),
187 'Foo <div class="bar">&gt;</div>',
188 'HTMLElement[] arrays are preserved as raw html'
189 );
190
191 assert.equal(
192 formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
193 'Foo <a href="http://example.org/?x=y&amp;z">bar</a>',
194 'Href is not double-escaped in wikilink function'
195 );
196 assert.equal(
197 formatParse( 'external-link-plural', 1, 'http://example.org' ),
198 'Foo is <a href="http://example.org">one</a> things.',
199 'Link is expanded inside plural and is not escaped html'
200 );
201 assert.equal(
202 formatParse( 'external-link-plural', 2, 'http://example.org' ),
203 'Foo <a href=\"http://example.org\">two</a> things.',
204 'Link is expanded inside an explicit plural form and is not escaped html'
205 );
206 assert.equal(
207 formatParse( 'external-link-plural', 3 ),
208 'Foo three things.',
209 'A simple explicit plural form co-existing with complex explicit plural forms'
210 );
211 assert.equal(
212 formatParse( 'external-link-plural', 4, 'http://example.org' ),
213 'Foo a=b things.',
214 'Only first equal sign is used as delimiter for explicit plural form. Repeated equal signs does not create issue'
215 );
216 assert.equal(
217 formatParse( 'external-link-plural', 6, 'http://example.org' ),
218 'Foo are <a href="http://example.org">some</a> things.',
219 'Plural fallback to the "other" plural form'
220 );
221 assert.equal(
222 formatParse( 'plural-only-explicit-forms', 2 ),
223 'It is a double room.',
224 'Plural with explicit forms alone.'
225 );
226 } );
227
228 QUnit.test( 'Plural', 9, function ( assert ) {
229 assert.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
230 assert.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
231 assert.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
232 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
233 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in Wiki', 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
234 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
235 assert.equal( formatParse( 'plural-empty-explicit-form', 0 ), 'There is me.' );
236 assert.equal( formatParse( 'plural-empty-explicit-form', 1 ), 'There is me and other people.' );
237 assert.equal( formatParse( 'plural-empty-explicit-form', 2 ), 'There is me and other people.' );
238 } );
239
240 QUnit.test( 'Gender', 15, function ( assert ) {
241 var originalGender = mw.user.options.get( 'gender' );
242
243 // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
244 // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
245 mw.user.options.set( 'gender', 'male' );
246 assert.equal(
247 formatParse( 'gender-msg', 'Bob', 'male' ),
248 'Bob: blue',
249 'Masculine from string "male"'
250 );
251 assert.equal(
252 formatParse( 'gender-msg', 'Bob', mw.user ),
253 'Bob: blue',
254 'Masculine from mw.user object'
255 );
256 assert.equal(
257 formatParse( 'gender-msg-currentuser' ),
258 'blue',
259 'Masculine for current user'
260 );
261
262 mw.user.options.set( 'gender', 'female' );
263 assert.equal(
264 formatParse( 'gender-msg', 'Alice', 'female' ),
265 'Alice: pink',
266 'Feminine from string "female"' );
267 assert.equal(
268 formatParse( 'gender-msg', 'Alice', mw.user ),
269 'Alice: pink',
270 'Feminine from mw.user object'
271 );
272 assert.equal(
273 formatParse( 'gender-msg-currentuser' ),
274 'pink',
275 'Feminine for current user'
276 );
277
278 mw.user.options.set( 'gender', 'unknown' );
279 assert.equal(
280 formatParse( 'gender-msg', 'Foo', mw.user ),
281 'Foo: green',
282 'Neutral from mw.user object' );
283 assert.equal(
284 formatParse( 'gender-msg', 'User' ),
285 'User: green',
286 'Neutral when no parameter given' );
287 assert.equal(
288 formatParse( 'gender-msg', 'User', 'unknown' ),
289 'User: green',
290 'Neutral from string "unknown"'
291 );
292 assert.equal(
293 formatParse( 'gender-msg-currentuser' ),
294 'green',
295 'Neutral for current user'
296 );
297
298 mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
299
300 assert.equal(
301 formatParse( 'gender-msg-one-form', 'male', 10 ),
302 'User: 10 edits',
303 'Gender neutral and plural form'
304 );
305 assert.equal(
306 formatParse( 'gender-msg-one-form', 'female', 1 ),
307 'User: 1 edit',
308 'Gender neutral and singular form'
309 );
310
311 mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
312 assert.equal(
313 formatParse( 'gender-msg-lowercase', 'male' ),
314 'he is awesome',
315 'Gender masculine'
316 );
317 assert.equal(
318 formatParse( 'gender-msg-lowercase', 'female' ),
319 'she is awesome',
320 'Gender feminine'
321 );
322
323 mw.messages.set( 'gender-msg-wrong', '{{gender}} test' );
324 assert.equal(
325 formatParse( 'gender-msg-wrong', 'female' ),
326 ' test',
327 'Invalid syntax should result in {{gender}} simply being stripped away'
328 );
329
330 mw.user.options.set( 'gender', originalGender );
331 } );
332
333 QUnit.test( 'Case changing', 8, function ( assert ) {
334 mw.messages.set( 'to-lowercase', '{{lc:thIS hAS MEsSed uP CapItaliZatiON}}' );
335 assert.equal( formatParse( 'to-lowercase' ), 'this has messed up capitalization', 'To lowercase' );
336
337 mw.messages.set( 'to-caps', '{{uc:thIS hAS MEsSed uP CapItaliZatiON}}' );
338 assert.equal( formatParse( 'to-caps' ), 'THIS HAS MESSED UP CAPITALIZATION', 'To caps' );
339
340 mw.messages.set( 'uc-to-lcfirst', '{{lcfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
341 mw.messages.set( 'lc-to-lcfirst', '{{lcfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
342 assert.equal( formatParse( 'uc-to-lcfirst' ), 'tHis hAS MEsSed uP CapItaliZatiON', 'Lcfirst caps' );
343 assert.equal( formatParse( 'lc-to-lcfirst' ), 'thIS hAS MEsSed uP CapItaliZatiON', 'Lcfirst lowercase' );
344
345 mw.messages.set( 'uc-to-ucfirst', '{{ucfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
346 mw.messages.set( 'lc-to-ucfirst', '{{ucfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
347 assert.equal( formatParse( 'uc-to-ucfirst' ), 'THis hAS MEsSed uP CapItaliZatiON', 'Ucfirst caps' );
348 assert.equal( formatParse( 'lc-to-ucfirst' ), 'ThIS hAS MEsSed uP CapItaliZatiON', 'Ucfirst lowercase' );
349
350 mw.messages.set( 'mixed-to-sentence', '{{ucfirst:{{lc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
351 assert.equal( formatParse( 'mixed-to-sentence' ), 'This has messed up capitalization', 'To sentence case' );
352 mw.messages.set( 'all-caps-except-first', '{{lcfirst:{{uc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
353 assert.equal( formatParse( 'all-caps-except-first' ), 'tHIS HAS MESSED UP CAPITALIZATION', 'To opposite sentence case' );
354 } );
355
356 QUnit.test( 'Grammar', 2, function ( assert ) {
357 assert.equal( formatParse( 'grammar-msg' ), 'Przeszukaj Wiki', 'Grammar Test with sitename' );
358
359 mw.messages.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
360 assert.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
361 } );
362
363 QUnit.test( 'Match PHP parser', mw.libs.phpParserData.tests.length, function ( assert ) {
364 mw.messages.set( mw.libs.phpParserData.messages );
365 var tasks = $.map( mw.libs.phpParserData.tests, function ( test ) {
366 return function ( next, abort ) {
367 var done = assert.async();
368 getMwLanguage( test.lang )
369 .then( function ( langClass ) {
370 mw.config.set( 'wgUserLanguage', test.lang );
371 var parser = new mw.jqueryMsg.parser( { language: langClass } );
372 assert.equal(
373 parser.parse( test.key, test.args ).html(),
374 test.result,
375 test.name
376 );
377 }, function () {
378 assert.ok( false, 'Language "' + test.lang + '" failed to load.' );
379 } )
380 .then( done, done )
381 .then( next, abort );
382 };
383 } );
384
385 process( tasks );
386 } );
387
388 QUnit.test( 'Links', 14, function ( assert ) {
389 var testCases,
390 expectedDisambiguationsText,
391 expectedMultipleBars,
392 expectedSpecialCharacters;
393
394 // The below three are all identical to or based on real messages. For disambiguations-text,
395 // the bold was removed because it is not yet implemented.
396
397 assert.htmlEqual(
398 formatParse( 'jquerymsg-test-statistics-users' ),
399 expectedListUsers,
400 'Piped wikilink'
401 );
402
403 expectedDisambiguationsText = 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from ' +
404 '<a title="MediaWiki:Disambiguationspage" href="/wiki/MediaWiki:Disambiguationspage">MediaWiki:Disambiguationspage</a>.';
405
406 mw.messages.set( 'disambiguations-text', 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from [[MediaWiki:Disambiguationspage]].' );
407 assert.htmlEqual(
408 formatParse( 'disambiguations-text' ),
409 expectedDisambiguationsText,
410 'Wikilink without pipe'
411 );
412
413 assert.htmlEqual(
414 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
415 expectedEntrypoints,
416 'External link'
417 );
418
419 // Pipe trick is not supported currently, but should not parse as text either.
420 mw.messages.set( 'pipe-trick', '[[Tampa, Florida|]]' );
421 mw.messages.set( 'reverse-pipe-trick', '[[|Tampa, Florida]]' );
422 mw.messages.set( 'empty-link', '[[]]' );
423 this.suppressWarnings();
424 assert.equal(
425 formatParse( 'pipe-trick' ),
426 '[[Tampa, Florida|]]',
427 'Pipe trick should not be parsed.'
428 );
429 assert.equal(
430 formatParse( 'reverse-pipe-trick' ),
431 '[[|Tampa, Florida]]',
432 'Reverse pipe trick should not be parsed.'
433 );
434 assert.equal(
435 formatParse( 'empty-link' ),
436 '[[]]',
437 'Empty link should not be parsed.'
438 );
439 this.restoreWarnings();
440
441 expectedMultipleBars = '<a title="Main Page" href="/wiki/Main_Page">Main|Page</a>';
442 mw.messages.set( 'multiple-bars', '[[Main Page|Main|Page]]' );
443 assert.htmlEqual(
444 formatParse( 'multiple-bars' ),
445 expectedMultipleBars,
446 'Bar in anchor'
447 );
448
449 expectedSpecialCharacters = '<a title="&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_%27Exotic_Island%27%3F">&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?</a>';
450
451 mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' );
452 assert.htmlEqual(
453 formatParse( 'special-characters' ),
454 expectedSpecialCharacters,
455 'Special characters'
456 );
457
458 mw.messages.set( 'leading-colon', '[[:File:Foo.jpg]]' );
459 assert.htmlEqual(
460 formatParse( 'leading-colon' ),
461 '<a title="File:Foo.jpg" href="/wiki/File:Foo.jpg">File:Foo.jpg</a>',
462 'Leading colon in links is stripped'
463 );
464
465 assert.htmlEqual(
466 formatParse( 'jquerymsg-test-statistics-users-sitename' ),
467 expectedListUsersSitename,
468 'Piped wikilink with parser function in the text'
469 );
470
471 testCases = [
472 [
473 'extlink-html-full',
474 'asd [http://example.org <strong>Example</strong>] asd',
475 'asd <a href="http://example.org"><strong>Example</strong></a> asd'
476 ],
477 [
478 'extlink-html-partial',
479 'asd [http://example.org foo <strong>Example</strong> bar] asd',
480 'asd <a href="http://example.org">foo <strong>Example</strong> bar</a> asd'
481 ],
482 [
483 'wikilink-html-full',
484 'asd [[Example|<strong>Example</strong>]] asd',
485 'asd <a title="Example" href="/wiki/Example"><strong>Example</strong></a> asd'
486 ],
487 [
488 'wikilink-html-partial',
489 'asd [[Example|foo <strong>Example</strong> bar]] asd',
490 'asd <a title="Example" href="/wiki/Example">foo <strong>Example</strong> bar</a> asd'
491 ]
492 ];
493
494 $.each( testCases, function () {
495 var
496 key = this[ 0 ],
497 input = this[ 1 ],
498 output = this[ 2 ];
499 mw.messages.set( key, input );
500 assert.htmlEqual(
501 formatParse( key ),
502 output,
503 'HTML in links: ' + key
504 );
505 } );
506 } );
507
508 QUnit.test( 'Replacements in links', 14, function ( assert ) {
509 var testCases = [
510 [
511 'extlink-param-href-full',
512 'asd [$1 Example] asd',
513 'asd <a href="http://example.com">Example</a> asd'
514 ],
515 [
516 'extlink-param-href-partial',
517 'asd [$1/example Example] asd',
518 'asd <a href="http://example.com/example">Example</a> asd'
519 ],
520 [
521 'extlink-param-text-full',
522 'asd [http://example.org $2] asd',
523 'asd <a href="http://example.org">Text</a> asd'
524 ],
525 [
526 'extlink-param-text-partial',
527 'asd [http://example.org Example $2] asd',
528 'asd <a href="http://example.org">Example Text</a> asd'
529 ],
530 [
531 'extlink-param-both-full',
532 'asd [$1 $2] asd',
533 'asd <a href="http://example.com">Text</a> asd'
534 ],
535 [
536 'extlink-param-both-partial',
537 'asd [$1/example Example $2] asd',
538 'asd <a href="http://example.com/example">Example Text</a> asd'
539 ],
540 [
541 'wikilink-param-href-full',
542 'asd [[$1|Example]] asd',
543 'asd <a title="Example" href="/wiki/Example">Example</a> asd'
544 ],
545 [
546 'wikilink-param-href-partial',
547 'asd [[$1/Test|Example]] asd',
548 'asd <a title="Example/Test" href="/wiki/Example/Test">Example</a> asd'
549 ],
550 [
551 'wikilink-param-text-full',
552 'asd [[Example|$2]] asd',
553 'asd <a title="Example" href="/wiki/Example">Text</a> asd'
554 ],
555 [
556 'wikilink-param-text-partial',
557 'asd [[Example|Example $2]] asd',
558 'asd <a title="Example" href="/wiki/Example">Example Text</a> asd'
559 ],
560 [
561 'wikilink-param-both-full',
562 'asd [[$1|$2]] asd',
563 'asd <a title="Example" href="/wiki/Example">Text</a> asd'
564 ],
565 [
566 'wikilink-param-both-partial',
567 'asd [[$1/Test|Example $2]] asd',
568 'asd <a title="Example/Test" href="/wiki/Example/Test">Example Text</a> asd'
569 ],
570 [
571 'wikilink-param-unpiped-full',
572 'asd [[$1]] asd',
573 'asd <a title="Example" href="/wiki/Example">Example</a> asd'
574 ],
575 [
576 'wikilink-param-unpiped-partial',
577 'asd [[$1/Test]] asd',
578 'asd <a title="Example/Test" href="/wiki/Example/Test">Example/Test</a> asd'
579 ]
580 ];
581
582 $.each( testCases, function () {
583 var
584 key = this[ 0 ],
585 input = this[ 1 ],
586 output = this[ 2 ],
587 paramHref = key.slice( 0, 8 ) === 'wikilink' ? 'Example' : 'http://example.com',
588 paramText = 'Text';
589 mw.messages.set( key, input );
590 assert.htmlEqual(
591 formatParse( key, paramHref, paramText ),
592 output,
593 'Replacements in links: ' + key
594 );
595 } );
596 } );
597
598 // Tests that {{-transformation vs. general parsing are done as requested
599 QUnit.test( 'Curly brace transformation', 16, function ( assert ) {
600 var oldUserLang = mw.config.get( 'wgUserLanguage' );
601
602 assertBothModes( assert, [ 'gender-msg', 'Bob', 'male' ], 'Bob: blue', 'gender is resolved' );
603
604 assertBothModes( assert, [ 'plural-msg', 5 ], 'Found 5 items', 'plural is resolved' );
605
606 assertBothModes( assert, [ 'grammar-msg' ], 'Przeszukaj Wiki', 'grammar is resolved' );
607
608 mw.config.set( 'wgUserLanguage', 'en' );
609 assertBothModes( assert, [ 'formatnum-msg', '987654321.654321' ], '987,654,321.654', 'formatnum is resolved' );
610
611 // Test non-{{ wikitext, where behavior differs
612
613 // Wikilink
614 assert.equal(
615 formatText( 'jquerymsg-test-statistics-users' ),
616 mw.messages.get( 'jquerymsg-test-statistics-users' ),
617 'Internal link message unchanged when format is \'text\''
618 );
619 assert.htmlEqual(
620 formatParse( 'jquerymsg-test-statistics-users' ),
621 expectedListUsers,
622 'Internal link message parsed when format is \'parse\''
623 );
624
625 // External link
626 assert.equal(
627 formatText( 'jquerymsg-test-version-entrypoints-index-php' ),
628 mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ),
629 'External link message unchanged when format is \'text\''
630 );
631 assert.htmlEqual(
632 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
633 expectedEntrypoints,
634 'External link message processed when format is \'parse\''
635 );
636
637 // External link with parameter
638 assert.equal(
639 formatText( 'external-link-replace', 'http://example.com' ),
640 'Foo [http://example.com bar]',
641 'External link message only substitutes parameter when format is \'text\''
642 );
643 assert.htmlEqual(
644 formatParse( 'external-link-replace', 'http://example.com' ),
645 'Foo <a href="http://example.com">bar</a>',
646 'External link message processed when format is \'parse\''
647 );
648 assert.htmlEqual(
649 formatParse( 'external-link-replace', $( '<i>' ) ),
650 'Foo <i>bar</i>',
651 'External link message processed as jQuery object when format is \'parse\''
652 );
653 assert.htmlEqual(
654 formatParse( 'external-link-replace', function () {} ),
655 'Foo <a href="#">bar</a>',
656 'External link message processed as function when format is \'parse\''
657 );
658
659 mw.config.set( 'wgUserLanguage', oldUserLang );
660 } );
661
662 QUnit.test( 'Int', 4, function ( assert ) {
663 var newarticletextSource = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the [[{{Int:Foobar}}|foobar]] for more info). If you are here by mistake, click your browser\'s back button.',
664 expectedNewarticletext,
665 helpPageTitle = 'Help:Foobar';
666
667 mw.messages.set( 'foobar', helpPageTitle );
668
669 expectedNewarticletext = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the ' +
670 '<a title="Help:Foobar" href="/wiki/Help:Foobar">foobar</a> for more info). If you are here by mistake, click your browser\'s back button.';
671
672 mw.messages.set( 'newarticletext', newarticletextSource );
673
674 assert.htmlEqual(
675 formatParse( 'newarticletext' ),
676 expectedNewarticletext,
677 'Link with nested message'
678 );
679
680 assert.equal(
681 formatParse( 'see-portal-url' ),
682 'Project:Community portal is an important community page.',
683 'Nested message'
684 );
685
686 mw.messages.set( 'newarticletext-lowercase',
687 newarticletextSource.replace( 'Int:Helppage', 'int:helppage' ) );
688
689 assert.htmlEqual(
690 formatParse( 'newarticletext-lowercase' ),
691 expectedNewarticletext,
692 'Link with nested message, lowercase include'
693 );
694
695 mw.messages.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
696
697 assert.equal(
698 formatParse( 'uses-missing-int' ),
699 '[doesnt-exist]',
700 'int: where nested message does not exist'
701 );
702 } );
703
704 QUnit.test( 'Ns', 4, function ( assert ) {
705 mw.messages.set( 'ns-template-talk', '{{ns:Template talk}}' );
706 assert.equal(
707 formatParse( 'ns-template-talk' ),
708 'Dyskusja szablonu',
709 'ns: returns localised namespace when used with a canonical namespace name'
710 );
711
712 mw.messages.set( 'ns-10', '{{ns:10}}' );
713 assert.equal(
714 formatParse( 'ns-10' ),
715 'Szablon',
716 'ns: returns localised namespace when used with a namespace number'
717 );
718
719 mw.messages.set( 'ns-unknown', '{{ns:doesnt-exist}}' );
720 assert.equal(
721 formatParse( 'ns-unknown' ),
722 '',
723 'ns: returns empty string for unknown namespace name'
724 );
725
726 mw.messages.set( 'ns-in-a-link', '[[{{ns:template}}:Foo]]' );
727 assert.equal(
728 formatParse( 'ns-in-a-link' ),
729 '<a title="Szablon:Foo" href="/wiki/Szablon:Foo">Szablon:Foo</a>',
730 'ns: works when used inside a wikilink'
731 );
732 } );
733
734 // Tests that getMessageFunction is used for non-plain messages with curly braces or
735 // square brackets, but not otherwise.
736 QUnit.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert ) {
737 var oldGMF, outerCalled, innerCalled;
738
739 mw.messages.set( {
740 'curly-brace': '{{int:message}}',
741 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
742 'double-square-bracket': '[[Some page]]',
743 regular: 'Other message'
744 } );
745
746 oldGMF = mw.jqueryMsg.getMessageFunction;
747
748 mw.jqueryMsg.getMessageFunction = function () {
749 outerCalled = true;
750 return function () {
751 innerCalled = true;
752 };
753 };
754
755 function verifyGetMessageFunction( key, format, shouldCall ) {
756 var message;
757 outerCalled = false;
758 innerCalled = false;
759 message = mw.message( key );
760 message[ format ]();
761 assert.strictEqual( outerCalled, shouldCall, 'Outer function called for ' + key );
762 assert.strictEqual( innerCalled, shouldCall, 'Inner function called for ' + key );
763 delete mw.messages[ format ];
764 }
765
766 verifyGetMessageFunction( 'curly-brace', 'parse', true );
767 verifyGetMessageFunction( 'curly-brace', 'plain', false );
768
769 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
770 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
771
772 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
773 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
774
775 verifyGetMessageFunction( 'regular', 'parse', false );
776 verifyGetMessageFunction( 'regular', 'plain', false );
777
778 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
779 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
780 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
781
782 mw.jqueryMsg.getMessageFunction = oldGMF;
783 } );
784
785 formatnumTests = [
786 {
787 lang: 'en',
788 number: 987654321.654321,
789 result: '987,654,321.654',
790 description: 'formatnum test for English, decimal separator'
791 },
792 {
793 lang: 'ar',
794 number: 987654321.654321,
795 result: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
796 description: 'formatnum test for Arabic, with decimal separator'
797 },
798 {
799 lang: 'ar',
800 number: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
801 result: 987654321,
802 integer: true,
803 description: 'formatnum test for Arabic, with decimal separator, reverse'
804 },
805 {
806 lang: 'ar',
807 number: -12.89,
808 result: '-١٢٫٨٩',
809 description: 'formatnum test for Arabic, negative number'
810 },
811 {
812 lang: 'ar',
813 number: '-١٢٫٨٩',
814 result: -12,
815 integer: true,
816 description: 'formatnum test for Arabic, negative number, reverse'
817 },
818 {
819 lang: 'nl',
820 number: 987654321.654321,
821 result: '987.654.321,654',
822 description: 'formatnum test for Nederlands, decimal separator'
823 },
824 {
825 lang: 'nl',
826 number: -12.89,
827 result: '-12,89',
828 description: 'formatnum test for Nederlands, negative number'
829 },
830 {
831 lang: 'nl',
832 number: '.89',
833 result: '0,89',
834 description: 'formatnum test for Nederlands'
835 },
836 {
837 lang: 'nl',
838 number: 'invalidnumber',
839 result: 'invalidnumber',
840 description: 'formatnum test for Nederlands, invalid number'
841 },
842 {
843 lang: 'ml',
844 number: '1000000000',
845 result: '1,00,00,00,000',
846 description: 'formatnum test for Malayalam'
847 },
848 {
849 lang: 'ml',
850 number: '-1000000000',
851 result: '-1,00,00,00,000',
852 description: 'formatnum test for Malayalam, negative number'
853 },
854 /*
855 * This will fail because of wrong pattern for ml in MW(different from CLDR)
856 {
857 lang: 'ml',
858 number: '1000000000.000',
859 result: '1,00,00,00,000.000',
860 description: 'formatnum test for Malayalam with decimal place'
861 },
862 */
863 {
864 lang: 'hi',
865 number: '123456789.123456789',
866 result: '१२,३४,५६,७८९',
867 description: 'formatnum test for Hindi'
868 },
869 {
870 lang: 'hi',
871 number: '१२,३४,५६,७८९',
872 result: '१२,३४,५६,७८९',
873 description: 'formatnum test for Hindi, Devanagari digits passed'
874 },
875 {
876 lang: 'hi',
877 number: '१२३४५६,७८९',
878 result: '123456',
879 integer: true,
880 description: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
881 }
882 ];
883
884 QUnit.test( 'formatnum', formatnumTests.length, function ( assert ) {
885 mw.messages.set( 'formatnum-msg', '{{formatnum:$1}}' );
886 mw.messages.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
887 var queue = $.map( formatnumTests, function ( test ) {
888 return function ( next, abort ) {
889 var done = assert.async();
890 getMwLanguage( test.lang )
891 .then( function ( langClass ) {
892 mw.config.set( 'wgUserLanguage', test.lang );
893 var parser = new mw.jqueryMsg.parser( { language: langClass } );
894 assert.equal(
895 parser.parse( test.integer ? 'formatnum-msg-int' : 'formatnum-msg',
896 [ test.number ] ).html(),
897 test.result,
898 test.description
899 );
900 }, function () {
901 assert.ok( false, 'Language "' + test.lang + '" failed to load' );
902 } )
903 .then( done, done )
904 .then( next, abort );
905 };
906 } );
907 process( queue );
908 } );
909
910 // HTML in wikitext
911 QUnit.test( 'HTML', 33, function ( assert ) {
912 mw.messages.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
913
914 assertBothModes( assert, [ 'jquerymsg-italics-msg' ], mw.messages.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
915
916 mw.messages.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
917 assertBothModes( assert, [ 'jquerymsg-bold-msg' ], mw.messages.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
918
919 mw.messages.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
920 assertBothModes( assert, [ 'jquerymsg-bold-italics-msg' ], mw.messages.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
921
922 mw.messages.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
923 assertBothModes( assert, [ 'jquerymsg-italics-bold-msg' ], mw.messages.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
924
925 mw.messages.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
926
927 assert.htmlEqual(
928 formatParse( 'jquerymsg-italics-with-link' ),
929 'An <i>italicized <a title="link" href="' + mw.html.escape( mw.util.getUrl( 'link' ) ) + '">wiki-link</i>',
930 'Italics with link inside in parse mode'
931 );
932
933 assert.equal(
934 formatText( 'jquerymsg-italics-with-link' ),
935 mw.messages.get( 'jquerymsg-italics-with-link' ),
936 'Italics with link unchanged in text mode'
937 );
938
939 mw.messages.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
940 assert.htmlEqual(
941 formatParse( 'jquerymsg-italics-id-class' ),
942 mw.messages.get( 'jquerymsg-italics-id-class' ),
943 'ID and class are allowed'
944 );
945
946 mw.messages.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
947 assert.htmlEqual(
948 formatParse( 'jquerymsg-italics-onclick' ),
949 '&lt;i onclick=&quot;alert(\'foo\')&quot;&gt;Foo&lt;/i&gt;',
950 'element with onclick is escaped because it is not allowed'
951 );
952
953 mw.messages.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
954 assert.htmlEqual(
955 formatParse( 'jquerymsg-script-msg' ),
956 '&lt;script &gt;alert( &quot;Who put this tag here?&quot; );&lt;/script&gt;',
957 'Tag outside whitelist escaped in parse mode'
958 );
959
960 assert.equal(
961 formatText( 'jquerymsg-script-msg' ),
962 mw.messages.get( 'jquerymsg-script-msg' ),
963 'Tag outside whitelist unchanged in text mode'
964 );
965
966 mw.messages.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
967 assert.htmlEqual(
968 formatParse( 'jquerymsg-script-link-msg' ),
969 '&lt;script&gt;<a title="Foo" href="' + mw.html.escape( mw.util.getUrl( 'Foo' ) ) + '">bar</a>&lt;/script&gt;',
970 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
971 );
972
973 mw.messages.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
974 assert.htmlEqual(
975 formatParse( 'jquerymsg-mismatched-html' ),
976 '&lt;i class=&quot;important&quot;&gt;test&lt;/b&gt;',
977 'Mismatched HTML start and end tag treated as text'
978 );
979
980 mw.messages.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
981 assert.htmlEqual(
982 formatParse( 'jquerymsg-script-and-external-link' ),
983 '&lt;script&gt;alert( "jquerymsg-script-and-external-link test" );&lt;/script&gt; <a href="http://example.com"><i>Foo</i> bar</a>',
984 'HTML tags in external links not interfering with escaping of other tags'
985 );
986
987 mw.messages.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
988 assert.htmlEqual(
989 formatParse( 'jquerymsg-link-script' ),
990 '<a href="http://example.com">&lt;script&gt;alert( "jquerymsg-link-script test" );&lt;/script&gt;</a>',
991 'Non-whitelisted HTML tag in external link anchor treated as text'
992 );
993
994 // Intentionally not using htmlEqual for the quote tests
995 mw.messages.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
996 assert.equal(
997 formatParse( 'jquerymsg-double-quotes-preserved' ),
998 mw.messages.get( 'jquerymsg-double-quotes-preserved' ),
999 'Attributes with double quotes are preserved as such'
1000 );
1001
1002 mw.messages.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
1003 assert.equal(
1004 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
1005 '<i id="single">Single</i>',
1006 'Attributes with single quotes are normalized to double'
1007 );
1008
1009 mw.messages.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:&quot;Arial&quot;">Styled</i>' );
1010 assert.htmlEqual(
1011 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
1012 mw.messages.get( 'jquerymsg-escaped-double-quotes-attribute' ),
1013 'Escaped attributes are parsed correctly'
1014 );
1015
1016 mw.messages.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:&#039;Arial&#039;\'>Styled</i>' );
1017 assert.htmlEqual(
1018 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
1019 mw.messages.get( 'jquerymsg-escaped-single-quotes-attribute' ),
1020 'Escaped attributes are parsed correctly'
1021 );
1022
1023 mw.messages.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
1024 assert.htmlEqual(
1025 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
1026 '<i><a href="http://example.com">Example</a></i>',
1027 'Contents of valid tag are treated as wikitext, so external link is parsed'
1028 );
1029
1030 mw.messages.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
1031 assert.htmlEqual(
1032 formatParse( 'jquerymsg-wikitext-contents-script' ),
1033 '<i>&lt;script&gt;Script inside&lt;/script&gt;</i>',
1034 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
1035 );
1036
1037 mw.messages.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
1038 assert.htmlEqual(
1039 formatParse( 'jquerymsg-unclosed-tag' ),
1040 'Foo&lt;tag&gt;bar',
1041 'Nonsupported unclosed tags are escaped'
1042 );
1043
1044 mw.messages.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
1045 assert.htmlEqual(
1046 formatParse( 'jquerymsg-self-closing-tag' ),
1047 'Foo&lt;tag/&gt;bar',
1048 'Self-closing tags don\'t cause a parse error'
1049 );
1050
1051 mw.messages.set( 'jquerymsg-asciialphabetliteral-regression', '<b >>>="dir">asd</b>' );
1052 assert.htmlEqual(
1053 formatParse( 'jquerymsg-asciialphabetliteral-regression' ),
1054 '<b>&gt;&gt;="dir"&gt;asd</b>',
1055 'Regression test for bad "asciiAlphabetLiteral" definition'
1056 );
1057
1058 mw.messages.set( 'jquerymsg-entities1', 'A&B' );
1059 mw.messages.set( 'jquerymsg-entities2', 'A&gt;B' );
1060 mw.messages.set( 'jquerymsg-entities3', 'A&rarr;B' );
1061 assert.htmlEqual(
1062 formatParse( 'jquerymsg-entities1' ),
1063 'A&amp;B',
1064 'Lone "&" is escaped in text'
1065 );
1066 assert.htmlEqual(
1067 formatParse( 'jquerymsg-entities2' ),
1068 'A&amp;gt;B',
1069 '"&gt;" entity is double-escaped in text' // (WHY?)
1070 );
1071 assert.htmlEqual(
1072 formatParse( 'jquerymsg-entities3' ),
1073 'A&amp;rarr;B',
1074 '"&rarr;" entity is double-escaped in text'
1075 );
1076
1077 mw.messages.set( 'jquerymsg-entities-attr1', '<i title="A&B"></i>' );
1078 mw.messages.set( 'jquerymsg-entities-attr2', '<i title="A&gt;B"></i>' );
1079 mw.messages.set( 'jquerymsg-entities-attr3', '<i title="A&rarr;B"></i>' );
1080 assert.htmlEqual(
1081 formatParse( 'jquerymsg-entities-attr1' ),
1082 '<i title="A&amp;B"></i>',
1083 'Lone "&" is escaped in attribute'
1084 );
1085 assert.htmlEqual(
1086 formatParse( 'jquerymsg-entities-attr2' ),
1087 '<i title="A&gt;B"></i>',
1088 '"&gt;" entity is not double-escaped in attribute' // (WHY?)
1089 );
1090 assert.htmlEqual(
1091 formatParse( 'jquerymsg-entities-attr3' ),
1092 '<i title="A&amp;rarr;B"></i>',
1093 '"&rarr;" entity is double-escaped in attribute'
1094 );
1095 } );
1096
1097 QUnit.test( 'Behavior in case of invalid wikitext', 3, function ( assert ) {
1098 mw.messages.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
1099
1100 this.suppressWarnings();
1101 var logSpy = this.sandbox.spy( mw.log, 'warn' );
1102
1103 assert.equal(
1104 formatParse( 'invalid-wikitext' ),
1105 '&lt;b&gt;{{FAIL}}&lt;/b&gt;',
1106 'Invalid wikitext: \'parse\' format'
1107 );
1108
1109 assert.equal(
1110 formatText( 'invalid-wikitext' ),
1111 '<b>{{FAIL}}</b>',
1112 'Invalid wikitext: \'text\' format'
1113 );
1114
1115 assert.equal( logSpy.callCount, 2, 'mw.log.warn calls' );
1116 } );
1117
1118 QUnit.test( 'Integration', 5, function ( assert ) {
1119 var expected, logSpy, msg;
1120
1121 expected = '<b><a title="Bold" href="/wiki/Bold">Bold</a>!</b>';
1122 mw.messages.set( 'integration-test', '<b>[[Bold]]!</b>' );
1123
1124 this.suppressWarnings();
1125 logSpy = this.sandbox.spy( mw.log, 'warn' );
1126 assert.equal(
1127 window.gM( 'integration-test' ),
1128 expected,
1129 'Global function gM() works correctly'
1130 );
1131 assert.equal( logSpy.callCount, 1, 'mw.log.warn called' );
1132 this.restoreWarnings();
1133
1134 assert.equal(
1135 mw.message( 'integration-test' ).parse(),
1136 expected,
1137 'mw.message().parse() works correctly'
1138 );
1139
1140 assert.equal(
1141 $( '<span>' ).msg( 'integration-test' ).html(),
1142 expected,
1143 'jQuery plugin $.fn.msg() works correctly'
1144 );
1145
1146 mw.messages.set( 'integration-test-extlink', '[$1 Link]' );
1147 msg = mw.message(
1148 'integration-test-extlink',
1149 $( '<a>' ).attr( 'href', 'http://example.com/' )
1150 );
1151 msg.parse(); // Not a no-op
1152 assert.equal(
1153 msg.parse(),
1154 '<a href="http://example.com/">Link</a>',
1155 'Calling .parse() multiple times does not duplicate link contents'
1156 );
1157 } );
1158
1159 }( mediaWiki, jQuery ) );