X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki%2Fmediawiki.util.test.js;h=2efe9cd7f448b166027180b01f2a5acf8f8116bd;hb=a10b14d78a4589fbdfe33bc9c9c0a8ab85bd626e;hp=0e887401724ecb21d5c136dbbaed957e42c41f94;hpb=8ea7953ab57163a575a2ce02d5dbf862d7c9744a;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 0e88740172..2efe9cd7f4 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -93,7 +93,7 @@ } ); QUnit.test( 'escapeId', function ( assert ) { - mw.config.set( 'wgExperimentalHtmlIds', false ); + mw.config.set( 'wgFragmentMode', [ 'legacy' ] ); $.each( { '+': '.2B', '&': '.26', @@ -117,6 +117,75 @@ } ); } ); + QUnit.test( 'escapeIdForAttribute', function ( assert ) { + // Test cases are kept in sync with SanitizerTest.php + var text = 'foo тест_#%!\'()[]:<>', + legacyEncoded = 'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E', + html5Encoded = 'foo_тест_#%!\'()[]:<>', + html5Experimental = 'foo_тест_!_()[]:<>', + // Settings: this is $wgFragmentMode + legacy = [ 'legacy' ], + legacyNew = [ 'legacy', 'html5' ], + newLegacy = [ 'html5', 'legacy' ], + allNew = [ 'html5' ], + experimentalLegacy = [ 'html5-legacy', 'legacy' ], + newExperimental = [ 'html5', 'html5-legacy' ]; + + // Test cases are kept in sync with SanitizerTest.php + $.each( [ + // Pure legacy: how MW worked before 2017 + [ legacy, text, legacyEncoded ], + // Transition to a new world: legacy links with HTML5 fallback + [ legacyNew, text, legacyEncoded ], + // New world: HTML5 links, legacy fallbacks + [ newLegacy, text, html5Encoded ], + // Distant future: no legacy fallbacks + [ allNew, text, html5Encoded ], + // Someone flipped $wgExperimentalHtmlIds on + [ experimentalLegacy, text, html5Experimental ], + // Migration from $wgExperimentalHtmlIds to modern HTML5 + [ newExperimental, text, html5Encoded ] + ], function ( index, testCase ) { + mw.config.set( 'wgFragmentMode', testCase[ 0 ] ); + + assert.equal( util.escapeIdForAttribute( testCase[ 1 ] ), testCase[ 2 ] ); + } ); + } ); + + QUnit.test( 'escapeIdForLink', function ( assert ) { + // Test cases are kept in sync with SanitizerTest.php + var text = 'foo тест_#%!\'()[]:<>', + legacyEncoded = 'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E', + html5Escaped = 'foo_%D1%82%D0%B5%D1%81%D1%82_%23%25!\'()%5B%5D:%3C%3E', + html5Experimental = 'foo_тест_!_()[]:<>', + // Settings: this is wgFragmentMode + legacy = [ 'legacy' ], + legacyNew = [ 'legacy', 'html5' ], + newLegacy = [ 'html5', 'legacy' ], + allNew = [ 'html5' ], + experimentalLegacy = [ 'html5-legacy', 'legacy' ], + newExperimental = [ 'html5', 'html5-legacy' ]; + + $.each( [ + // Pure legacy: how MW worked before 2017 + [ legacy, text, legacyEncoded ], + // Transition to a new world: legacy links with HTML5 fallback + [ legacyNew, text, legacyEncoded ], + // New world: HTML5 links, legacy fallbacks + [ newLegacy, text, html5Escaped ], + // Distant future: no legacy fallbacks + [ allNew, text, html5Escaped ], + // Someone flipped wgExperimentalHtmlIds on + [ experimentalLegacy, text, html5Experimental ], + // Migration from wgExperimentalHtmlIds to modern HTML5 + [ newExperimental, text, html5Escaped ] + ], function ( index, testCase ) { + mw.config.set( 'wgFragmentMode', testCase[ 0 ] ); + + assert.equal( util.escapeIdForLink( testCase[ 1 ] ), testCase[ 2 ] ); + } ); + } ); + QUnit.test( 'wikiUrlencode', function ( assert ) { assert.equal( util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); // See also wfUrlencodeTest.php#provideURLS @@ -256,28 +325,28 @@ var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo, addedAfter, tbRLDMnonexistentid, tbRLDMemptyjquery; - pTestTb = '\ -
\ -

Toolbox

\ - \ -
'; - pCustom = '\ -
\ -

Views

\ - \ -
'; - vectorTabs = '\ -
\ -

Views

\ - \ -
'; + pTestTb = + '
' + + '

Toolbox

' + + '' + + '
'; + pCustom = + '
' + + '

Views

' + + '' + + '
'; + vectorTabs = + '
' + + '

Views

' + + '' + + '
'; $( '#qunit-fixture' ).append( pTestTb, pCustom, vectorTabs );