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