Merge "Doc: Document problem sorting inserted data"
[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 cases = [
441 {
442 text: 'asd',
443 relativeTo: 123,
444 expectedResult: ':Asd'
445 },
446 {
447 text: 'dfg',
448 relativeTo: 0,
449 expectedResult: 'Dfg'
450 },
451 {
452 text: 'Template:Ghj',
453 relativeTo: 0,
454 expectedResult: 'Template:Ghj'
455 },
456 {
457 text: 'Template:1',
458 relativeTo: 10,
459 expectedResult: '1'
460 },
461 {
462 text: 'User:Hi',
463 relativeTo: 10,
464 expectedResult: 'User:Hi'
465 }
466 ], i, thisCase, title;
467
468 for ( i = 0; i < cases.length; i++ ) {
469 thisCase = cases[i];
470
471 title = mw.Title.newFromText( thisCase.text );
472 assert.equal( title.getRelativeText( thisCase.relativeTo ), thisCase.expectedResult );
473 }
474 } );
475
476 QUnit.test( 'newFromUserInput', 8, function ( assert ) {
477 var title, i, thisCase, prefix,
478 cases = [
479 {
480 title: 'DCS0001557854455.JPG',
481 defaultNamespace: 0,
482 options: {
483 fileExtension: 'PNG'
484 },
485 expected: 'DCS0001557854455.JPG',
486 description: 'Title in normal namespace without anything invalid but with "file extension"'
487 },
488 {
489 title: 'MediaWiki:Msg-awesome',
490 defaultNamespace: undefined,
491 expected: 'MediaWiki:Msg-awesome',
492 description: 'Full title (page in MediaWiki namespace) supplied as string'
493 },
494 {
495 title: 'The/Mw/Sound.flac',
496 defaultNamespace: -2,
497 expected: 'Media:The-Mw-Sound.flac',
498 description: 'Page in Media-namespace without explicit options'
499 },
500 {
501 title: 'File:The/Mw/Sound.kml',
502 defaultNamespace: 6,
503 options: {
504 forUploading: false
505 },
506 expected: 'File:The/Mw/Sound.kml',
507 description: 'Page in File-namespace without explicit options'
508 }
509 ];
510
511 for ( i = 0; i < cases.length; i++ ) {
512 thisCase = cases[i];
513 title = mw.Title.newFromUserInput( thisCase.title, thisCase.defaultNamespace, thisCase.options );
514
515 if ( thisCase.expected !== undefined ) {
516 prefix = '[' + thisCase.description + '] ';
517
518 assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
519 assert.equal( title.toText(), thisCase.expected, prefix + 'Title as expected' );
520 } else {
521 assert.strictEqual( title, null, thisCase.description + ', should not produce an mw.Title object' );
522 }
523 }
524 } );
525
526 QUnit.test( 'newFromFileName', 62, function ( assert ) {
527 var title, i, thisCase, prefix,
528 cases = [
529 {
530 fileName: 'DCS0001557854455.JPG',
531 typeOfName: 'Standard camera output',
532 nameText: 'DCS0001557854455',
533 prefixedText: 'File:DCS0001557854455.JPG',
534 extensionDesired: 'jpg'
535 },
536 {
537 fileName: 'File:Sample.png',
538 typeOfName: 'Carrying namespace',
539 nameText: 'File-Sample',
540 prefixedText: 'File:File-Sample.png'
541 },
542 {
543 fileName: 'Treppe 2222 Test upload.jpg',
544 typeOfName: 'File name with spaces in it and lower case file extension',
545 nameText: 'Treppe 2222 Test upload',
546 prefixedText: 'File:Treppe 2222 Test upload.jpg',
547 extensionDesired: 'JPG'
548 },
549 {
550 fileName: 'I contain a \ttab.jpg',
551 typeOfName: 'Name containing a tab character',
552 nameText: 'I contain a tab',
553 prefixedText: 'File:I contain a tab.jpg'
554 },
555 {
556 fileName: 'I_contain multiple__ ___ _underscores.jpg',
557 typeOfName: 'Name containing multiple underscores',
558 nameText: 'I contain multiple underscores',
559 prefixedText: 'File:I contain multiple underscores.jpg'
560 },
561 {
562 fileName: 'I like ~~~~~~~~es.jpg',
563 typeOfName: 'Name containing more than three consecutive tilde characters',
564 nameText: 'I like ~~es',
565 prefixedText: 'File:I like ~~es.jpg'
566 },
567 {
568 fileName: 'BI\u200EDI.jpg',
569 typeOfName: 'Name containing BIDI overrides',
570 nameText: 'BIDI',
571 prefixedText: 'File:BIDI.jpg'
572 },
573 {
574 fileName: '100%ab progress.jpg',
575 typeOfName: 'File name with URL encoding',
576 nameText: '100% ab progress',
577 prefixedText: 'File:100% ab progress.jpg'
578 },
579 {
580 fileName: '<([>]):/#.jpg',
581 typeOfName: 'File name with characters not permitted in titles that are replaced',
582 nameText: '((()))---',
583 prefixedText: 'File:((()))---.jpg'
584 },
585 {
586 fileName: 'spaces\u0009\u2000\u200A\u200Bx.djvu',
587 typeOfName: 'File name with different kind of spaces',
588 nameText: 'Spaces \u200Bx',
589 prefixedText: 'File:Spaces \u200Bx.djvu'
590 },
591 {
592 fileName: 'dot.dot.dot.dot.dotdot',
593 typeOfName: 'File name with a lot of dots',
594 nameText: 'Dot.dot.dot.dot',
595 prefixedText: 'File:Dot.dot.dot.dot.dotdot'
596 },
597 {
598 fileName: 'dot. dot ._dot',
599 typeOfName: 'File name with multiple dots and spaces',
600 nameText: 'Dot. dot',
601 prefixedText: 'File:Dot. dot. dot'
602 },
603 {
604 fileName: 'dot. dot ._dot',
605 typeOfName: 'File name with different file extension desired',
606 nameText: 'Dot. dot . dot',
607 prefixedText: 'File:Dot. dot . dot.png',
608 extensionDesired: 'png'
609 },
610 {
611 fileName: 'fileWOExt',
612 typeOfName: 'File W/O extension with extension desired',
613 nameText: 'FileWOExt',
614 prefixedText: 'File:FileWOExt.png',
615 extensionDesired: 'png'
616 },
617 {
618 fileName: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂.png',
619 typeOfName: 'File name longer than 240 bytes',
620 nameText: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵',
621 prefixedText: 'File:𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵.png'
622 },
623 {
624 fileName: '',
625 typeOfName: 'Empty string'
626 },
627 {
628 fileName: 'foo',
629 typeOfName: 'String with only alphabet characters'
630 }
631 ];
632
633 for ( i = 0; i < cases.length; i++ ) {
634 thisCase = cases[i];
635 title = mw.Title.newFromFileName( thisCase.fileName, thisCase.extensionDesired );
636
637 if ( thisCase.nameText !== undefined ) {
638 prefix = '[' + thisCase.typeOfName + '] ';
639
640 assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
641 assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
642 assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
643 assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
644 } else {
645 assert.strictEqual( title, null, thisCase.typeOfName + ', should not produce an mw.Title object' );
646 }
647 }
648 } );
649
650 }( mediaWiki, jQuery ) );