From: Matthew Flaschen Date: Tue, 12 Feb 2013 21:51:35 +0000 (-0500) Subject: Add to/tweak mediawiki and jqueryMsg JS tests, fix comment X-Git-Tag: 1.31.0-rc.0~20103^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=e5a3f241d0a7c09902daa477232253576a23ea84;p=lhc%2Fweb%2Fwiklou.git Add to/tweak mediawiki and jqueryMsg JS tests, fix comment * Remove getOuterHtml. * Use htmlEqual where getOuterHtml was used, among other places. * The comment reflected a change I considered making, but did not in the end. * Add a few link tests * Minor tweaks to other test code for consistency * Replace wikiGetlink with explicit output Change-Id: Id6a857c9686901f8db4944fcc081d4b9c4457fa8 --- diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 2ceb3eac78..d8a1aed9dc 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -134,8 +134,7 @@ var mw = ( function ( $, undefined ) { Message.prototype = { /** - * Simple message parser, does $N replacement, HTML-escaping (only for - * 'escaped' format), and nothing else. + * Simple message parser, does $N replacement and nothing else. * * This may be overridden to provide a more complex message parser. * diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js index 0a9df966a8..697159c7ca 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js @@ -1,20 +1,11 @@ ( function ( mw, $ ) { - var mwLanguageCache = {}, oldGetOuterHtml, formatnumTests, specialCharactersPageName, + var mwLanguageCache = {}, formatnumTests, specialCharactersPageName, expectedListUsers, expectedEntrypoints; QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( { setup: function () { this.orgMwLangauge = mw.language; mw.language = $.extend( true, {}, this.orgMwLangauge ); - oldGetOuterHtml = $.fn.getOuterHtml; - $.fn.getOuterHtml = function () { - var $div = $( '
' ), html; - $div.append( $( this ).eq( 0 ).clone() ); - html = $div.html(); - $div.empty(); - $div = undefined; - return html; - }; // Messages that are reused in multiple tests mw.messages.set( { @@ -39,18 +30,18 @@ 'external-link-replace': 'Foo [$1 bar]' } ); + mw.config.set( { + wgArticlePath: '/wiki/$1' + } ); + specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?'; - expectedListUsers = '注册' + $( '' ).attr( { - title: 'Special:ListUsers', - href: mw.util.wikiGetlink( 'Special:ListUsers' ) - } ).text( '用户' ).getOuterHtml(); + expectedListUsers = '注册用户'; expectedEntrypoints = 'index.php'; }, teardown: function () { mw.language = this.orgMwLangauge; - $.fn.getOuterHtml = oldGetOuterHtml; } } ) ); @@ -252,25 +243,23 @@ the bold was removed because it is not yet implemented. */ - assert.equal( + assert.htmlEqual( parser( 'jquerymsg-test-statistics-users' ), expectedListUsers, 'Piped wikilink' ); 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 ' + - $( '' ).attr( { - title: 'MediaWiki:Disambiguationspage', - href: mw.util.wikiGetlink( 'MediaWiki:Disambiguationspage' ) - } ).text( 'MediaWiki:Disambiguationspage' ).getOuterHtml() + '.'; + 'MediaWiki:Disambiguationspage.'; + 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]].' ); - assert.equal( + assert.htmlEqual( parser( 'disambiguations-text' ), expectedDisambiguationsText, 'Wikilink without pipe' ); - assert.equal( + assert.htmlEqual( parser( 'jquerymsg-test-version-entrypoints-index-php' ), expectedEntrypoints, 'External link' @@ -284,24 +273,18 @@ 'Pipe trick should return error string.' ); - expectedMultipleBars = $( '' ).attr( { - title: 'Main Page', - href: mw.util.wikiGetlink( 'Main Page' ) - } ).text( 'Main|Page' ).getOuterHtml(); + expectedMultipleBars = 'Main|Page'; mw.messages.set( 'multiple-bars', '[[Main Page|Main|Page]]' ); - assert.equal( + assert.htmlEqual( parser( 'multiple-bars' ), expectedMultipleBars, 'Bar in anchor' ); - expectedSpecialCharacters = $( '' ).attr( { - title: specialCharactersPageName, - href: mw.util.wikiGetlink( specialCharactersPageName ) - } ).text( specialCharactersPageName ).getOuterHtml(); + expectedSpecialCharacters = '"Who" wants to be a millionaire & live on 'Exotic Island'?'; mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' ); - assert.equal( + assert.htmlEqual( parser( 'special-characters' ), expectedSpecialCharacters, 'Special characters' @@ -345,7 +328,7 @@ mw.messages.get( 'jquerymsg-test-statistics-users' ), 'Internal link message unchanged when format is \'text\'' ); - assert.equal( + assert.htmlEqual( formatParse( 'jquerymsg-test-statistics-users' ), expectedListUsers, 'Internal link message parsed when format is \'parse\'' @@ -357,7 +340,7 @@ mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ), 'External link message unchanged when format is \'text\'' ); - assert.equal( + assert.htmlEqual( formatParse( 'jquerymsg-test-version-entrypoints-index-php' ), expectedEntrypoints, 'External link message processed when format is \'parse\'' @@ -369,7 +352,7 @@ 'Foo [http://example.com bar]', 'External link message only substitutes parameter when format is \'text\'' ); - assert.equal( + assert.htmlEqual( formatParse( 'external-link-replace', 'http://example.com' ), 'Foo bar', 'External link message processed when format is \'parse\'' @@ -381,19 +364,17 @@ QUnit.test( 'Int', 4, function ( assert ) { var parser = mw.jqueryMsg.getMessageFunction(), 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:Helppage}}|help page]] for more info). If you are here by mistake, click your browser\'s back button.', - expectedNewarticletext; + expectedNewarticletext, + helpPageTitle = 'Help:Contents'; - mw.messages.set( 'helppage', 'Help:Contents' ); + mw.messages.set( 'helppage', helpPageTitle ); 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 ' + - $( '' ).attr( { - title: mw.msg( 'helppage' ), - href: mw.util.wikiGetlink( mw.msg( 'helppage' ) ) - } ).text( 'help page' ).getOuterHtml() + ' for more info). If you are here by mistake, click your browser\'s back button.'; + 'help page for more info). If you are here by mistake, click your browser\'s back button.'; mw.messages.set( 'newarticletext', newarticletextSource ); - assert.equal( + assert.htmlEqual( parser( 'newarticletext' ), expectedNewarticletext, 'Link with nested message' @@ -408,7 +389,7 @@ mw.messages.set( 'newarticletext-lowercase', newarticletextSource.replace( 'Int:Helppage', 'int:helppage' ) ); - assert.equal( + assert.htmlEqual( parser( 'newarticletext-lowercase' ), expectedNewarticletext, 'Link with nested message, lowercase include' diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index e8663f8ee0..7ae9826646 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -15,11 +15,17 @@ 'gender-plural-msg': '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome', 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}', 'formatnum-msg': '{{formatnum:$1}}', - 'int-msg': 'Some {{int:other-message}}' + 'int-msg': 'Some {{int:other-message}}', + 'mediawiki-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]', + 'external-link-replace': 'Foo [$1 bar]' } ); - // For formatnum tests - mw.config.set( 'wgUserLanguage', 'en' ); + mw.config.set( { + wgArticlePath: '/wiki/$1', + + // For formatnum tests + wgUserLanguage: 'en' + } ); specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?'; } @@ -124,7 +130,7 @@ assert.ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' ); } ); - QUnit.test( 'mw.message & mw.messages', 54, function ( assert ) { + QUnit.test( 'mw.message & mw.messages', 68, function ( assert ) { var goodbye, hello; // Convenience method for asserting the same result for multiple formats @@ -158,11 +164,24 @@ assert.equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped returns the escaped message' ); assert.equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' ); - assert.ok( mw.messages.set( 'escaped-with-curly-brace', '"{{SITENAME}}" is the home of {{int:other-message}}' ) ); - assert.equal( mw.message( 'escaped-with-curly-brace' ).escaped(), mw.html.escape( '"' + mw.config.get( 'wgSiteName' ) + '" is the home of Other Message' ), 'Escaped format works correctly for curly brace message' ); + assert.ok( mw.messages.set( 'multiple-curly-brace', '"{{SITENAME}}" is the home of {{int:other-message}}' ), 'mw.messages.set: Register' ); + assertMultipleFormats( ['multiple-curly-brace'], ['text', 'parse'], '"' + mw.config.get( 'wgSiteName') + '" is the home of Other Message', 'Curly brace format works correctly' ); + assert.equal( mw.message( 'multiple-curly-brace' ).plain(), mw.messages.get( 'multiple-curly-brace' ), 'Plain format works correctly for curly brace message' ); + assert.equal( mw.message( 'multiple-curly-brace' ).escaped(), mw.html.escape( '"' + mw.config.get( 'wgSiteName') + '" is the home of Other Message' ), 'Escaped format works correctly for curly brace message' ); + + assert.ok( mw.messages.set( 'multiple-square-brackets-and-ampersand', 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]' ), 'mw.messages.set: Register' ); + assertMultipleFormats( ['multiple-square-brackets-and-ampersand'], ['plain', 'text'], mw.messages.get( 'multiple-square-brackets-and-ampersand' ), 'Square bracket message is not processed' ); + assert.equal( mw.message( 'multiple-square-brackets-and-ampersand' ).escaped(), 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]', 'Escaped format works correctly for square bracket message' ); + assert.htmlEqual( mw.message( 'multiple-square-brackets-and-ampersand' ).parse(), 'Visit the ' + + 'community portal' + + ' & help desk', 'Internal links work with parse' ); + + assertMultipleFormats( ['mediawiki-test-version-entrypoints-index-php'], ['plain', 'text', 'escaped'], mw.messages.get( 'mediawiki-test-version-entrypoints-index-php' ), 'External link markup is unprocessed' ); + assert.htmlEqual( mw.message( 'mediawiki-test-version-entrypoints-index-php' ).parse(), 'index.php', 'External link works correctly in parse mode' ); - assert.ok( mw.messages.set( 'escaped-with-square-brackets', 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]' ) ); - assert.equal( mw.message( 'escaped-with-square-brackets' ).escaped(), 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]', 'Escaped format works correctly for square bracket message' ); + assertMultipleFormats( ['external-link-replace', 'http://example.org/?x=y&z'], ['plain', 'text'] , 'Foo [http://example.org/?x=y&z bar]', 'Parameters are substituted but external link is not processed' ); + assert.equal( mw.message( 'external-link-replace', 'http://example.org/?x=y&z' ).escaped(), 'Foo [http://example.org/?x=y&z bar]', 'In escaped mode, parameters are substituted and ampersand is escaped, but external link is not processed' ); + assert.htmlEqual( mw.message( 'external-link-replace', 'http://example.org/?x=y&z' ).parse(), 'Foo bar', 'External link with replacement works in parse mode without double-escaping' ); hello.parse(); assert.equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' ); @@ -196,7 +215,7 @@ assert.ok( mw.messages.set( 'mediawiki-test-categorytree-collapse-bullet', '[−]' ), 'mw.messages.set: Register' ); assert.equal( mw.message( 'mediawiki-test-categorytree-collapse-bullet' ).plain(), mw.messages.get( 'mediawiki-test-categorytree-collapse-bullet' ), 'Single square brackets unchanged in plain mode' ); - assert.ok( mw.messages.set( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result', 'Username (talk)' ) ); + assert.ok( mw.messages.set( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result', 'Username (talk)' ), 'mw.messages.set: Register' ); assert.equal( mw.message( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result' ).plain(), mw.messages.get( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result' ), 'HTML message with curly braces is not changed in plain mode' ); assertMultipleFormats( ['gender-plural-msg', 'male', 1], ['text', 'parse', 'escaped'], 'he is awesome', 'Gender and plural are resolved' ); @@ -218,7 +237,7 @@ assert.equal( mw.msg( 'hello' ), 'Hello awesome world', 'Gets message with default options (existing message)' ); assert.equal( mw.msg( 'goodbye' ), '', 'Gets message with default options (nonexistent message)' ); - assert.ok( mw.messages.set( 'plural-item', 'Found $1 {{PLURAL:$1|item|items}}' ) ); + assert.ok( mw.messages.set( 'plural-item' , 'Found $1 {{PLURAL:$1|item|items}}' ), 'mw.messages.set: Register' ); assert.equal( mw.msg( 'plural-item', 5 ), 'Found 5 items', 'Apply plural for count 5' ); assert.equal( mw.msg( 'plural-item', 0 ), 'Found 0 items', 'Apply plural for count 0' ); assert.equal( mw.msg( 'plural-item', 1 ), 'Found 1 item', 'Apply plural for count 1' );