Support fragments in getUrl() of mw.Title
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.Title.test.js
index d5425a1..2e63b7a 100644 (file)
 
        } );
 
-       QUnit.test( 'getUrl', 3, function ( assert ) {
+       QUnit.test( 'getUrl', 4, function ( assert ) {
                var title;
 
                // Config
 
                title = new mw.Title( 'John Doe', 3 );
                assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
+
+               title = new mw.Title( 'John Cena#And_His_Name_Is', 3 );
+               assert.equal( title.getUrl( { meme: true } ), '/wiki/User_talk:John_Cena?meme=true#And_His_Name_Is', 'title with fragment and query parameter' );
        } );
 
-       QUnit.test( 'newFromImg', 40, function ( assert ) {
+       QUnit.test( 'newFromImg', 44, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                                        nameText: 'Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V)',
                                        prefixedText: 'File:Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V).jpg'
                                },
+
+                               {
+                                       url: '//upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Princess_Alexandra_of_Denmark_%28later_Queen_Alexandra%2C_wife_of_Edward_VII%29_with_her_two_eldest_sons%2C_Prince_Albert_Victor_%28Eddy%29_and_George_Frederick_Ernest_Albert_%28later_George_V%29.jpg/939px-ki708pr1r6g2dl5lbhvwdqxenhait13.jpg',
+                                       typeOfUrl: 'Hashed thumb with sha1-ed path',
+                                       nameText: 'Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V)',
+                                       prefixedText: 'File:Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V).jpg'
+                               },
+
                                {
                                        url: '/wiki/images/thumb/9/91/Anticlockwise_heliotrope%27s.jpg/99px-Anticlockwise_heliotrope%27s.jpg',
                                        typeOfUrl: 'Normal hashed directory thumbnail',
                }
        } );
 
-       QUnit.test( 'newFromUserInput', 8, function ( assert ) {
+       QUnit.test( 'normalizeExtension', 5, function ( assert ) {
+               var extension, i, thisCase, prefix,
+                       cases = [
+                               {
+                                       extension: 'png',
+                                       expected: 'png',
+                                       description: 'Extension already in canonical form'
+                               },
+                               {
+                                       extension: 'PNG',
+                                       expected: 'png',
+                                       description: 'Extension lowercased in canonical form'
+                               },
+                               {
+                                       extension: 'jpeg',
+                                       expected: 'jpg',
+                                       description: 'Extension changed in canonical form'
+                               },
+                               {
+                                       extension: 'JPEG',
+                                       expected: 'jpg',
+                                       description: 'Extension lowercased and changed in canonical form'
+                               },
+                               {
+                                       extension: '~~~',
+                                       expected: '',
+                                       description: 'Extension invalid and discarded'
+                               }
+                       ];
+
+               for ( i = 0; i < cases.length; i++ ) {
+                       thisCase = cases[ i ];
+                       extension = mw.Title.normalizeExtension( thisCase.extension );
+
+                       prefix = '[' + thisCase.description + '] ';
+                       assert.equal( extension, thisCase.expected, prefix + 'Extension as expected' );
+               }
+       } );
+
+       QUnit.test( 'newFromUserInput', 12, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                                        title: 'DCS0001557854455.JPG',
-                                       defaultNamespace: 0,
-                                       options: {
-                                               fileExtension: 'PNG'
-                                       },
                                        expected: 'DCS0001557854455.JPG',
                                        description: 'Title in normal namespace without anything invalid but with "file extension"'
                                },
                                {
                                        title: 'MediaWiki:Msg-awesome',
-                                       defaultNamespace: undefined,
                                        expected: 'MediaWiki:Msg-awesome',
                                        description: 'Full title (page in MediaWiki namespace) supplied as string'
                                },
                                        },
                                        expected: 'File:The/Mw/Sound.kml',
                                        description: 'Page in File-namespace without explicit options'
+                               },
+                               {
+                                       title: 'File:Foo.JPEG',
+                                       expected: 'File:Foo.JPEG',
+                                       description: 'Page in File-namespace with non-canonical extension'
+                               },
+                               {
+                                       title: 'File:Foo.JPEG  ',
+                                       expected: 'File:Foo.JPEG',
+                                       description: 'Page in File-namespace with trailing whitespace'
                                }
                        ];
 
                }
        } );
 
-       QUnit.test( 'newFromFileName', 62, function ( assert ) {
+       QUnit.test( 'newFromFileName', 54, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                                        fileName: 'DCS0001557854455.JPG',
                                        typeOfName: 'Standard camera output',
                                        nameText: 'DCS0001557854455',
-                                       prefixedText: 'File:DCS0001557854455.JPG',
-                                       extensionDesired: 'jpg'
+                                       prefixedText: 'File:DCS0001557854455.JPG'
                                },
                                {
                                        fileName: 'File:Sample.png',
                                        fileName: 'Treppe 2222 Test upload.jpg',
                                        typeOfName: 'File name with spaces in it and lower case file extension',
                                        nameText: 'Treppe 2222 Test upload',
-                                       prefixedText: 'File:Treppe 2222 Test upload.jpg',
-                                       extensionDesired: 'JPG'
+                                       prefixedText: 'File:Treppe 2222 Test upload.jpg'
                                },
                                {
                                        fileName: 'I contain a \ttab.jpg',
                                        nameText: 'Dot. dot',
                                        prefixedText: 'File:Dot. dot. dot'
                                },
-                               {
-                                       fileName: 'dot. dot ._dot',
-                                       typeOfName: 'File name with different file extension desired',
-                                       nameText: 'Dot. dot . dot',
-                                       prefixedText: 'File:Dot. dot . dot.png',
-                                       extensionDesired: 'png'
-                               },
-                               {
-                                       fileName: 'fileWOExt',
-                                       typeOfName: 'File W/O extension with extension desired',
-                                       nameText: 'FileWOExt',
-                                       prefixedText: 'File:FileWOExt.png',
-                                       extensionDesired: 'png'
-                               },
                                {
                                        fileName: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂.png',
                                        typeOfName: 'File name longer than 240 bytes',
 
                for ( i = 0; i < cases.length; i++ ) {
                        thisCase = cases[ i ];
-                       title = mw.Title.newFromFileName( thisCase.fileName, thisCase.extensionDesired );
+                       title = mw.Title.newFromFileName( thisCase.fileName );
 
                        if ( thisCase.nameText !== undefined ) {
                                prefix = '[' + thisCase.typeOfName + '] ';