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', 16, 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 formatParse( 'external-link-replace', $( '<i>' ) ),
375 'External link message processed as jQuery object when format is \'parse\''
378 formatParse( 'external-link-replace', function () {} ),
379 'Foo <a href="#">bar</a>',
380 'External link message processed as function when format is \'parse\''
383 mw
.config
.set( 'wgUserLanguage', oldUserLang
);
386 QUnit
.test( 'Int', 4, function ( assert
) {
387 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.',
388 expectedNewarticletext
,
389 helpPageTitle
= 'Help:Foobar';
391 mw
.messages
.set( 'foobar', helpPageTitle
);
393 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 ' +
394 '<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.';
396 mw
.messages
.set( 'newarticletext', newarticletextSource
);
399 formatParse( 'newarticletext' ),
400 expectedNewarticletext
,
401 'Link with nested message'
405 formatParse( 'see-portal-url' ),
406 'Project:Community portal is an important community page.',
410 mw
.messages
.set( 'newarticletext-lowercase',
411 newarticletextSource
.replace( 'Int:Helppage', 'int:helppage' ) );
414 formatParse( 'newarticletext-lowercase' ),
415 expectedNewarticletext
,
416 'Link with nested message, lowercase include'
419 mw
.messages
.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
422 formatParse( 'uses-missing-int' ),
424 'int: where nested message does not exist'
428 // Tests that getMessageFunction is used for non-plain messages with curly braces or
429 // square brackets, but not otherwise.
430 QUnit
.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert
) {
431 var oldGMF
, outerCalled
, innerCalled
;
434 'curly-brace': '{{int:message}}',
435 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
436 'double-square-bracket': '[[Some page]]',
437 'regular': 'Other message'
440 oldGMF
= mw
.jqueryMsg
.getMessageFunction
;
442 mw
.jqueryMsg
.getMessageFunction = function () {
449 function verifyGetMessageFunction( key
, format
, shouldCall
) {
453 message
= mw
.message( key
);
455 assert
.strictEqual( outerCalled
, shouldCall
, 'Outer function called for ' + key
);
456 assert
.strictEqual( innerCalled
, shouldCall
, 'Inner function called for ' + key
);
459 verifyGetMessageFunction( 'curly-brace', 'parse', true );
460 verifyGetMessageFunction( 'curly-brace', 'plain', false );
462 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
463 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
465 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
466 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
468 verifyGetMessageFunction( 'regular', 'parse', false );
469 verifyGetMessageFunction( 'regular', 'plain', false );
471 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
472 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
473 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
475 mw
.jqueryMsg
.getMessageFunction
= oldGMF
;
481 number
: 987654321.654321,
482 result
: '987,654,321.654',
483 description
: 'formatnum test for English, decimal seperator'
487 number
: 987654321.654321,
488 result
: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
489 description
: 'formatnum test for Arabic, with decimal seperator'
493 number
: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
496 description
: 'formatnum test for Arabic, with decimal seperator, reverse'
502 description
: 'formatnum test for Arabic, negative number'
509 description
: 'formatnum test for Arabic, negative number, reverse'
513 number
: 987654321.654321,
514 result
: '987.654.321,654',
515 description
: 'formatnum test for Nederlands, decimal seperator'
521 description
: 'formatnum test for Nederlands, negative number'
527 description
: 'formatnum test for Nederlands'
531 number
: 'invalidnumber',
532 result
: 'invalidnumber',
533 description
: 'formatnum test for Nederlands, invalid number'
537 number
: '1000000000',
538 result
: '1,00,00,00,000',
539 description
: 'formatnum test for Malayalam'
543 number
: '-1000000000',
544 result
: '-1,00,00,00,000',
545 description
: 'formatnum test for Malayalam, negative number'
548 * This will fail because of wrong pattern for ml in MW(different from CLDR)
551 number: '1000000000.000',
552 result: '1,00,00,00,000.000',
553 description: 'formatnum test for Malayalam with decimal place'
558 number
: '123456789.123456789',
559 result
: '१२,३४,५६,७८९',
560 description
: 'formatnum test for Hindi'
564 number
: '१२,३४,५६,७८९',
565 result
: '१२,३४,५६,७८९',
566 description
: 'formatnum test for Hindi, Devanagari digits passed'
570 number
: '१२३४५६,७८९',
573 description
: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
577 QUnit
.test( 'formatnum', formatnumTests
.length
, function ( assert
) {
578 mw
.messages
.set( 'formatnum-msg', '{{formatnum:$1}}' );
579 mw
.messages
.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
580 $.each( formatnumTests
, function ( i
, test
) {
582 getMwLanguage( test
.lang
, function ( langClass
) {
585 assert
.ok( false, 'Language "' + test
.lang
+ '" failed to load' );
588 mw
.messages
.set(test
.message
);
589 mw
.config
.set( 'wgUserLanguage', test
.lang
);
590 var parser
= new mw
.jqueryMsg
.parser( { language
: langClass
} );
592 parser
.parse( test
.integer
? 'formatnum-msg-int' : 'formatnum-msg',
593 [ test
.number
] ).html(),
602 QUnit
.test( 'HTML', 26, function ( assert
) {
603 mw
.messages
.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
605 assertBothModes( assert
, ['jquerymsg-italics-msg'], mw
.messages
.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
607 mw
.messages
.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
608 assertBothModes( assert
, ['jquerymsg-bold-msg'], mw
.messages
.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
610 mw
.messages
.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
611 assertBothModes( assert
, ['jquerymsg-bold-italics-msg'], mw
.messages
.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
613 mw
.messages
.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
614 assertBothModes( assert
, ['jquerymsg-italics-bold-msg'], mw
.messages
.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
616 mw
.messages
.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
619 formatParse( 'jquerymsg-italics-with-link' ),
620 'An <i>italicized <a title="link" href="' + mw
.html
.escape( mw
.util
.getUrl( 'link' ) ) + '">wiki-link</i>',
621 'Italics with link inside in parse mode'
625 formatText( 'jquerymsg-italics-with-link' ),
626 mw
.messages
.get( 'jquerymsg-italics-with-link' ),
627 'Italics with link unchanged in text mode'
630 mw
.messages
.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
632 formatParse( 'jquerymsg-italics-id-class' ),
633 mw
.messages
.get( 'jquerymsg-italics-id-class' ),
634 'ID and class are allowed'
637 mw
.messages
.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
639 formatParse( 'jquerymsg-italics-onclick' ),
640 '<i onclick="alert(\'foo\')">Foo</i>',
641 'element with onclick is escaped because it is not allowed'
644 mw
.messages
.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
646 formatParse( 'jquerymsg-script-msg' ),
647 '<script >alert( "Who put this tag here?" );</script>',
648 'Tag outside whitelist escaped in parse mode'
652 formatText( 'jquerymsg-script-msg' ),
653 mw
.messages
.get( 'jquerymsg-script-msg' ),
654 'Tag outside whitelist unchanged in text mode'
657 mw
.messages
.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
659 formatParse( 'jquerymsg-script-link-msg' ),
660 '<script><a title="Foo" href="' + mw
.html
.escape( mw
.util
.getUrl( 'Foo' ) ) + '">bar</a></script>',
661 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
664 mw
.messages
.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
666 formatParse( 'jquerymsg-mismatched-html' ),
667 '<i class="important">test</b>',
668 'Mismatched HTML start and end tag treated as text'
671 // TODO (mattflaschen, 2013-03-18): It's not a security issue, but there's no real
672 // reason the htmlEmitter span needs to be here. It's an artifact of how emitting works.
673 mw
.messages
.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
675 formatParse( 'jquerymsg-script-and-external-link' ),
676 '<script>alert( "jquerymsg-script-and-external-link test" );</script> <a href="http://example.com"><span class="mediaWiki_htmlEmitter"><i>Foo</i> bar</span></a>',
677 'HTML tags in external links not interfering with escaping of other tags'
680 mw
.messages
.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
682 formatParse( 'jquerymsg-link-script' ),
683 '<a href="http://example.com"><span class="mediaWiki_htmlEmitter"><script>alert( "jquerymsg-link-script test" );</script></span></a>',
684 'Non-whitelisted HTML tag in external link anchor treated as text'
687 // Intentionally not using htmlEqual for the quote tests
688 mw
.messages
.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
690 formatParse( 'jquerymsg-double-quotes-preserved' ),
691 mw
.messages
.get( 'jquerymsg-double-quotes-preserved' ),
692 'Attributes with double quotes are preserved as such'
695 mw
.messages
.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
697 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
698 '<i id="single">Single</i>',
699 'Attributes with single quotes are normalized to double'
702 mw
.messages
.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:"Arial"">Styled</i>' );
704 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
705 mw
.messages
.get( 'jquerymsg-escaped-double-quotes-attribute' ),
706 'Escaped attributes are parsed correctly'
709 mw
.messages
.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:'Arial'\'>Styled</i>' );
711 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
712 mw
.messages
.get( 'jquerymsg-escaped-single-quotes-attribute' ),
713 'Escaped attributes are parsed correctly'
716 mw
.messages
.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
718 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
719 '<i><a href="http://example.com">Example</a></i>',
720 'Contents of valid tag are treated as wikitext, so external link is parsed'
723 mw
.messages
.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
725 formatParse( 'jquerymsg-wikitext-contents-script' ),
726 '<i><span class="mediaWiki_htmlEmitter"><script>Script inside</script></span></i>',
727 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
730 mw
.messages
.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
732 formatParse( 'jquerymsg-unclosed-tag' ),
734 'Nonsupported unclosed tags are escaped'
737 mw
.messages
.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
739 formatParse( 'jquerymsg-self-closing-tag' ),
740 'Foo<tag/>bar',
741 'Self-closing tags don\'t cause a parse error'
745 QUnit
.test( 'Behavior in case of invalid wikitext', 3, function ( assert
) {
746 mw
.messages
.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
748 this.suppressWarnings();
749 var logSpy
= this.sandbox
.spy( mw
.log
, 'warn' );
752 formatParse( 'invalid-wikitext' ),
753 '<b>{{FAIL}}</b>',
754 'Invalid wikitext: \'parse\' format'
758 formatText( 'invalid-wikitext' ),
760 'Invalid wikitext: \'text\' format'
763 assert
.equal( logSpy
.callCount
, 2, 'mw.log.warn calls' );
766 }( mediaWiki
, jQuery
) );