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 // Messages that are reused in multiple tests
17 // The values for gender are not significant,
18 // what matters is which of the values is choosen by the parser
19 'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
20 'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
22 'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
24 // Assume the grammar form grammar_case_foo is not valid in any language
25 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
27 'formatnum-msg': '{{formatnum:$1}}',
29 'portal-url': 'Project:Community portal',
30 'see-portal-url': '{{Int:portal-url}} is an important community page.',
32 'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
34 'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
36 'external-link-replace': 'Foo [$1 bar]'
40 wgArticlePath
: '/wiki/$1'
43 specialCharactersPageName
= '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
45 expectedListUsers
= '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
47 expectedEntrypoints
= '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
49 formatText
= mw
.jqueryMsg
.getMessageFunction( {
53 formatParse
= mw
.jqueryMsg
.getMessageFunction( {
57 teardown: function () {
58 mw
.language
= this.originalMwLanguage
;
62 function getMwLanguage( langCode
, cb
) {
63 if ( mwLanguageCache
[langCode
] !== undefined ) {
64 mwLanguageCache
[langCode
].add( cb
);
67 mwLanguageCache
[langCode
] = $.Callbacks( 'once memory' );
68 mwLanguageCache
[langCode
].add( cb
);
70 url
: mw
.util
.wikiScript( 'load' ),
72 skin
: mw
.config
.get( 'skin' ),
74 debug
: mw
.config
.get( 'debug' ),
76 'mediawiki.language.data',
82 } ).done(function () {
83 mwLanguageCache
[langCode
].fire( mw
.language
);
84 } ).fail( function () {
85 mwLanguageCache
[langCode
].fire( false );
89 QUnit
.test( 'Replace', 9, function ( assert
) {
90 mw
.messages
.set( 'simple', 'Foo $1 baz $2' );
92 assert
.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
93 assert
.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
94 assert
.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
96 mw
.messages
.set( 'plain-input', '<foo foo="foo">x$1y<</foo>z' );
99 formatParse( 'plain-input', 'bar' ),
100 '<foo foo="foo">xbary&lt;</foo>z',
101 'Input is not considered html'
104 mw
.messages
.set( 'plain-replace', 'Foo $1' );
107 formatParse( 'plain-replace', '<bar bar="bar">></bar>' ),
108 'Foo <bar bar="bar">&gt;</bar>',
109 'Replacement is not considered html'
112 mw
.messages
.set( 'object-replace', 'Foo $1' );
115 formatParse( 'object-replace', $( '<div class="bar">></div>' ) ),
116 'Foo <div class="bar">></div>',
117 'jQuery objects are preserved as raw html'
121 formatParse( 'object-replace', $( '<div class="bar">></div>' ).get( 0 ) ),
122 'Foo <div class="bar">></div>',
123 'HTMLElement objects are preserved as raw html'
127 formatParse( 'object-replace', $( '<div class="bar">></div>' ).toArray() ),
128 'Foo <div class="bar">></div>',
129 'HTMLElement[] arrays are preserved as raw html'
133 formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
134 'Foo <a href="http://example.org/?x=y&z">bar</a>',
135 'Href is not double-escaped in wikilink function'
139 QUnit
.test( 'Plural', 3, function ( assert
) {
140 assert
.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
141 assert
.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
142 assert
.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
145 QUnit
.test( 'Gender', 15, function ( assert
) {
146 var originalGender
= mw
.user
.options
.get( 'gender' );
148 // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
149 // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
150 mw
.user
.options
.set( 'gender', 'male' );
152 formatParse( 'gender-msg', 'Bob', 'male' ),
154 'Masculine from string "male"'
157 formatParse( 'gender-msg', 'Bob', mw
.user
),
159 'Masculine from mw.user object'
162 formatParse( 'gender-msg-currentuser' ),
164 'Masculine for current user'
167 mw
.user
.options
.set( 'gender', 'female' );
169 formatParse( 'gender-msg', 'Alice', 'female' ),
171 'Feminine from string "female"' );
173 formatParse( 'gender-msg', 'Alice', mw
.user
),
175 'Feminine from mw.user object'
178 formatParse( 'gender-msg-currentuser' ),
180 'Feminine for current user'
183 mw
.user
.options
.set( 'gender', 'unknown' );
185 formatParse( 'gender-msg', 'Foo', mw
.user
),
187 'Neutral from mw.user object' );
189 formatParse( 'gender-msg', 'User' ),
191 'Neutral when no parameter given' );
193 formatParse( 'gender-msg', 'User', 'unknown' ),
195 'Neutral from string "unknown"'
198 formatParse( 'gender-msg-currentuser' ),
200 'Neutral for current user'
203 mw
.messages
.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
206 formatParse( 'gender-msg-one-form', 'male', 10 ),
208 'Gender neutral and plural form'
211 formatParse( 'gender-msg-one-form', 'female', 1 ),
213 'Gender neutral and singular form'
216 mw
.messages
.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
218 formatParse( 'gender-msg-lowercase', 'male' ),
223 formatParse( 'gender-msg-lowercase', 'female' ),
228 mw
.messages
.set( 'gender-msg-wrong', '{{gender}} test' );
230 formatParse( 'gender-msg-wrong', 'female' ),
232 'Invalid syntax should result in {{gender}} simply being stripped away'
235 mw
.user
.options
.set( 'gender', originalGender
);
238 QUnit
.test( 'Grammar', 2, function ( assert
) {
239 assert
.equal( formatParse( 'grammar-msg' ), 'Przeszukaj ' + mw
.config
.get( 'wgSiteName' ), 'Grammar Test with sitename' );
241 mw
.messages
.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
242 assert
.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
245 QUnit
.test( 'Match PHP parser', mw
.libs
.phpParserData
.tests
.length
, function ( assert
) {
246 mw
.messages
.set( mw
.libs
.phpParserData
.messages
);
247 $.each( mw
.libs
.phpParserData
.tests
, function ( i
, test
) {
249 getMwLanguage( test
.lang
, function ( langClass
) {
252 assert
.ok( false, 'Language "' + test
.lang
+ '" failed to load' );
255 mw
.config
.set( 'wgUserLanguage', test
.lang
);
256 var parser
= new mw
.jqueryMsg
.parser( { language
: langClass
} );
258 parser
.parse( test
.key
, test
.args
).html(),
266 QUnit
.test( 'Links', 6, function ( assert
) {
267 var expectedDisambiguationsText
,
268 expectedMultipleBars
,
269 expectedSpecialCharacters
;
272 The below three are all identical to or based on real messages. For disambiguations-text,
273 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', 14, 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 mw
.config
.set( 'wgUserLanguage', oldUserLang
);
380 QUnit
.test( 'Int', 4, function ( assert
) {
381 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.',
382 expectedNewarticletext
,
383 helpPageTitle
= 'Help:Foobar';
385 mw
.messages
.set( 'foobar', helpPageTitle
);
387 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 ' +
388 '<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.';
390 mw
.messages
.set( 'newarticletext', newarticletextSource
);
393 formatParse( 'newarticletext' ),
394 expectedNewarticletext
,
395 'Link with nested message'
399 formatParse( 'see-portal-url' ),
400 'Project:Community portal is an important community page.',
404 mw
.messages
.set( 'newarticletext-lowercase',
405 newarticletextSource
.replace( 'Int:Helppage', 'int:helppage' ) );
408 formatParse( 'newarticletext-lowercase' ),
409 expectedNewarticletext
,
410 'Link with nested message, lowercase include'
413 mw
.messages
.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
416 formatParse( 'uses-missing-int' ),
418 'int: where nested message does not exist'
422 // Tests that getMessageFunction is used for non-plain messages with curly braces or
423 // square brackets, but not otherwise.
424 QUnit
.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert
) {
425 var oldGMF
, outerCalled
, innerCalled
;
428 'curly-brace': '{{int:message}}',
429 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
430 'double-square-bracket': '[[Some page]]',
431 'regular': 'Other message'
434 oldGMF
= mw
.jqueryMsg
.getMessageFunction
;
436 mw
.jqueryMsg
.getMessageFunction = function () {
443 function verifyGetMessageFunction( key
, format
, shouldCall
) {
447 message
= mw
.message( key
);
449 assert
.strictEqual( outerCalled
, shouldCall
, 'Outer function called for ' + key
);
450 assert
.strictEqual( innerCalled
, shouldCall
, 'Inner function called for ' + key
);
453 verifyGetMessageFunction( 'curly-brace', 'parse', true );
454 verifyGetMessageFunction( 'curly-brace', 'plain', false );
456 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
457 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
459 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
460 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
462 verifyGetMessageFunction( 'regular', 'parse', false );
463 verifyGetMessageFunction( 'regular', 'plain', false );
465 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
466 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
467 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
469 mw
.jqueryMsg
.getMessageFunction
= oldGMF
;
475 number
: 987654321.654321,
476 result
: '987,654,321.654',
477 description
: 'formatnum test for English, decimal seperator'
481 number
: 987654321.654321,
482 result
: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
483 description
: 'formatnum test for Arabic, with decimal seperator'
487 number
: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
490 description
: 'formatnum test for Arabic, with decimal seperator, reverse'
496 description
: 'formatnum test for Arabic, negative number'
503 description
: 'formatnum test for Arabic, negative number, reverse'
507 number
: 987654321.654321,
508 result
: '987.654.321,654',
509 description
: 'formatnum test for Nederlands, decimal seperator'
515 description
: 'formatnum test for Nederlands, negative number'
521 description
: 'formatnum test for Nederlands'
525 number
: 'invalidnumber',
526 result
: 'invalidnumber',
527 description
: 'formatnum test for Nederlands, invalid number'
531 number
: '1000000000',
532 result
: '1,00,00,00,000',
533 description
: 'formatnum test for Malayalam'
537 number
: '-1000000000',
538 result
: '-1,00,00,00,000',
539 description
: 'formatnum test for Malayalam, negative number'
542 * This will fail because of wrong pattern for ml in MW(different from CLDR)
545 number: '1000000000.000',
546 result: '1,00,00,00,000.000',
547 description: 'formatnum test for Malayalam with decimal place'
552 number
: '123456789.123456789',
553 result
: '१२,३४,५६,७८९',
554 description
: 'formatnum test for Hindi'
558 number
: '१२,३४,५६,७८९',
559 result
: '१२,३४,५६,७८९',
560 description
: 'formatnum test for Hindi, Devanagari digits passed'
564 number
: '१२३४५६,७८९',
567 description
: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
571 QUnit
.test( 'formatnum', formatnumTests
.length
, function ( assert
) {
572 mw
.messages
.set( 'formatnum-msg', '{{formatnum:$1}}' );
573 mw
.messages
.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
574 $.each( formatnumTests
, function ( i
, test
) {
576 getMwLanguage( test
.lang
, function ( langClass
) {
579 assert
.ok( false, 'Language "' + test
.lang
+ '" failed to load' );
582 mw
.messages
.set(test
.message
);
583 mw
.config
.set( 'wgUserLanguage', test
.lang
);
584 var parser
= new mw
.jqueryMsg
.parser( { language
: langClass
} );
586 parser
.parse( test
.integer
? 'formatnum-msg-int' : 'formatnum-msg',
587 [ test
.number
] ).html(),
596 QUnit
.test( 'HTML', 26, function ( assert
) {
597 mw
.messages
.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
599 assertBothModes( assert
, ['jquerymsg-italics-msg'], mw
.messages
.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
601 mw
.messages
.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
602 assertBothModes( assert
, ['jquerymsg-bold-msg'], mw
.messages
.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
604 mw
.messages
.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
605 assertBothModes( assert
, ['jquerymsg-bold-italics-msg'], mw
.messages
.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
607 mw
.messages
.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
608 assertBothModes( assert
, ['jquerymsg-italics-bold-msg'], mw
.messages
.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
610 mw
.messages
.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
613 formatParse( 'jquerymsg-italics-with-link' ),
614 'An <i>italicized <a title="link" href="' + mw
.html
.escape( mw
.util
.getUrl( 'link' ) ) + '">wiki-link</i>',
615 'Italics with link inside in parse mode'
619 formatText( 'jquerymsg-italics-with-link' ),
620 mw
.messages
.get( 'jquerymsg-italics-with-link' ),
621 'Italics with link unchanged in text mode'
624 mw
.messages
.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
626 formatParse( 'jquerymsg-italics-id-class' ),
627 mw
.messages
.get( 'jquerymsg-italics-id-class' ),
628 'ID and class are allowed'
631 mw
.messages
.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
633 formatParse( 'jquerymsg-italics-onclick' ),
634 '<i onclick="alert(\'foo\')">Foo</i>',
635 'element with onclick is escaped because it is not allowed'
638 mw
.messages
.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
640 formatParse( 'jquerymsg-script-msg' ),
641 '<script >alert( "Who put this tag here?" );</script>',
642 'Tag outside whitelist escaped in parse mode'
646 formatText( 'jquerymsg-script-msg' ),
647 mw
.messages
.get( 'jquerymsg-script-msg' ),
648 'Tag outside whitelist unchanged in text mode'
651 mw
.messages
.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
653 formatParse( 'jquerymsg-script-link-msg' ),
654 '<script><a title="Foo" href="' + mw
.html
.escape( mw
.util
.getUrl( 'Foo' ) ) + '">bar</a></script>',
655 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
658 mw
.messages
.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
660 formatParse( 'jquerymsg-mismatched-html' ),
661 '<i class="important">test</b>',
662 'Mismatched HTML start and end tag treated as text'
665 // TODO (mattflaschen, 2013-03-18): It's not a security issue, but there's no real
666 // reason the htmlEmitter span needs to be here. It's an artifact of how emitting works.
667 mw
.messages
.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
669 formatParse( 'jquerymsg-script-and-external-link' ),
670 '<script>alert( "jquerymsg-script-and-external-link test" );</script> <a href="http://example.com"><span class="mediaWiki_htmlEmitter"><i>Foo</i> bar</span></a>',
671 'HTML tags in external links not interfering with escaping of other tags'
674 mw
.messages
.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
676 formatParse( 'jquerymsg-link-script' ),
677 '<a href="http://example.com"><span class="mediaWiki_htmlEmitter"><script>alert( "jquerymsg-link-script test" );</script></span></a>',
678 'Non-whitelisted HTML tag in external link anchor treated as text'
681 // Intentionally not using htmlEqual for the quote tests
682 mw
.messages
.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
684 formatParse( 'jquerymsg-double-quotes-preserved' ),
685 mw
.messages
.get( 'jquerymsg-double-quotes-preserved' ),
686 'Attributes with double quotes are preserved as such'
689 mw
.messages
.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
691 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
692 '<i id="single">Single</i>',
693 'Attributes with single quotes are normalized to double'
696 mw
.messages
.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:"Arial"">Styled</i>' );
698 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
699 mw
.messages
.get( 'jquerymsg-escaped-double-quotes-attribute' ),
700 'Escaped attributes are parsed correctly'
703 mw
.messages
.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:'Arial'\'>Styled</i>' );
705 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
706 mw
.messages
.get( 'jquerymsg-escaped-single-quotes-attribute' ),
707 'Escaped attributes are parsed correctly'
710 mw
.messages
.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
712 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
713 '<i><a href="http://example.com">Example</a></i>',
714 'Contents of valid tag are treated as wikitext, so external link is parsed'
717 mw
.messages
.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
719 formatParse( 'jquerymsg-wikitext-contents-script' ),
720 '<i><span class="mediaWiki_htmlEmitter"><script>Script inside</script></span></i>',
721 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
724 mw
.messages
.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
726 formatParse( 'jquerymsg-unclosed-tag' ),
728 'Nonsupported unclosed tags are escaped'
731 mw
.messages
.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
733 formatParse( 'jquerymsg-self-closing-tag' ),
734 'Foo<tag/>bar',
735 'Self-closing tags don\'t cause a parse error'
739 QUnit
.test( 'Behavior in case of invalid wikitext', 3, function ( assert
) {
740 mw
.messages
.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
742 this.suppressWarnings();
743 var logSpy
= this.sandbox
.spy( mw
.log
, 'warn' );
746 formatParse( 'invalid-wikitext' ),
747 '<b>{{FAIL}}</b>',
748 'Invalid wikitext: \'parse\' format'
752 formatText( 'invalid-wikitext' ),
754 'Invalid wikitext: \'text\' format'
757 assert
.equal( logSpy
.callCount
, 2, 'mw.log.warn calls' );
760 }( mediaWiki
, jQuery
) );