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}}',
43 // See https://bugzilla.wikimedia.org/69993
44 'plural-msg-explicit-forms-nested': 'Found {{PLURAL:$1|$1 results|0=no results in {{SITENAME}}|1=$1 result}}',
45 // Assume the grammar form grammar_case_foo is not valid in any language
46 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
48 'formatnum-msg': '{{formatnum:$1}}',
50 'portal-url': 'Project:Community portal',
51 'see-portal-url': '{{Int:portal-url}} is an important community page.',
53 'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
55 'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
57 'external-link-replace': 'Foo [$1 bar]'
61 function getMwLanguage( langCode
, cb
) {
62 if ( mwLanguageCache
[langCode
] !== undefined ) {
63 mwLanguageCache
[langCode
].add( cb
);
66 mwLanguageCache
[langCode
] = $.Callbacks( 'once memory' );
67 mwLanguageCache
[langCode
].add( cb
);
69 url
: mw
.util
.wikiScript( 'load' ),
71 skin
: mw
.config
.get( 'skin' ),
73 debug
: mw
.config
.get( 'debug' ),
75 'mediawiki.language.data',
81 } ).done(function () {
82 mwLanguageCache
[langCode
].fire( mw
.language
);
83 } ).fail( function () {
84 mwLanguageCache
[langCode
].fire( false );
88 QUnit
.test( 'Replace', 9, function ( assert
) {
89 mw
.messages
.set( 'simple', 'Foo $1 baz $2' );
91 assert
.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
92 assert
.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
93 assert
.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
95 mw
.messages
.set( 'plain-input', '<foo foo="foo">x$1y<</foo>z' );
98 formatParse( 'plain-input', 'bar' ),
99 '<foo foo="foo">xbary&lt;</foo>z',
100 'Input is not considered html'
103 mw
.messages
.set( 'plain-replace', 'Foo $1' );
106 formatParse( 'plain-replace', '<bar bar="bar">></bar>' ),
107 'Foo <bar bar="bar">&gt;</bar>',
108 'Replacement is not considered html'
111 mw
.messages
.set( 'object-replace', 'Foo $1' );
114 formatParse( 'object-replace', $( '<div class="bar">></div>' ) ),
115 'Foo <div class="bar">></div>',
116 'jQuery objects are preserved as raw html'
120 formatParse( 'object-replace', $( '<div class="bar">></div>' ).get( 0 ) ),
121 'Foo <div class="bar">></div>',
122 'HTMLElement objects are preserved as raw html'
126 formatParse( 'object-replace', $( '<div class="bar">></div>' ).toArray() ),
127 'Foo <div class="bar">></div>',
128 'HTMLElement[] arrays are preserved as raw html'
132 formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
133 'Foo <a href="http://example.org/?x=y&z">bar</a>',
134 'Href is not double-escaped in wikilink function'
138 QUnit
.test( 'Plural', 6, function ( assert
) {
139 assert
.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
140 assert
.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
141 assert
.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
142 assert
.equal( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
143 assert
.equal( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in ' + mw
.config
.get( 'wgSiteName' ), 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
144 assert
.equal( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
147 QUnit
.test( 'Gender', 15, function ( assert
) {
148 var originalGender
= mw
.user
.options
.get( 'gender' );
150 // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
151 // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
152 mw
.user
.options
.set( 'gender', 'male' );
154 formatParse( 'gender-msg', 'Bob', 'male' ),
156 'Masculine from string "male"'
159 formatParse( 'gender-msg', 'Bob', mw
.user
),
161 'Masculine from mw.user object'
164 formatParse( 'gender-msg-currentuser' ),
166 'Masculine for current user'
169 mw
.user
.options
.set( 'gender', 'female' );
171 formatParse( 'gender-msg', 'Alice', 'female' ),
173 'Feminine from string "female"' );
175 formatParse( 'gender-msg', 'Alice', mw
.user
),
177 'Feminine from mw.user object'
180 formatParse( 'gender-msg-currentuser' ),
182 'Feminine for current user'
185 mw
.user
.options
.set( 'gender', 'unknown' );
187 formatParse( 'gender-msg', 'Foo', mw
.user
),
189 'Neutral from mw.user object' );
191 formatParse( 'gender-msg', 'User' ),
193 'Neutral when no parameter given' );
195 formatParse( 'gender-msg', 'User', 'unknown' ),
197 'Neutral from string "unknown"'
200 formatParse( 'gender-msg-currentuser' ),
202 'Neutral for current user'
205 mw
.messages
.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
208 formatParse( 'gender-msg-one-form', 'male', 10 ),
210 'Gender neutral and plural form'
213 formatParse( 'gender-msg-one-form', 'female', 1 ),
215 'Gender neutral and singular form'
218 mw
.messages
.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
220 formatParse( 'gender-msg-lowercase', 'male' ),
225 formatParse( 'gender-msg-lowercase', 'female' ),
230 mw
.messages
.set( 'gender-msg-wrong', '{{gender}} test' );
232 formatParse( 'gender-msg-wrong', 'female' ),
234 'Invalid syntax should result in {{gender}} simply being stripped away'
237 mw
.user
.options
.set( 'gender', originalGender
);
240 QUnit
.test( 'Grammar', 2, function ( assert
) {
241 assert
.equal( formatParse( 'grammar-msg' ), 'Przeszukaj ' + mw
.config
.get( 'wgSiteName' ), 'Grammar Test with sitename' );
243 mw
.messages
.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
244 assert
.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
247 QUnit
.test( 'Match PHP parser', mw
.libs
.phpParserData
.tests
.length
, function ( assert
) {
248 mw
.messages
.set( mw
.libs
.phpParserData
.messages
);
249 $.each( mw
.libs
.phpParserData
.tests
, function ( i
, test
) {
251 getMwLanguage( test
.lang
, function ( langClass
) {
254 assert
.ok( false, 'Language "' + test
.lang
+ '" failed to load' );
257 mw
.config
.set( 'wgUserLanguage', test
.lang
);
258 var parser
= new mw
.jqueryMsg
.parser( { language
: langClass
} );
260 parser
.parse( test
.key
, test
.args
).html(),
268 QUnit
.test( 'Links', 6, function ( assert
) {
269 var expectedDisambiguationsText
,
270 expectedMultipleBars
,
271 expectedSpecialCharacters
;
273 // The below three are all identical to or based on real messages. For disambiguations-text,
274 // the bold was removed because it is not yet implemented.
277 formatParse( 'jquerymsg-test-statistics-users' ),
282 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 ' +
283 '<a title="MediaWiki:Disambiguationspage" href="/wiki/MediaWiki:Disambiguationspage">MediaWiki:Disambiguationspage</a>.';
285 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]].' );
287 formatParse( 'disambiguations-text' ),
288 expectedDisambiguationsText
,
289 'Wikilink without pipe'
293 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
298 // Pipe trick is not supported currently, but should not parse as text either.
299 mw
.messages
.set( 'pipe-trick', '[[Tampa, Florida|]]' );
300 this.suppressWarnings();
302 formatParse( 'pipe-trick' ),
303 '[[Tampa, Florida|]]',
304 'Pipe trick should not be parsed.'
306 this.restoreWarnings();
308 expectedMultipleBars
= '<a title="Main Page" href="/wiki/Main_Page">Main|Page</a>';
309 mw
.messages
.set( 'multiple-bars', '[[Main Page|Main|Page]]' );
311 formatParse( 'multiple-bars' ),
312 expectedMultipleBars
,
316 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>';
318 mw
.messages
.set( 'special-characters', '[[' + specialCharactersPageName
+ ']]' );
320 formatParse( 'special-characters' ),
321 expectedSpecialCharacters
,
326 // Tests that {{-transformation vs. general parsing are done as requested
327 QUnit
.test( 'Curly brace transformation', 16, function ( assert
) {
328 var oldUserLang
= mw
.config
.get( 'wgUserLanguage' );
330 assertBothModes( assert
, ['gender-msg', 'Bob', 'male'], 'Bob: blue', 'gender is resolved' );
332 assertBothModes( assert
, ['plural-msg', 5], 'Found 5 items', 'plural is resolved' );
334 assertBothModes( assert
, ['grammar-msg'], 'Przeszukaj ' + mw
.config
.get( 'wgSiteName' ), 'grammar is resolved' );
336 mw
.config
.set( 'wgUserLanguage', 'en' );
337 assertBothModes( assert
, ['formatnum-msg', '987654321.654321'], '987,654,321.654', 'formatnum is resolved' );
339 // Test non-{{ wikitext, where behavior differs
343 formatText( 'jquerymsg-test-statistics-users' ),
344 mw
.messages
.get( 'jquerymsg-test-statistics-users' ),
345 'Internal link message unchanged when format is \'text\''
348 formatParse( 'jquerymsg-test-statistics-users' ),
350 'Internal link message parsed when format is \'parse\''
355 formatText( 'jquerymsg-test-version-entrypoints-index-php' ),
356 mw
.messages
.get( 'jquerymsg-test-version-entrypoints-index-php' ),
357 'External link message unchanged when format is \'text\''
360 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
362 'External link message processed when format is \'parse\''
365 // External link with parameter
367 formatText( 'external-link-replace', 'http://example.com' ),
368 'Foo [http://example.com bar]',
369 'External link message only substitutes parameter when format is \'text\''
372 formatParse( 'external-link-replace', 'http://example.com' ),
373 'Foo <a href="http://example.com">bar</a>',
374 'External link message processed when format is \'parse\''
377 formatParse( 'external-link-replace', $( '<i>' ) ),
379 'External link message processed as jQuery object when format is \'parse\''
382 formatParse( 'external-link-replace', function () {} ),
383 'Foo <a href="#">bar</a>',
384 'External link message processed as function when format is \'parse\''
387 mw
.config
.set( 'wgUserLanguage', oldUserLang
);
390 QUnit
.test( 'Int', 4, function ( assert
) {
391 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.',
392 expectedNewarticletext
,
393 helpPageTitle
= 'Help:Foobar';
395 mw
.messages
.set( 'foobar', helpPageTitle
);
397 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 ' +
398 '<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.';
400 mw
.messages
.set( 'newarticletext', newarticletextSource
);
403 formatParse( 'newarticletext' ),
404 expectedNewarticletext
,
405 'Link with nested message'
409 formatParse( 'see-portal-url' ),
410 'Project:Community portal is an important community page.',
414 mw
.messages
.set( 'newarticletext-lowercase',
415 newarticletextSource
.replace( 'Int:Helppage', 'int:helppage' ) );
418 formatParse( 'newarticletext-lowercase' ),
419 expectedNewarticletext
,
420 'Link with nested message, lowercase include'
423 mw
.messages
.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
426 formatParse( 'uses-missing-int' ),
428 'int: where nested message does not exist'
432 // Tests that getMessageFunction is used for non-plain messages with curly braces or
433 // square brackets, but not otherwise.
434 QUnit
.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert
) {
435 var oldGMF
, outerCalled
, innerCalled
;
438 'curly-brace': '{{int:message}}',
439 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
440 'double-square-bracket': '[[Some page]]',
441 'regular': 'Other message'
444 oldGMF
= mw
.jqueryMsg
.getMessageFunction
;
446 mw
.jqueryMsg
.getMessageFunction = function () {
453 function verifyGetMessageFunction( key
, format
, shouldCall
) {
457 message
= mw
.message( key
);
459 assert
.strictEqual( outerCalled
, shouldCall
, 'Outer function called for ' + key
);
460 assert
.strictEqual( innerCalled
, shouldCall
, 'Inner function called for ' + key
);
463 verifyGetMessageFunction( 'curly-brace', 'parse', true );
464 verifyGetMessageFunction( 'curly-brace', 'plain', false );
466 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
467 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
469 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
470 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
472 verifyGetMessageFunction( 'regular', 'parse', false );
473 verifyGetMessageFunction( 'regular', 'plain', false );
475 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
476 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
477 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
479 mw
.jqueryMsg
.getMessageFunction
= oldGMF
;
485 number
: 987654321.654321,
486 result
: '987,654,321.654',
487 description
: 'formatnum test for English, decimal seperator'
491 number
: 987654321.654321,
492 result
: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
493 description
: 'formatnum test for Arabic, with decimal seperator'
497 number
: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
500 description
: 'formatnum test for Arabic, with decimal seperator, reverse'
506 description
: 'formatnum test for Arabic, negative number'
513 description
: 'formatnum test for Arabic, negative number, reverse'
517 number
: 987654321.654321,
518 result
: '987.654.321,654',
519 description
: 'formatnum test for Nederlands, decimal seperator'
525 description
: 'formatnum test for Nederlands, negative number'
531 description
: 'formatnum test for Nederlands'
535 number
: 'invalidnumber',
536 result
: 'invalidnumber',
537 description
: 'formatnum test for Nederlands, invalid number'
541 number
: '1000000000',
542 result
: '1,00,00,00,000',
543 description
: 'formatnum test for Malayalam'
547 number
: '-1000000000',
548 result
: '-1,00,00,00,000',
549 description
: 'formatnum test for Malayalam, negative number'
552 * This will fail because of wrong pattern for ml in MW(different from CLDR)
555 number: '1000000000.000',
556 result: '1,00,00,00,000.000',
557 description: 'formatnum test for Malayalam with decimal place'
562 number
: '123456789.123456789',
563 result
: '१२,३४,५६,७८९',
564 description
: 'formatnum test for Hindi'
568 number
: '१२,३४,५६,७८९',
569 result
: '१२,३४,५६,७८९',
570 description
: 'formatnum test for Hindi, Devanagari digits passed'
574 number
: '१२३४५६,७८९',
577 description
: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
581 QUnit
.test( 'formatnum', formatnumTests
.length
, function ( assert
) {
582 mw
.messages
.set( 'formatnum-msg', '{{formatnum:$1}}' );
583 mw
.messages
.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
584 $.each( formatnumTests
, function ( i
, test
) {
586 getMwLanguage( test
.lang
, function ( langClass
) {
589 assert
.ok( false, 'Language "' + test
.lang
+ '" failed to load' );
592 mw
.messages
.set(test
.message
);
593 mw
.config
.set( 'wgUserLanguage', test
.lang
);
594 var parser
= new mw
.jqueryMsg
.parser( { language
: langClass
} );
596 parser
.parse( test
.integer
? 'formatnum-msg-int' : 'formatnum-msg',
597 [ test
.number
] ).html(),
606 QUnit
.test( 'HTML', 26, function ( assert
) {
607 mw
.messages
.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
609 assertBothModes( assert
, ['jquerymsg-italics-msg'], mw
.messages
.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
611 mw
.messages
.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
612 assertBothModes( assert
, ['jquerymsg-bold-msg'], mw
.messages
.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
614 mw
.messages
.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
615 assertBothModes( assert
, ['jquerymsg-bold-italics-msg'], mw
.messages
.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
617 mw
.messages
.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
618 assertBothModes( assert
, ['jquerymsg-italics-bold-msg'], mw
.messages
.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
620 mw
.messages
.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
623 formatParse( 'jquerymsg-italics-with-link' ),
624 'An <i>italicized <a title="link" href="' + mw
.html
.escape( mw
.util
.getUrl( 'link' ) ) + '">wiki-link</i>',
625 'Italics with link inside in parse mode'
629 formatText( 'jquerymsg-italics-with-link' ),
630 mw
.messages
.get( 'jquerymsg-italics-with-link' ),
631 'Italics with link unchanged in text mode'
634 mw
.messages
.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
636 formatParse( 'jquerymsg-italics-id-class' ),
637 mw
.messages
.get( 'jquerymsg-italics-id-class' ),
638 'ID and class are allowed'
641 mw
.messages
.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
643 formatParse( 'jquerymsg-italics-onclick' ),
644 '<i onclick="alert(\'foo\')">Foo</i>',
645 'element with onclick is escaped because it is not allowed'
648 mw
.messages
.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
650 formatParse( 'jquerymsg-script-msg' ),
651 '<script >alert( "Who put this tag here?" );</script>',
652 'Tag outside whitelist escaped in parse mode'
656 formatText( 'jquerymsg-script-msg' ),
657 mw
.messages
.get( 'jquerymsg-script-msg' ),
658 'Tag outside whitelist unchanged in text mode'
661 mw
.messages
.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
663 formatParse( 'jquerymsg-script-link-msg' ),
664 '<script><a title="Foo" href="' + mw
.html
.escape( mw
.util
.getUrl( 'Foo' ) ) + '">bar</a></script>',
665 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
668 mw
.messages
.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
670 formatParse( 'jquerymsg-mismatched-html' ),
671 '<i class="important">test</b>',
672 'Mismatched HTML start and end tag treated as text'
675 // TODO (mattflaschen, 2013-03-18): It's not a security issue, but there's no real
676 // reason the htmlEmitter span needs to be here. It's an artifact of how emitting works.
677 mw
.messages
.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
679 formatParse( 'jquerymsg-script-and-external-link' ),
680 '<script>alert( "jquerymsg-script-and-external-link test" );</script> <a href="http://example.com"><span class="mediaWiki_htmlEmitter"><i>Foo</i> bar</span></a>',
681 'HTML tags in external links not interfering with escaping of other tags'
684 mw
.messages
.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
686 formatParse( 'jquerymsg-link-script' ),
687 '<a href="http://example.com"><span class="mediaWiki_htmlEmitter"><script>alert( "jquerymsg-link-script test" );</script></span></a>',
688 'Non-whitelisted HTML tag in external link anchor treated as text'
691 // Intentionally not using htmlEqual for the quote tests
692 mw
.messages
.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
694 formatParse( 'jquerymsg-double-quotes-preserved' ),
695 mw
.messages
.get( 'jquerymsg-double-quotes-preserved' ),
696 'Attributes with double quotes are preserved as such'
699 mw
.messages
.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
701 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
702 '<i id="single">Single</i>',
703 'Attributes with single quotes are normalized to double'
706 mw
.messages
.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:"Arial"">Styled</i>' );
708 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
709 mw
.messages
.get( 'jquerymsg-escaped-double-quotes-attribute' ),
710 'Escaped attributes are parsed correctly'
713 mw
.messages
.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:'Arial'\'>Styled</i>' );
715 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
716 mw
.messages
.get( 'jquerymsg-escaped-single-quotes-attribute' ),
717 'Escaped attributes are parsed correctly'
720 mw
.messages
.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
722 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
723 '<i><a href="http://example.com">Example</a></i>',
724 'Contents of valid tag are treated as wikitext, so external link is parsed'
727 mw
.messages
.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
729 formatParse( 'jquerymsg-wikitext-contents-script' ),
730 '<i><span class="mediaWiki_htmlEmitter"><script>Script inside</script></span></i>',
731 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
734 mw
.messages
.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
736 formatParse( 'jquerymsg-unclosed-tag' ),
738 'Nonsupported unclosed tags are escaped'
741 mw
.messages
.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
743 formatParse( 'jquerymsg-self-closing-tag' ),
744 'Foo<tag/>bar',
745 'Self-closing tags don\'t cause a parse error'
749 QUnit
.test( 'Behavior in case of invalid wikitext', 3, function ( assert
) {
750 mw
.messages
.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
752 this.suppressWarnings();
753 var logSpy
= this.sandbox
.spy( mw
.log
, 'warn' );
756 formatParse( 'invalid-wikitext' ),
757 '<b>{{FAIL}}</b>',
758 'Invalid wikitext: \'parse\' format'
762 formatText( 'invalid-wikitext' ),
764 'Invalid wikitext: \'text\' format'
767 assert
.equal( logSpy
.callCount
, 2, 'mw.log.warn calls' );
770 }( mediaWiki
, jQuery
) );