Merge "Reorder backlinks indexes"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.Title.test.js
1 /*jshint -W024 */
2 ( function ( mw, $ ) {
3 var repeat = function ( input, multiplier ) {
4 return new Array( multiplier + 1 ).join( input );
5 },
6 cases = {
7 // See also TitleTest.php#testSecureAndSplit
8 valid: [
9 'Sandbox',
10 'A "B"',
11 'A \'B\'',
12 '.com',
13 '~',
14 '"',
15 '\'',
16 'Talk:Sandbox',
17 'Talk:Foo:Sandbox',
18 'File:Example.svg',
19 'File_talk:Example.svg',
20 'Foo/.../Sandbox',
21 'Sandbox/...',
22 'A~~',
23 ':A',
24 // Length is 256 total, but only title part matters
25 'Category:' + repeat( 'x', 248 ),
26 repeat( 'x', 252 )
27 ],
28 invalid: [
29 '',
30 ':',
31 '__ __',
32 ' __ ',
33 // Bad characters forbidden regardless of wgLegalTitleChars
34 'A [ B',
35 'A ] B',
36 'A { B',
37 'A } B',
38 'A < B',
39 'A > B',
40 'A | B',
41 // URL encoding
42 'A%20B',
43 'A%23B',
44 'A%2523B',
45 // XML/HTML character entity references
46 // Note: The ones with # are commented out as those are interpreted as fragment and
47 // as such end up being valid.
48 'A &eacute; B',
49 // 'A &#233; B',
50 // 'A &#x00E9; B',
51 // Subject of NS_TALK does not roundtrip to NS_MAIN
52 'Talk:File:Example.svg',
53 // Directory navigation
54 '.',
55 '..',
56 './Sandbox',
57 '../Sandbox',
58 'Foo/./Sandbox',
59 'Foo/../Sandbox',
60 'Sandbox/.',
61 'Sandbox/..',
62 // Tilde
63 'A ~~~ Name',
64 'A ~~~~ Signature',
65 'A ~~~~~ Timestamp',
66 repeat( 'x', 256 ),
67 // Extension separation is a js invention, for length
68 // purposes it is part of the title
69 repeat( 'x', 252 ) + '.json',
70 // Namespace prefix without actual title
71 'Talk:',
72 'Category: ',
73 'Category: #bar'
74 ]
75 };
76
77 QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment( {
78 // mw.Title relies on these three config vars
79 // Restore them after each test run
80 config: {
81 wgFormattedNamespaces: {
82 '-2': 'Media',
83 '-1': 'Special',
84 0: '',
85 1: 'Talk',
86 2: 'User',
87 3: 'User talk',
88 4: 'Wikipedia',
89 5: 'Wikipedia talk',
90 6: 'File',
91 7: 'File talk',
92 8: 'MediaWiki',
93 9: 'MediaWiki talk',
94 10: 'Template',
95 11: 'Template talk',
96 12: 'Help',
97 13: 'Help talk',
98 14: 'Category',
99 15: 'Category talk',
100 // testing custom / localized namespace
101 100: 'Penguins'
102 },
103 wgNamespaceIds: {
104 'media': -2,
105 'special': -1,
106 '': 0,
107 'talk': 1,
108 'user': 2,
109 'user_talk': 3,
110 'wikipedia': 4,
111 'wikipedia_talk': 5,
112 'file': 6,
113 'file_talk': 7,
114 'mediawiki': 8,
115 'mediawiki_talk': 9,
116 'template': 10,
117 'template_talk': 11,
118 'help': 12,
119 'help_talk': 13,
120 'category': 14,
121 'category_talk': 15,
122 'image': 6,
123 'image_talk': 7,
124 'project': 4,
125 'project_talk': 5,
126 // Testing custom namespaces and aliases
127 'penguins': 100,
128 'antarctic_waterfowl': 100
129 },
130 wgCaseSensitiveNamespaces: []
131 }
132 } ) );
133
134 QUnit.test( 'constructor', cases.invalid.length, function ( assert ) {
135 var i, title;
136 for ( i = 0; i < cases.valid.length; i++ ) {
137 title = new mw.Title( cases.valid[i] );
138 }
139 for ( i = 0; i < cases.invalid.length; i++ ) {
140 /*jshint loopfunc:true */
141 title = cases.invalid[i];
142 assert.throws( function () {
143 return new mw.Title( title );
144 }, cases.invalid[i] );
145 }
146 } );
147
148 QUnit.test( 'newFromText', cases.valid.length + cases.invalid.length, function ( assert ) {
149 var i;
150 for ( i = 0; i < cases.valid.length; i++ ) {
151 assert.equal(
152 $.type( mw.Title.newFromText( cases.valid[i] ) ),
153 'object',
154 cases.valid[i]
155 );
156 }
157 for ( i = 0; i < cases.invalid.length; i++ ) {
158 assert.equal(
159 $.type( mw.Title.newFromText( cases.invalid[i] ) ),
160 'null',
161 cases.invalid[i]
162 );
163 }
164 } );
165
166 QUnit.test( 'Basic parsing', 12, function ( assert ) {
167 var title;
168 title = new mw.Title( 'File:Foo_bar.JPG' );
169
170 assert.equal( title.getNamespaceId(), 6 );
171 assert.equal( title.getNamespacePrefix(), 'File:' );
172 assert.equal( title.getName(), 'Foo_bar' );
173 assert.equal( title.getNameText(), 'Foo bar' );
174 assert.equal( title.getExtension(), 'JPG' );
175 assert.equal( title.getDotExtension(), '.JPG' );
176 assert.equal( title.getMain(), 'Foo_bar.JPG' );
177 assert.equal( title.getMainText(), 'Foo bar.JPG' );
178 assert.equal( title.getPrefixedDb(), 'File:Foo_bar.JPG' );
179 assert.equal( title.getPrefixedText(), 'File:Foo bar.JPG' );
180
181 title = new mw.Title( 'Foo#bar' );
182 assert.equal( title.getPrefixedText(), 'Foo' );
183 assert.equal( title.getFragment(), 'bar' );
184 } );
185
186 QUnit.test( 'Transformation', 11, function ( assert ) {
187 var title;
188
189 title = new mw.Title( 'File:quux pif.jpg' );
190 assert.equal( title.getNameText(), 'Quux pif', 'First character of title' );
191
192 title = new mw.Title( 'File:Glarg_foo_glang.jpg' );
193 assert.equal( title.getNameText(), 'Glarg foo glang', 'Underscores' );
194
195 title = new mw.Title( 'User:ABC.DEF' );
196 assert.equal( title.toText(), 'User:ABC.DEF', 'Round trip text' );
197 assert.equal( title.getNamespaceId(), 2, 'Parse canonical namespace prefix' );
198
199 title = new mw.Title( 'Image:quux pix.jpg' );
200 assert.equal( title.getNamespacePrefix(), 'File:', 'Transform alias to canonical namespace' );
201
202 title = new mw.Title( 'uSEr:hAshAr' );
203 assert.equal( title.toText(), 'User:HAshAr' );
204 assert.equal( title.getNamespaceId(), 2, 'Case-insensitive namespace prefix' );
205
206 // Don't ask why, it's the way the backend works. One space is kept of each set.
207 title = new mw.Title( 'Foo __ \t __ bar' );
208 assert.equal( title.getMain(), 'Foo_bar', 'Merge multiple types of whitespace/underscores into a single underscore' );
209
210 // Regression test: Previously it would only detect an extension if there is no space after it
211 title = new mw.Title( 'Example.js ' );
212 assert.equal( title.getExtension(), 'js', 'Space after an extension is stripped' );
213
214 title = new mw.Title( 'Example#foo' );
215 assert.equal( title.getFragment(), 'foo', 'Fragment' );
216
217 title = new mw.Title( 'Example#_foo_bar baz_' );
218 assert.equal( title.getFragment(), ' foo bar baz', 'Fragment' );
219 } );
220
221 QUnit.test( 'Namespace detection and conversion', 10, function ( assert ) {
222 var title;
223
224 title = new mw.Title( 'File:User:Example' );
225 assert.equal( title.getNamespaceId(), 6, 'Titles can contain namespace prefixes, which are otherwise ignored' );
226
227 title = new mw.Title( 'Example', 6 );
228 assert.equal( title.getNamespaceId(), 6, 'Default namespace passed is used' );
229
230 title = new mw.Title( 'User:Example', 6 );
231 assert.equal( title.getNamespaceId(), 2, 'Included namespace prefix overrides the given default' );
232
233 title = new mw.Title( ':Example', 6 );
234 assert.equal( title.getNamespaceId(), 0, 'Colon forces main namespace' );
235
236 title = new mw.Title( 'something.PDF', 6 );
237 assert.equal( title.toString(), 'File:Something.PDF' );
238
239 title = new mw.Title( 'NeilK', 3 );
240 assert.equal( title.toString(), 'User_talk:NeilK' );
241 assert.equal( title.toText(), 'User talk:NeilK' );
242
243 title = new mw.Title( 'Frobisher', 100 );
244 assert.equal( title.toString(), 'Penguins:Frobisher' );
245
246 title = new mw.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
247 assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
248
249 title = new mw.Title( 'Penguins:flightless_yet_cute.jpg' );
250 assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
251 } );
252
253 QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
254 assert.throws( function () {
255 return new mw.Title( '' );
256 }, 'Throw error on empty string' );
257 } );
258
259 QUnit.test( 'Case-sensivity', 3, function ( assert ) {
260 var title;
261
262 // Default config
263 mw.config.set( 'wgCaseSensitiveNamespaces', [] );
264
265 title = new mw.Title( 'article' );
266 assert.equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
267
268 // $wgCapitalLinks = false;
269 mw.config.set( 'wgCaseSensitiveNamespaces', [0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15] );
270
271 title = new mw.Title( 'article' );
272 assert.equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
273
274 title = new mw.Title( 'john', 2 );
275 assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
276 } );
277
278 QUnit.test( 'toString / toText', 2, function ( assert ) {
279 var title = new mw.Title( 'Some random page' );
280
281 assert.equal( title.toString(), title.getPrefixedDb() );
282 assert.equal( title.toText(), title.getPrefixedText() );
283 } );
284
285 QUnit.test( 'getExtension', 7, function ( assert ) {
286 function extTest( pagename, ext, description ) {
287 var title = new mw.Title( pagename );
288 assert.equal( title.getExtension(), ext, description || pagename );
289 }
290
291 extTest( 'MediaWiki:Vector.js', 'js' );
292 extTest( 'User:Example/common.css', 'css' );
293 extTest( 'File:Example.longextension', 'longextension', 'Extension parsing not limited (bug 36151)' );
294 extTest( 'Example/information.json', 'json', 'Extension parsing not restricted from any namespace' );
295 extTest( 'Foo.', null, 'Trailing dot is not an extension' );
296 extTest( 'Foo..', null, 'Trailing dots are not an extension' );
297 extTest( 'Foo.a.', null, 'Page name with dots and ending in a dot does not have an extension' );
298
299 // @broken: Throws an exception
300 // extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
301 } );
302
303 QUnit.test( 'exists', 3, function ( assert ) {
304 var title;
305
306 // Empty registry, checks default to null
307
308 title = new mw.Title( 'Some random page', 4 );
309 assert.strictEqual( title.exists(), null, 'Return null with empty existance registry' );
310
311 // Basic registry, checks default to boolean
312 mw.Title.exist.set( ['Does_exist', 'User_talk:NeilK', 'Wikipedia:Sandbox_rules'], true );
313 mw.Title.exist.set( ['Does_not_exist', 'User:John', 'Foobar'], false );
314
315 title = new mw.Title( 'Project:Sandbox rules' );
316 assert.assertTrue( title.exists(), 'Return true for page titles marked as existing' );
317 title = new mw.Title( 'Foobar' );
318 assert.assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );
319
320 } );
321
322 QUnit.test( 'getUrl', 3, function ( assert ) {
323 var title;
324
325 // Config
326 mw.config.set( 'wgArticlePath', '/wiki/$1' );
327
328 title = new mw.Title( 'Foobar' );
329 assert.equal( title.getUrl(), '/wiki/Foobar', 'Basic functionality, getUrl uses mw.util.getUrl' );
330 assert.equal( title.getUrl({ action: 'edit' }), '/wiki/Foobar?action=edit', 'Basic functionality, \'params\' parameter' );
331
332 title = new mw.Title( 'John Doe', 3 );
333 assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
334 } );
335
336 QUnit.test( 'newFromImg', 40, function ( assert ) {
337 var title, i, thisCase, prefix,
338 cases = [
339 {
340 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-thumbnail.jpg',
341 typeOfUrl: 'Hashed thumb with shortened path',
342 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)',
343 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'
344 },
345 {
346 url: '/wiki/images/thumb/9/91/Anticlockwise_heliotrope%27s.jpg/99px-Anticlockwise_heliotrope%27s.jpg',
347 typeOfUrl: 'Normal hashed directory thumbnail',
348 nameText: 'Anticlockwise heliotrope\'s',
349 prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
350 },
351
352 {
353 url: '/wiki/images/thumb/8/80/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
354 typeOfUrl: 'Normal hashed directory thumbnail with complex thumbnail parameters',
355 nameText: 'Wikipedia-logo-v2',
356 prefixedText: 'File:Wikipedia-logo-v2.svg'
357 },
358
359 {
360 url: '//upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/150px-Wikipedia-logo-v2.svg.png',
361 typeOfUrl: 'Commons thumbnail',
362 nameText: 'Wikipedia-logo-v2',
363 prefixedText: 'File:Wikipedia-logo-v2.svg'
364 },
365
366 {
367 url: '/wiki/images/9/91/Anticlockwise_heliotrope%27s.jpg',
368 typeOfUrl: 'Full image',
369 nameText: 'Anticlockwise heliotrope\'s',
370 prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
371 },
372
373 {
374 url: 'http://localhost/thumb.php?f=Stuffless_Figaro%27s.jpg&width=180',
375 typeOfUrl: 'thumb.php-based thumbnail',
376 nameText: 'Stuffless Figaro\'s',
377 prefixedText: 'File:Stuffless Figaro\'s.jpg'
378 },
379
380 {
381 url: '/wikipedia/commons/thumb/Wikipedia-logo-v2.svg/150px-Wikipedia-logo-v2.svg.png',
382 typeOfUrl: 'Commons unhashed thumbnail',
383 nameText: 'Wikipedia-logo-v2',
384 prefixedText: 'File:Wikipedia-logo-v2.svg'
385 },
386
387 {
388 url: '/wikipedia/commons/thumb/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
389 typeOfUrl: 'Commons unhashed thumbnail with complex thumbnail parameters',
390 nameText: 'Wikipedia-logo-v2',
391 prefixedText: 'File:Wikipedia-logo-v2.svg'
392 },
393
394 {
395 url: '/wiki/images/Anticlockwise_heliotrope%27s.jpg',
396 typeOfUrl: 'Unhashed local file',
397 nameText: 'Anticlockwise heliotrope\'s',
398 prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
399 },
400
401 {
402 url: '',
403 typeOfUrl: 'Empty string'
404 },
405
406 {
407 url: 'foo',
408 typeOfUrl: 'String with only alphabet characters'
409 },
410
411 {
412 url: 'foobar.foobar',
413 typeOfUrl: 'Not a file path'
414 },
415
416 {
417 url: '/a/a0/blah blah blah',
418 typeOfUrl: 'Space characters'
419 }
420 ];
421
422 for ( i = 0; i < cases.length; i++ ) {
423 thisCase = cases[i];
424 title = mw.Title.newFromImg( { src: thisCase.url } );
425
426 if ( thisCase.nameText !== undefined ) {
427 prefix = '[' + thisCase.typeOfUrl + ' URL' + '] ';
428
429 assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
430 assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
431 assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
432 assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
433 } else {
434 assert.strictEqual( title, null, thisCase.typeOfUrl + ', should not produce an mw.Title object' );
435 }
436 }
437 } );
438
439 QUnit.test( 'getRelativeText', 5, function ( assert ) {
440 var i, thisCase, title,
441 cases = [
442 {
443 text: 'asd',
444 relativeTo: 123,
445 expectedResult: ':Asd'
446 },
447 {
448 text: 'dfg',
449 relativeTo: 0,
450 expectedResult: 'Dfg'
451 },
452 {
453 text: 'Template:Ghj',
454 relativeTo: 0,
455 expectedResult: 'Template:Ghj'
456 },
457 {
458 text: 'Template:1',
459 relativeTo: 10,
460 expectedResult: '1'
461 },
462 {
463 text: 'User:Hi',
464 relativeTo: 10,
465 expectedResult: 'User:Hi'
466 }
467 ];
468
469 for ( i = 0; i < cases.length; i++ ) {
470 thisCase = cases[i];
471
472 title = mw.Title.newFromText( thisCase.text );
473 assert.equal( title.getRelativeText( thisCase.relativeTo ), thisCase.expectedResult );
474 }
475 } );
476
477 QUnit.test( 'newFromUserInput', 8, function ( assert ) {
478 var title, i, thisCase, prefix,
479 cases = [
480 {
481 title: 'DCS0001557854455.JPG',
482 defaultNamespace: 0,
483 options: {
484 fileExtension: 'PNG'
485 },
486 expected: 'DCS0001557854455.JPG',
487 description: 'Title in normal namespace without anything invalid but with "file extension"'
488 },
489 {
490 title: 'MediaWiki:Msg-awesome',
491 defaultNamespace: undefined,
492 expected: 'MediaWiki:Msg-awesome',
493 description: 'Full title (page in MediaWiki namespace) supplied as string'
494 },
495 {
496 title: 'The/Mw/Sound.flac',
497 defaultNamespace: -2,
498 expected: 'Media:The-Mw-Sound.flac',
499 description: 'Page in Media-namespace without explicit options'
500 },
501 {
502 title: 'File:The/Mw/Sound.kml',
503 defaultNamespace: 6,
504 options: {
505 forUploading: false
506 },
507 expected: 'File:The/Mw/Sound.kml',
508 description: 'Page in File-namespace without explicit options'
509 }
510 ];
511
512 for ( i = 0; i < cases.length; i++ ) {
513 thisCase = cases[i];
514 title = mw.Title.newFromUserInput( thisCase.title, thisCase.defaultNamespace, thisCase.options );
515
516 if ( thisCase.expected !== undefined ) {
517 prefix = '[' + thisCase.description + '] ';
518
519 assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
520 assert.equal( title.toText(), thisCase.expected, prefix + 'Title as expected' );
521 } else {
522 assert.strictEqual( title, null, thisCase.description + ', should not produce an mw.Title object' );
523 }
524 }
525 } );
526
527 QUnit.test( 'newFromFileName', 62, function ( assert ) {
528 var title, i, thisCase, prefix,
529 cases = [
530 {
531 fileName: 'DCS0001557854455.JPG',
532 typeOfName: 'Standard camera output',
533 nameText: 'DCS0001557854455',
534 prefixedText: 'File:DCS0001557854455.JPG',
535 extensionDesired: 'jpg'
536 },
537 {
538 fileName: 'File:Sample.png',
539 typeOfName: 'Carrying namespace',
540 nameText: 'File-Sample',
541 prefixedText: 'File:File-Sample.png'
542 },
543 {
544 fileName: 'Treppe 2222 Test upload.jpg',
545 typeOfName: 'File name with spaces in it and lower case file extension',
546 nameText: 'Treppe 2222 Test upload',
547 prefixedText: 'File:Treppe 2222 Test upload.jpg',
548 extensionDesired: 'JPG'
549 },
550 {
551 fileName: 'I contain a \ttab.jpg',
552 typeOfName: 'Name containing a tab character',
553 nameText: 'I contain a tab',
554 prefixedText: 'File:I contain a tab.jpg'
555 },
556 {
557 fileName: 'I_contain multiple__ ___ _underscores.jpg',
558 typeOfName: 'Name containing multiple underscores',
559 nameText: 'I contain multiple underscores',
560 prefixedText: 'File:I contain multiple underscores.jpg'
561 },
562 {
563 fileName: 'I like ~~~~~~~~es.jpg',
564 typeOfName: 'Name containing more than three consecutive tilde characters',
565 nameText: 'I like ~~es',
566 prefixedText: 'File:I like ~~es.jpg'
567 },
568 {
569 fileName: 'BI\u200EDI.jpg',
570 typeOfName: 'Name containing BIDI overrides',
571 nameText: 'BIDI',
572 prefixedText: 'File:BIDI.jpg'
573 },
574 {
575 fileName: '100%ab progress.jpg',
576 typeOfName: 'File name with URL encoding',
577 nameText: '100% ab progress',
578 prefixedText: 'File:100% ab progress.jpg'
579 },
580 {
581 fileName: '<([>]):/#.jpg',
582 typeOfName: 'File name with characters not permitted in titles that are replaced',
583 nameText: '((()))---',
584 prefixedText: 'File:((()))---.jpg'
585 },
586 {
587 fileName: 'spaces\u0009\u2000\u200A\u200Bx.djvu',
588 typeOfName: 'File name with different kind of spaces',
589 nameText: 'Spaces \u200Bx',
590 prefixedText: 'File:Spaces \u200Bx.djvu'
591 },
592 {
593 fileName: 'dot.dot.dot.dot.dotdot',
594 typeOfName: 'File name with a lot of dots',
595 nameText: 'Dot.dot.dot.dot',
596 prefixedText: 'File:Dot.dot.dot.dot.dotdot'
597 },
598 {
599 fileName: 'dot. dot ._dot',
600 typeOfName: 'File name with multiple dots and spaces',
601 nameText: 'Dot. dot',
602 prefixedText: 'File:Dot. dot. dot'
603 },
604 {
605 fileName: 'dot. dot ._dot',
606 typeOfName: 'File name with different file extension desired',
607 nameText: 'Dot. dot . dot',
608 prefixedText: 'File:Dot. dot . dot.png',
609 extensionDesired: 'png'
610 },
611 {
612 fileName: 'fileWOExt',
613 typeOfName: 'File W/O extension with extension desired',
614 nameText: 'FileWOExt',
615 prefixedText: 'File:FileWOExt.png',
616 extensionDesired: 'png'
617 },
618 {
619 fileName: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂.png',
620 typeOfName: 'File name longer than 240 bytes',
621 nameText: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵',
622 prefixedText: 'File:𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵.png'
623 },
624 {
625 fileName: '',
626 typeOfName: 'Empty string'
627 },
628 {
629 fileName: 'foo',
630 typeOfName: 'String with only alphabet characters'
631 }
632 ];
633
634 for ( i = 0; i < cases.length; i++ ) {
635 thisCase = cases[i];
636 title = mw.Title.newFromFileName( thisCase.fileName, thisCase.extensionDesired );
637
638 if ( thisCase.nameText !== undefined ) {
639 prefix = '[' + thisCase.typeOfName + '] ';
640
641 assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
642 assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
643 assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
644 assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
645 } else {
646 assert.strictEqual( title, null, thisCase.typeOfName + ', should not produce an mw.Title object' );
647 }
648 }
649 } );
650
651 }( mediaWiki, jQuery ) );