X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki%2Fmediawiki.util.test.js;h=81fda7e3b2daa264fa3b8aac9baaebad2f17ad3e;hb=cc8dae6518bfccaa369a3ed47accf5e108d84625;hp=9216f0afe01113adf353646f0576263bb369e97b;hpb=b8a720c5e6322de4311024d0769be9996b699edb;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 9216f0afe0..9b620de406 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -1,11 +1,15 @@ ( function ( mw, $ ) { QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( { setup: function () { - this.taPrefix = mw.util.tooltipAccessKeyPrefix; - mw.util.tooltipAccessKeyPrefix = 'ctrl-alt-'; + $.fn.updateTooltipAccessKeys.setTestMode( true ); }, teardown: function () { - mw.util.tooltipAccessKeyPrefix = this.taPrefix; + $.fn.updateTooltipAccessKeys.setTestMode( false ); + }, + messages: { + // Used by accessKeyLabel in test for addPortletLink + 'brackets': '[$1]', + 'word-separator': ' ' } } ) ); @@ -13,8 +17,22 @@ assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' ); } ); - QUnit.test( 'wikiUrlencode', 1, function ( assert ) { + QUnit.test( 'wikiUrlencode', 10, function ( assert ) { assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); + // See also wfUrlencodeTest.php#provideURLS + $.each( { + '+': '%2B', + '&': '%26', + '=': '%3D', + ':': ':', + ';@$-_.!*': ';@$-_.!*', + '/': '/', + '[]': '%5B%5D', + '<>': '%3C%3E', + '\'': '%27' + }, function ( input, output ) { + assert.equal( mw.util.wikiUrlencode( input ), output ); + } ); } ); QUnit.test( 'getUrl', 4, function ( assert ) { @@ -26,7 +44,7 @@ assert.equal( href, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); href = mw.util.getUrl( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); - assert.equal( href, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', + assert.equal( href, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_!_(test)/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); href = mw.util.getUrl(); @@ -71,38 +89,6 @@ $( style.ownerNode ).remove(); } ); - QUnit.asyncTest( 'toggleToc', 4, function ( assert ) { - var tocHtml, $toggleLink; - - function actionC() { - QUnit.start(); - } - - function actionB() { - assert.strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' ); - } - - function actionA() { - assert.strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' ); - } - - assert.strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' ); - - tocHtml = '
' + - '
' + - '

Contents

' + - ' [Hide ]' + - '
' + - '' + - '
'; - $( tocHtml ).appendTo( '#qunit-fixture' ); - $toggleLink = $( '#togglelink' ); - - assert.strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' ); - - actionA(); - } ); - QUnit.test( 'getParamValue', 5, function ( assert ) { var url; @@ -121,6 +107,8 @@ } ); QUnit.test( 'tooltipAccessKey', 4, function ( assert ) { + this.suppressWarnings(); + assert.equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'tooltipAccessKeyPrefix must be a string' ); assert.equal( $.type( mw.util.tooltipAccessKeyRegexp ), 'regexp', 'tooltipAccessKeyRegexp is a regexp' ); assert.ok( mw.util.updateTooltipAccessKeys, 'updateTooltipAccessKeys is non-empty' ); @@ -128,6 +116,8 @@ 'Example [a]'.replace( mw.util.tooltipAccessKeyRegexp, function ( sub, m1, m2, m3, m4, m5, m6 ) { assert.equal( m6, 'a', 'tooltipAccessKeyRegexp finds the accesskey hint' ); } ); + + this.restoreWarnings(); } ); QUnit.test( '$content', 2, function ( assert ) { @@ -177,7 +167,7 @@ assert.ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' ); tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/', - 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ); + 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org', 'm', tbRL ); $tbMW = $( tbMW ); assert.propEqual( @@ -192,19 +182,19 @@ $tbMW.find( 'a' ).getAttrs(), { href: '//mediawiki.org/', - title: 'Go to MediaWiki.org [ctrl-alt-m]', + title: 'Go to MediaWiki.org [test-m]', accesskey: 'm' }, 'Validate attributes of anchor tag in created element' ); assert.equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' ); - assert.strictEqual( $tbMW.next()[0], tbRL, 'Link is in the correct position (by passing nextnode)' ); + assert.strictEqual( $tbMW.next()[0], tbRL, 'Link is in the correct position (nextnode as Node object)' ); cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux', null, 'Example [shift-x]', 'q' ); $cuQuux = $( cuQuux ); - assert.equal( $cuQuux.find( 'a' ).attr( 'title' ), 'Example [ctrl-alt-q]', 'Existing accesskey is stripped and updated' ); + assert.equal( $cuQuux.find( 'a' ).attr( 'title' ), 'Example [test-q]', 'Existing accesskey is stripped and updated' ); assert.equal( $( '#p-test-custom #c-barmenu ul li' ).length, @@ -215,7 +205,7 @@ tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' ); - assert.equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' ); + assert.strictEqual( $( tbRLDM ).next()[0], tbRL, 'Link is in the correct position (CSS selector as nextnode)' ); caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' ); @@ -223,27 +213,26 @@ assert.strictEqual( $( caFoo ).find( 'span' ).length, 1, 'A element should be added for porlets with vectorTabs class.' ); addedAfter = mw.util.addPortletLink( 'p-test-tb', '#', 'After foo', 'post-foo', 'After foo', null, $( tbRL ) ); - assert.strictEqual( $( addedAfter ).next()[0], tbRL, 'Link is in the correct position (by passing a jQuery object as nextnode)' ); + assert.strictEqual( $( addedAfter ).next()[0], tbRL, 'Link is in the correct position (jQuery object as nextnode)' ); // test case - nonexistent id as next node tbRLDMnonexistentid = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', 'Default modules', 't-rldm-nonexistent', 'List of all default modules ', 'd', '#t-rl-nonexistent' ); - assert.equal( tbRLDMnonexistentid, $( '#p-test-tb li:last' )[0], 'Nonexistent id as nextnode adds the portlet at end' ); + assert.equal( tbRLDMnonexistentid, $( '#p-test-tb li:last' )[0], 'Fallback to adding at the end (nextnode non-matching CSS selector)' ); // test case - empty jquery object as next node tbRLDMemptyjquery = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', 'Default modules', 't-rldm-empty-jquery', 'List of all default modules ', 'd', $( '#t-rl-nonexistent' ) ); - assert.equal( tbRLDMemptyjquery, $( '#p-test-tb li:last' )[0], 'Empty jquery as nextnode adds the portlet at end' ); + assert.equal( tbRLDMemptyjquery, $( '#p-test-tb li:last' )[0], 'Fallback to adding at the end (nextnode as empty jQuery object)' ); } ); QUnit.test( 'jsMessage', 1, function ( assert ) { + this.suppressWarnings(); var a = mw.util.jsMessage( 'MediaWiki is Awesome.' ); + this.restoreWarnings(); assert.ok( a, 'Basic checking of return value' ); - - // Clean up - $( '#mw-js-message' ).remove(); } ); QUnit.test( 'validateEmail', 6, function ( assert ) {