Merge "Strip Unicode 6.3.0 directional formatting characters from title"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.Title.test.js
index 31a1a28..e8db4e1 100644 (file)
@@ -1,79 +1,80 @@
 ( function ( mw, $ ) {
+       /* eslint-disable camelcase */
        var repeat = function ( input, multiplier ) {
-               return new Array( multiplier + 1 ).join( input );
-       },
-       cases = {
+                       return new Array( multiplier + 1 ).join( input );
+               },
                // See also TitleTest.php#testSecureAndSplit
-               valid: [
-                       'Sandbox',
-                       'A "B"',
-                       'A \'B\'',
-                       '.com',
-                       '~',
-                       '"',
-                       '\'',
-                       'Talk:Sandbox',
-                       'Talk:Foo:Sandbox',
-                       'File:Example.svg',
-                       'File_talk:Example.svg',
-                       'Foo/.../Sandbox',
-                       'Sandbox/...',
-                       'A~~',
-                       ':A',
-                       // Length is 256 total, but only title part matters
-                       'Category:' + repeat( 'x', 248 ),
-                       repeat( 'x', 252 )
-               ],
-               invalid: [
-                       '',
-                       ':',
-                       '__  __',
-                       '  __  ',
-                       // Bad characters forbidden regardless of wgLegalTitleChars
-                       'A [ B',
-                       'A ] B',
-                       'A { B',
-                       'A } B',
-                       'A < B',
-                       'A > B',
-                       'A | B',
-                       'A \t B',
-                       'A \n B',
-                       // URL encoding
-                       'A%20B',
-                       'A%23B',
-                       'A%2523B',
-                       // XML/HTML character entity references
-                       // Note: The ones with # are commented out as those are interpreted as fragment and
-                       // as such end up being valid.
-                       'A &eacute; B',
-                       // 'A &#233; B',
-                       // 'A &#x00E9; B',
-                       // Subject of NS_TALK does not roundtrip to NS_MAIN
-                       'Talk:File:Example.svg',
-                       // Directory navigation
-                       '.',
-                       '..',
-                       './Sandbox',
-                       '../Sandbox',
-                       'Foo/./Sandbox',
-                       'Foo/../Sandbox',
-                       'Sandbox/.',
-                       'Sandbox/..',
-                       // Tilde
-                       'A ~~~ Name',
-                       'A ~~~~ Signature',
-                       'A ~~~~~ Timestamp',
-                       repeat( 'x', 256 ),
-                       // Extension separation is a js invention, for length
-                       // purposes it is part of the title
-                       repeat( 'x', 252 ) + '.json',
-                       // Namespace prefix without actual title
-                       'Talk:',
-                       'Category: ',
-                       'Category: #bar'
-               ]
-       };
+               cases = {
+                       valid: [
+                               'Sandbox',
+                               'A "B"',
+                               'A \'B\'',
+                               '.com',
+                               '~',
+                               '"',
+                               '\'',
+                               'Talk:Sandbox',
+                               'Talk:Foo:Sandbox',
+                               'File:Example.svg',
+                               'File_talk:Example.svg',
+                               'Foo/.../Sandbox',
+                               'Sandbox/...',
+                               'A~~',
+                               ':A',
+                               // Length is 256 total, but only title part matters
+                               'Category:' + repeat( 'x', 248 ),
+                               repeat( 'x', 252 )
+                       ],
+                       invalid: [
+                               '',
+                               ':',
+                               '__  __',
+                               '  __  ',
+                               // Bad characters forbidden regardless of wgLegalTitleChars
+                               'A [ B',
+                               'A ] B',
+                               'A { B',
+                               'A } B',
+                               'A < B',
+                               'A > B',
+                               'A | B',
+                               'A \t B',
+                               'A \n B',
+                               // URL encoding
+                               'A%20B',
+                               'A%23B',
+                               'A%2523B',
+                               // XML/HTML character entity references
+                               // Note: The ones with # are commented out as those are interpreted as fragment and
+                               // as such end up being valid.
+                               'A &eacute; B',
+                               // 'A &#233; B',
+                               // 'A &#x00E9; B',
+                               // Subject of NS_TALK does not roundtrip to NS_MAIN
+                               'Talk:File:Example.svg',
+                               // Directory navigation
+                               '.',
+                               '..',
+                               './Sandbox',
+                               '../Sandbox',
+                               'Foo/./Sandbox',
+                               'Foo/../Sandbox',
+                               'Sandbox/.',
+                               'Sandbox/..',
+                               // Tilde
+                               'A ~~~ Name',
+                               'A ~~~~ Signature',
+                               'A ~~~~~ Timestamp',
+                               repeat( 'x', 256 ),
+                               // Extension separation is a js invention, for length
+                               // purposes it is part of the title
+                               repeat( 'x', 252 ) + '.json',
+                               // Namespace prefix without actual title
+                               'Talk:',
+                               'Category: ',
+                               'Category: #bar'
+                       ]
+               };
 
        QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment( {
                // mw.Title relies on these three config vars
                                // testing custom / localized namespace
                                100: 'Penguins'
                        },
-                       // jscs: disable requireCamelCaseOrUpperCaseIdentifiers
                        wgNamespaceIds: {
                                media: -2,
                                special: -1,
                                penguins: 100,
                                antarctic_waterfowl: 100
                        },
-                       // jscs: enable requireCamelCaseOrUpperCaseIdentifiers
                        wgCaseSensitiveNamespaces: []
                }
        } ) );
 
