2 var mwLanguageCache = {}, formatText, formatParse, formatnumTests, specialCharactersPageName,
3 expectedListUsers, expectedEntrypoints;
5 // When the expected result is the same in both modes
6 function assertBothModes( assert, parserArguments, expectedResult, assertMessage ) {
7 assert.equal( formatText.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'text\'' );
8 assert.equal( formatParse.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'parse\'' );
11 QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( {
13 this.originalMwLanguage = mw.language;
15 specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
17 expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
19 expectedEntrypoints = '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
21 formatText = mw.jqueryMsg.getMessageFunction( {
25 formatParse = mw.jqueryMsg.getMessageFunction( {
29 teardown: function () {
30 mw.language = this.originalMwLanguage;
33 wgArticlePath: '/wiki/$1'
35 // Messages that are reused in multiple tests
37 // The values for gender are not significant,
38 // what matters is which of the values is choosen by the parser
39 'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
40 'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
42 'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
44 // Assume the grammar form grammar_case_foo is not valid in any language
45 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
47 'formatnum-msg': '{{formatnum:$1}}',
49 'portal-url': 'Project:Community portal',
50 'see-portal-url': '{{Int:portal-url}} is an important community page.',
52 'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
54 'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
56 'external-link-replace': 'Foo [$1 bar]'
60 function getMwLanguage( langCode, cb ) {
61 if ( mwLanguageCache[langCode] !== undefined ) {
62 mwLanguageCache[langCode].add( cb );
65 mwLanguageCache[langCode] = $.Callbacks( 'once memory' );
66 mwLanguageCache[langCode].add( cb );
68 url: mw.util.wikiScript( 'load' ),
70 skin: mw.config.get( 'skin' ),
72 debug: mw.config.get( 'debug' ),
74 'mediawiki.language.data',
80 } ).done(function () {
81 mwLanguageCache[langCode].fire( mw.language );
82 } ).fail( function () {
83 mwLanguageCache[langCode].fire( false );
87 QUnit.test( 'Replace', 9, function ( assert ) {
88 mw.messages.set( 'simple', 'Foo $1 baz $2' );
90 assert.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
91 assert.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
92 assert.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
94 mw.messages.set( 'plain-input', '<foo foo="foo">x$1y<</foo>z' );
97 formatParse( 'plain-input', 'bar' ),
98 '<foo foo="foo">xbary&lt;</foo>z',
99 'Input is not considered html'
102 mw.messages.set( 'plain-replace', 'Foo $1' );
105 formatParse( 'plain-replace', '<bar bar="bar">></bar>' ),
106 'Foo <bar bar="bar">&gt;</bar>',
107 'Replacement is not considered html'
110 mw.messages.set( 'object-replace', 'Foo $1' );
113 formatParse( 'object-replace', $( '<div class="bar">></div>' ) ),
114 'Foo <div class="bar">></div>',
115 'jQuery objects are preserved as raw html'
119 formatParse( 'object-replace', $( '<div class="bar">></div>' ).get( 0 ) ),
120 'Foo <div class="bar">></div>',
121 'HTMLElement objects are preserved as raw html'
125 formatParse( 'object-replace', $( '<div class="bar">></div>' ).toArray() ),
126 'Foo <div class="bar">></div>',
127 'HTMLElement[] arrays are preserved as raw html'
131 formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
132 'Foo <a href="http://example.org/?x=y&z">bar</a>',
133 'Href is not double-escaped in wikilink function'
137 QUnit.test( 'Plural', 3, function ( assert ) {
138 assert.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
139 assert.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
140 assert.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
143 QUnit.test( 'Gender', 15, function ( assert ) {
144 var originalGender = mw.user.options.get( 'gender' );
146 // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
147 // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
148 mw.user.options.set( 'gender', 'male' );
150 formatParse( 'gender-msg', 'Bob', 'male' ),
152 'Masculine from string "male"'
155 formatParse( 'gender-msg', 'Bob', mw.user ),
157 'Masculine from mw.user object'
160 formatParse( 'gender-msg-currentuser' ),
162 'Masculine for current user'
165 mw.user.options.set( 'gender', 'female' );
167 formatParse( 'gender-msg', 'Alice', 'female' ),
169 'Feminine from string "female"' );
171 formatParse( 'gender-msg', 'Alice', mw.user ),
173 'Feminine from mw.user object'
176 formatParse( 'gender-msg-currentuser' ),
178 'Feminine for current user'
181 mw.user.options.set( 'gender', 'unknown' );
183 formatParse( 'gender-msg', 'Foo', mw.user ),
185 'Neutral from mw.user object' );
187 formatParse( 'gender-msg', 'User' ),
189 'Neutral when no parameter given' );
191 formatParse( 'gender-msg', 'User', 'unknown' ),
193 'Neutral from string "unknown"'
196 formatParse( 'gender-msg-currentuser' ),
198 'Neutral for current user'
201 mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
204 formatParse( 'gender-msg-one-form', 'male', 10 ),
206 'Gender neutral and plural form'
209 formatParse( 'gender-msg-one-form', 'female', 1 ),
211 'Gender neutral and singular form'
214 mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
216 formatParse( 'gender-msg-lowercase', 'male' ),
221 formatParse( 'gender-msg-lowercase', 'female' ),
226 mw.messages.set( 'gender-msg-wrong', '{{gender}} test' );
228 formatParse( 'gender-msg-wrong', 'female' ),
230 'Invalid syntax should result in {{gender}} simply being stripped away'
233 mw.user.options.set( 'gender', originalGender );
236 QUnit.test( 'Grammar', 2, function ( assert ) {
237 assert.equal( formatParse( 'grammar-msg' ), 'Przeszukaj ' + mw.config.get( 'wgSiteName' ), 'Grammar Test with sitename' );
239 mw.messages.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
240 assert.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
243 QUnit.test( 'Match PHP parser', mw.libs.phpParserData.tests.length, function ( assert ) {
244 mw.messages.set( mw.libs.phpParserData.messages );
245 $.each( mw.libs.phpParserData.tests, function ( i, test ) {
247 getMwLanguage( test.lang, function ( langClass ) {
250 assert.ok( false, 'Language "' + test.lang + '" failed to load' );
253 mw.config.set( 'wgUserLanguage', test.lang );
254 var parser = new mw.jqueryMsg.parser( { language: langClass } );
256 parser.parse( test.key, test.args ).html(),
264 QUnit.test( 'Links', 6, function ( assert ) {
265 var expectedDisambiguationsText,
266 expectedMultipleBars,
267 expectedSpecialCharacters;
269 // The below three are all identical to or based on real messages. For disambiguations-text,
270 // the bold was removed because it is not yet implemented.
273 formatParse( 'jquerymsg-test-statistics-users' ),
278 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 ' +
279 '<a title="MediaWiki:Disambiguationspage" href="/wiki/MediaWiki:Disambiguationspage">MediaWiki:Disambiguationspage</a>.';
281 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]].' );
283 formatParse( 'disambiguations-text' ),
284 expectedDisambiguationsText,
285 'Wikilink without pipe'
289 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
294 // Pipe trick is not supported currently, but should not parse as text either.
295 mw.messages.set( 'pipe-trick', '[[Tampa, Florida|]]' );
296 this.suppressWarnings();
298 formatParse( 'pipe-trick' ),
299 '[[Tampa, Florida|]]',
300 'Pipe trick should not be parsed.'
302 this.restoreWarnings();
304 expectedMultipleBars = '<a title="Main Page" href="/wiki/Main_Page">Main|Page</a>';
305 mw.messages.set( 'multiple-bars', '[[Main Page|Main|Page]]' );
307 formatParse( 'multiple-bars' ),
308 expectedMultipleBars,
312 expectedSpecialCharacters = '<a title=""Who" wants to be a millionaire & live on 'Exotic Island'?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_%27Exotic_Island%27%3F">"Who" wants to be a millionaire & live on 'Exotic Island'?</a>';
314 mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' );
316 formatParse( 'special-characters' ),
317 expectedSpecialCharacters,
322 // Tests that {{-transformation vs. general parsing are done as requested
323 QUnit.test( 'Curly brace transformation', 14, function ( assert ) {
324 var oldUserLang = mw.config.get( 'wgUserLanguage' );
326 assertBothModes( assert, ['gender-msg', 'Bob', 'male'], 'Bob: blue', 'gender is resolved' );
328 assertBothModes( assert, ['plural-msg', 5], 'Found 5 items', 'plural is resolved' );
330 assertBothModes( assert, ['grammar-msg'], 'Przeszukaj ' + mw.config.get( 'wgSiteName' ), 'grammar is resolved' );
332 mw.config.set( 'wgUserLanguage', 'en' );
333 assertBothModes( assert, ['formatnum-msg', '987654321.654321'], '987,654,321.654', 'formatnum is resolved' );
335 // Test non-{{ wikitext, where behavior differs
339 formatText( 'jquerymsg-test-statistics-users' ),
340 mw.messages.get( 'jquerymsg-test-statistics-users' ),
341 'Internal link message unchanged when format is \'text\''
344 formatParse( 'jquerymsg-test-statistics-users' ),
346 'Internal link message parsed when format is \'parse\''
351 formatText( 'jquerymsg-test-version-entrypoints-index-php' ),
352 mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ),
353 'External link message unchanged when format is \'text\''
356 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
358 'External link message processed when format is \'parse\''
361 // External link with parameter
363 formatText( 'external-link-replace', 'http://example.com' ),
364 'Foo [http://example.com bar]',
365 'External link message only substitutes parameter when format is \'text\''
368 formatParse( 'external-link-replace', 'http://example.com' ),
369 'Foo <a href="http://example.com">bar</a>',
370 'External link message processed when format is \'parse\''
373 mw.config.set( 'wgUserLanguage', oldUserLang );
376 QUnit.test( 'Int', 4, function ( assert ) {
377 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.',
378 expectedNewarticletext,
379 helpPageTitle = 'Help:Foobar';
381 mw.messages.set( 'foobar', helpPageTitle );
383 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 ' +
384 '<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.';
386 mw.messages.set( 'newarticletext', newarticletextSource );
389 formatParse( 'newarticletext' ),
390 expectedNewarticletext,
391 'Link with nested message'
395 formatParse( 'see-portal-url' ),
396 'Project:Community portal is an important community page.',
400 mw.messages.set( 'newarticletext-lowercase',
401 newarticletextSource.replace( 'Int:Helppage', 'int:helppage' ) );
404 formatParse( 'newarticletext-lowercase' ),
405 expectedNewarticletext,
406 'Link with nested message, lowercase include'
409 mw.messages.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
412 formatParse( 'uses-missing-int' ),
414 'int: where nested message does not exist'
418 // Tests that getMessageFunction is used for non-plain messages with curly braces or
419 // square brackets, but not otherwise.
420 QUnit.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert ) {
421 var oldGMF, outerCalled, innerCalled;
424 'curly-brace': '{{int:message}}',
425 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
426 'double-square-bracket': '[[Some page]]',
427 'regular': 'Other message'
430 oldGMF = mw.jqueryMsg.getMessageFunction;
432 mw.jqueryMsg.getMessageFunction = function () {
439 function verifyGetMessageFunction( key, format, shouldCall ) {
443 message = mw.message( key );
445 assert.strictEqual( outerCalled, shouldCall, 'Outer function called for ' + key );
446 assert.strictEqual( innerCalled, shouldCall, 'Inner function called for ' + key );
449 verifyGetMessageFunction( 'curly-brace', 'parse', true );
450 verifyGetMessageFunction( 'curly-brace', 'plain', false );
452 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
453 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
455 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
456 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
458 verifyGetMessageFunction( 'regular', 'parse', false );
459 verifyGetMessageFunction( 'regular', 'plain', false );
461 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
462 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
463 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
465 mw.jqueryMsg.getMessageFunction = oldGMF;
471 number: 987654321.654321,
472 result: '987,654,321.654',
473 description: 'formatnum test for English, decimal seperator'
477 number: 987654321.654321,
478 result: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
479 description: 'formatnum test for Arabic, with decimal seperator'
483 number: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
486 description: 'formatnum test for Arabic, with decimal seperator, reverse'
492 description: 'formatnum test for Arabic, negative number'
499 description: 'formatnum test for Arabic, negative number, reverse'
503 number: 987654321.654321,
504 result: '987.654.321,654',
505 description: 'formatnum test for Nederlands, decimal seperator'
511 description: 'formatnum test for Nederlands, negative number'
517 description: 'formatnum test for Nederlands'
521 number: 'invalidnumber',
522 result: 'invalidnumber',
523 description: 'formatnum test for Nederlands, invalid number'
527 number: '1000000000',
528 result: '1,00,00,00,000',
529 description: 'formatnum test for Malayalam'
533 number: '-1000000000',
534 result: '-1,00,00,00,000',
535 description: 'formatnum test for Malayalam, negative number'
538 * This will fail because of wrong pattern for ml in MW(different from CLDR)
541 number: '1000000000.000',
542 result: '1,00,00,00,000.000',
543 description: 'formatnum test for Malayalam with decimal place'
548 number: '123456789.123456789',
549 result: '१२,३४,५६,७८९',
550 description: 'formatnum test for Hindi'
554 number: '१२,३४,५६,७८९',
555 result: '१२,३४,५६,७८९',
556 description: 'formatnum test for Hindi, Devanagari digits passed'
560 number: '१२३४५६,७८९',
563 description: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
567 QUnit.test( 'formatnum', formatnumTests.length, function ( assert ) {
568 mw.messages.set( 'formatnum-msg', '{{formatnum:$1}}' );
569 mw.messages.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
570 $.each( formatnumTests, function ( i, test ) {
572 getMwLanguage( test.lang, function ( langClass ) {
575 assert.ok( false, 'Language "' + test.lang + '" failed to load' );
578 mw.messages.set(test.message );
579 mw.config.set( 'wgUserLanguage', test.lang );
580 var parser = new mw.jqueryMsg.parser( { language: langClass } );
582 parser.parse( test.integer ? 'formatnum-msg-int' : 'formatnum-msg',
583 [ test.number ] ).html(),
592 QUnit.test( 'HTML', 26, function ( assert ) {
593 mw.messages.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
595 assertBothModes( assert, ['jquerymsg-italics-msg'], mw.messages.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
597 mw.messages.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
598 assertBothModes( assert, ['jquerymsg-bold-msg'], mw.messages.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
600 mw.messages.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
601 assertBothModes( assert, ['jquerymsg-bold-italics-msg'], mw.messages.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
603 mw.messages.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
604 assertBothModes( assert, ['jquerymsg-italics-bold-msg'], mw.messages.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
606 mw.messages.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
609 formatParse( 'jquerymsg-italics-with-link' ),
610 'An <i>italicized <a title="link" href="' + mw.html.escape( mw.util.getUrl( 'link' ) ) + '">wiki-link</i>',
611 'Italics with link inside in parse mode'
615 formatText( 'jquerymsg-italics-with-link' ),
616 mw.messages.get( 'jquerymsg-italics-with-link' ),
617 'Italics with link unchanged in text mode'
620 mw.messages.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
622 formatParse( 'jquerymsg-italics-id-class' ),
623 mw.messages.get( 'jquerymsg-italics-id-class' ),
624 'ID and class are allowed'
627 mw.messages.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
629 formatParse( 'jquerymsg-italics-onclick' ),
630 '<i onclick="alert(\'foo\')">Foo</i>',
631 'element with onclick is escaped because it is not allowed'
634 mw.messages.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
636 formatParse( 'jquerymsg-script-msg' ),
637 '<script >alert( "Who put this tag here?" );</script>',
638 'Tag outside whitelist escaped in parse mode'
642 formatText( 'jquerymsg-script-msg' ),
643 mw.messages.get( 'jquerymsg-script-msg' ),
644 'Tag outside whitelist unchanged in text mode'
647 mw.messages.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
649 formatParse( 'jquerymsg-script-link-msg' ),
650 '<script><a title="Foo" href="' + mw.html.escape( mw.util.getUrl( 'Foo' ) ) + '">bar</a></script>',
651 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
654 mw.messages.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
656 formatParse( 'jquerymsg-mismatched-html' ),
657 '<i class="important">test</b>',
658 'Mismatched HTML start and end tag treated as text'
661 // TODO (mattflaschen, 2013-03-18): It's not a security issue, but there's no real
662 // reason the htmlEmitter span needs to be here. It's an artifact of how emitting works.
663 mw.messages.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
665 formatParse( 'jquerymsg-script-and-external-link' ),
666 '<script>alert( "jquerymsg-script-and-external-link test" );</script> <a href="http://example.com"><span class="mediaWiki_htmlEmitter"><i>Foo</i> bar</span></a>',
667 'HTML tags in external links not interfering with escaping of other tags'
670 mw.messages.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
672 formatParse( 'jquerymsg-link-script' ),
673 '<a href="http://example.com"><span class="mediaWiki_htmlEmitter"><script>alert( "jquerymsg-link-script test" );</script></span></a>',
674 'Non-whitelisted HTML tag in external link anchor treated as text'
677 // Intentionally not using htmlEqual for the quote tests
678 mw.messages.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
680 formatParse( 'jquerymsg-double-quotes-preserved' ),
681 mw.messages.get( 'jquerymsg-double-quotes-preserved' ),
682 'Attributes with double quotes are preserved as such'
685 mw.messages.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
687 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
688 '<i id="single">Single</i>',
689 'Attributes with single quotes are normalized to double'
692 mw.messages.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:"Arial"">Styled</i>' );
694 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
695 mw.messages.get( 'jquerymsg-escaped-double-quotes-attribute' ),
696 'Escaped attributes are parsed correctly'
699 mw.messages.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:'Arial'\'>Styled</i>' );
701 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
702 mw.messages.get( 'jquerymsg-escaped-single-quotes-attribute' ),
703 'Escaped attributes are parsed correctly'
706 mw.messages.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
708 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
709 '<i><a href="http://example.com">Example</a></i>',
710 'Contents of valid tag are treated as wikitext, so external link is parsed'
713 mw.messages.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
715 formatParse( 'jquerymsg-wikitext-contents-script' ),
716 '<i><span class="mediaWiki_htmlEmitter"><script>Script inside</script></span></i>',
717 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
720 mw.messages.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
722 formatParse( 'jquerymsg-unclosed-tag' ),
724 'Nonsupported unclosed tags are escaped'
727 mw.messages.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
729 formatParse( 'jquerymsg-self-closing-tag' ),
730 'Foo<tag/>bar',
731 'Self-closing tags don\'t cause a parse error'
735 QUnit.test( 'Behavior in case of invalid wikitext', 3, function ( assert ) {
736 mw.messages.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
738 this.suppressWarnings();
739 var logSpy = this.sandbox.spy( mw.log, 'warn' );
742 formatParse( 'invalid-wikitext' ),
743 '<b>{{FAIL}}</b>',
744 'Invalid wikitext: \'parse\' format'
748 formatText( 'invalid-wikitext' ),
750 'Invalid wikitext: \'text\' format'
753 assert.equal( logSpy.callCount, 2, 'mw.log.warn calls' );
756 }( mediaWiki, jQuery ) );