-       QUnit.test( 'constructor', cases.invalid.length, function ( assert ) {
+       QUnit.test( 'constructor', function ( assert ) {
                var i, title;
                for ( i = 0; i < cases.valid.length; i++ ) {
                        title = new mw.Title( cases.valid[ i ] );
                }
                for ( i = 0; i < cases.invalid.length; i++ ) {
-                       /*jshint loopfunc:true */
                        title = cases.invalid[ i ];
+                       // eslint-disable-next-line no-loop-func
                        assert.throws( function () {
                                return new mw.Title( title );
                        }, cases.invalid[ i ] );
                }
        } );
 
-       QUnit.test( 'newFromText', cases.valid.length + cases.invalid.length, function ( assert ) {
+       QUnit.test( 'newFromText', function ( assert ) {
                var i;
                for ( i = 0; i < cases.valid.length; i++ ) {
                        assert.equal(
                }
        } );
 
-       QUnit.test( 'makeTitle', 6, function ( assert ) {
+       QUnit.test( 'makeTitle', function ( assert ) {
                var cases, i, title, expected,
                        NS_MAIN = 0,
                        NS_TALK = 1,
                }
        } );
 
-       QUnit.test( 'Basic parsing', 21, function ( assert ) {
+       QUnit.test( 'Basic parsing', function ( assert ) {
                var title;
                title = new mw.Title( 'File:Foo_bar.JPG' );
 
                assert.equal( title.getPrefixedText(), '.foo' );
        } );
 
-       QUnit.test( 'Transformation', 12, function ( assert ) {
+       QUnit.test( 'Transformation', function ( assert ) {
                var title;
 
                title = new mw.Title( 'File:quux pif.jpg' );
                title = new mw.Title( 'Foo \u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000 bar' );
                assert.equal( title.getMain(), 'Foo_bar', 'Merge multiple types of whitespace/underscores into a single underscore' );
 
-               title = new mw.Title( 'Foo\u200E\u200F\u202A\u202B\u202C\u202D\u202Ebar' );
-               assert.equal( title.getMain(), 'Foobar', 'Strip Unicode bidi override characters' );
+               title = new mw.Title( 'Foo\u00AD\u061C\u200E\u200F\u202A\u202B\u202C\u202D\u202E\u2066\u2067\u2068\u2069bar' );
+               assert.equal( title.getMain(), 'Foobar', 'Strip soft hyphen and Unicode directional formatting characters' );
 
                // Regression test: Previously it would only detect an extension if there is no space after it
                title = new mw.Title( 'Example.js  ' );
                assert.equal( title.getFragment(), ' foo bar baz', 'Fragment' );
        } );
 
-       QUnit.test( 'Namespace detection and conversion', 10, function ( assert ) {
+       QUnit.test( 'Namespace detection and conversion', function ( assert ) {
                var title;
 
                title = new mw.Title( 'File:User:Example' );
                assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
        } );
 
-       QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
+       QUnit.test( 'Throw error on invalid title', function ( assert ) {
                assert.throws( function () {
                        return new mw.Title( '' );
                }, 'Throw error on empty string' );
        } );
 
-       QUnit.test( 'Case-sensivity', 5, function ( assert ) {
+       QUnit.test( 'Case-sensivity', function ( assert ) {
                var title;
 
                // Default config
                assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
        } );
 
-       QUnit.test( 'toString / toText', 2, function ( assert ) {
+       QUnit.test( 'toString / toText', function ( assert ) {
                var title = new mw.Title( 'Some random page' );
 
                assert.equal( title.toString(), title.getPrefixedDb() );
                assert.equal( title.toText(), title.getPrefixedText() );
        } );
 
-       QUnit.test( 'getExtension', 7, function ( assert ) {
+       QUnit.test( 'getExtension', function ( assert ) {
                function extTest( pagename, ext, description ) {
                        var title = new mw.Title( pagename );
                        assert.equal( title.getExtension(), ext, description || pagename );
                // extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
        } );
 
-       QUnit.test( 'exists', 3, function ( assert ) {
+       QUnit.test( 'exists', function ( assert ) {
                var title;
 
                // Empty registry, checks default to null
 
        } );
 
-       QUnit.test( 'getUrl', 4, function ( assert ) {
+       QUnit.test( 'getUrl', function ( assert ) {
                var title;
                mw.config.set( {
                        wgScript: '/w/index.php',
                assert.equal( title.getUrl( { meme: true } ), '/w/index.php?title=User_talk:John_Cena&meme=true#And_His_Name_Is', 'title with fragment and query parameter' );
        } );
 
-       QUnit.test( 'newFromImg', 44, function ( assert ) {
+       QUnit.test( 'newFromImg', function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                        title = mw.Title.newFromImg( { src: thisCase.url } );
 
                        if ( thisCase.nameText !== undefined ) {
-                               prefix = '[' + thisCase.typeOfUrl + ' URL' + '] ';
+                               prefix = '[' + thisCase.typeOfUrl + ' URL] ';
 
                                assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
                                assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
                }
        } );
 
-       QUnit.test( 'getRelativeText', 5, function ( assert ) {
+       QUnit.test( 'getRelativeText', function ( assert ) {
                var i, thisCase, title,
                        cases = [
                                {
                }
        } );
 
-       QUnit.test( 'normalizeExtension', 5, function ( assert ) {
+       QUnit.test( 'normalizeExtension', function ( assert ) {
                var extension, i, thisCase, prefix,
                        cases = [
                                {
                }
        } );
 
-       QUnit.test( 'newFromUserInput', 12, function ( assert ) {
+       QUnit.test( 'newFromUserInput', function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                }
        } );
 
-       QUnit.test( 'newFromFileName', 54, function ( assert ) {
+       QUnit.test( 'newFromFileName', function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                                },
                                {
                                        fileName: 'BI\u200EDI.jpg',
-                                       typeOfName: 'Name containing BIDI overrides',
+                                       typeOfName: 'Name containing Unicode directional formatting characters',
                                        nameText: 'BIDI',
                                        prefixedText: 'File:BIDI.jpg'
                                },