summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
blob: 641a5a5df3f5e4239498ab138de65bd8ce5d1c7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/*jshint -W024 */
( function ( mw, $ ) {
	var repeat = function ( input, multiplier ) {
		return new Array( multiplier + 1 ).join( input );
	},
	cases = {
		// 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',
			// 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
		// Restore them after each test run
		config: {
			wgFormattedNamespaces: {
				'-2': 'Media',
				'-1': 'Special',
				0: '',
				1: 'Talk',
				2: 'User',
				3: 'User talk',
				4: 'Wikipedia',
				5: 'Wikipedia talk',
				6: 'File',
				7: 'File talk',
				8: 'MediaWiki',
				9: 'MediaWiki talk',
				10: 'Template',
				11: 'Template talk',
				12: 'Help',
				13: 'Help talk',
				14: 'Category',
				15: 'Category talk',
				// testing custom / localized namespace
				100: 'Penguins'
			},
			// jscs: disable requireCamelCaseOrUpperCaseIdentifiers
			wgNamespaceIds: {
				media: -2,
				special: -1,
				'': 0,
				talk: 1,
				user: 2,
				user_talk: 3,
				wikipedia: 4,
				wikipedia_talk: 5,
				file: 6,
				file_talk: 7,
				mediawiki: 8,
				mediawiki_talk: 9,
				template: 10,
				template_talk: 11,
				help: 12,
				help_talk: 13,
				category: 14,
				category_talk: 15,
				image: 6,
				image_talk: 7,
				project: 4,
				project_talk: 5,
				// Testing custom namespaces and aliases
				penguins: 100,
				antarctic_waterfowl: 100
			},
			// jscs: enable requireCamelCaseOrUpperCaseIdentifiers
			wgCaseSensitiveNamespaces: []
		}
	} ) );

	QUnit.test( 'constructor', cases.invalid.length, 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 ];
			assert.throws( function () {
				return new mw.Title( title );
			}, cases.invalid[ i ] );
		}
	} );

	QUnit.test( 'newFromText', cases.valid.length + cases.invalid.length, function ( assert ) {
		var i;
		for ( i = 0; i < cases.valid.length; i++ ) {
			assert.equal(
				$.type( mw.Title.newFromText( cases.valid[ i ] ) ),
				'object',
				cases.valid[ i ]
			);
		}
		for ( i = 0; i < cases.invalid.length; i++ ) {
			assert.equal(
				$.type( mw.Title.newFromText( cases.invalid[ i ] ) ),
				'null',
				cases.invalid[ i ]
			);
		}
	} );

	QUnit.test( 'Basic parsing', 21, function ( assert ) {
		var title;
		title = new mw.Title( 'File:Foo_bar.JPG' );

		assert.equal( title.getNamespaceId(), 6 );
		assert.equal( title.getNamespacePrefix(), 'File:' );
		assert.equal( title.getName(), 'Foo_bar' );
		assert.equal( title.getNameText(), 'Foo bar' );
		assert.equal( title.getExtension(), 'JPG' );
		assert.equal( title.getDotExtension(), '.JPG' );
		assert.equal( title.getMain(), 'Foo_bar.JPG' );
		assert.equal( title.getMainText(), 'Foo bar.JPG' );
		assert.equal( title.getPrefixedDb(), 'File:Foo_bar.JPG' );
		assert.equal( title.getPrefixedText(), 'File:Foo bar.JPG' );

		title = new mw.Title( 'Foo#bar' );
		assert.equal( title.getPrefixedText(), 'Foo' );
		assert.equal( title.getFragment(), 'bar' );

		title = new mw.Title( '.foo' );
		assert.equal( title.getPrefixedText(), '.foo' );
		assert.equal( title.getName(), '' );
		assert.equal( title.getNameText(), '' );
		assert.equal( title.getExtension(), 'foo' );
		assert.equal( title.getDotExtension(), '.foo' );
		assert.equal( title.getMain(), '.foo' );
		assert.equal( title.getMainText(), '.foo' );
		assert.equal( title.getPrefixedDb(), '.foo' );
		assert.equal( title.getPrefixedText(), '.foo' );
	} );

	QUnit.test( 'Transformation', 11, function ( assert ) {
		var title;

		title = new mw.Title( 'File:quux pif.jpg' );
		assert.equal( title.getNameText(), 'Quux pif', 'First character of title' );

		title = new mw.Title( 'File:Glarg_foo_glang.jpg' );
		assert.equal( title.getNameText(), 'Glarg foo glang', 'Underscores' );

		title = new mw.Title( 'User:ABC.DEF' );
		assert.equal( title.toText(), 'User:ABC.DEF', 'Round trip text' );
		assert.equal( title.getNamespaceId(), 2, 'Parse canonical namespace prefix' );

		title = new mw.Title( 'Image:quux pix.jpg' );
		assert.equal( title.getNamespacePrefix(), 'File:', 'Transform alias to canonical namespace' );

		title = new mw.Title( 'uSEr:hAshAr' );
		assert.equal( title.toText(), 'User:HAshAr' );
		assert.equal( title.getNamespaceId(), 2, 'Case-insensitive namespace prefix' );

		// Don't ask why, it's the way the backend works. One space is kept of each set.
		title = new mw.Title( 'Foo  __  \t __ bar' );
		assert.equal( title.getMain(), 'Foo_bar', 'Merge multiple types of whitespace/underscores into a single underscore' );

		// 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.getExtension(), 'js', 'Space after an extension is stripped' );

		title = new mw.Title( 'Example#foo' );
		assert.equal( title.getFragment(), 'foo', 'Fragment' );

		title = new mw.Title( 'Example#_foo_bar baz_' );
		assert.equal( title.getFragment(), ' foo bar baz', 'Fragment' );
	} );

	QUnit.test( 'Namespace detection and conversion', 10, function ( assert ) {
		var title;

		title = new mw.Title( 'File:User:Example' );
		assert.equal( title.getNamespaceId(), 6, 'Titles can contain namespace prefixes, which are otherwise ignored' );

		title = new mw.Title( 'Example', 6 );
		assert.equal( title.getNamespaceId(), 6, 'Default namespace passed is used' );

		title = new mw.Title( 'User:Example', 6 );
		assert.equal( title.getNamespaceId(), 2, 'Included namespace prefix overrides the given default' );

		title = new mw.Title( ':Example', 6 );
		assert.equal( title.getNamespaceId(), 0, 'Colon forces main namespace' );

		title = new mw.Title( 'something.PDF', 6 );
		assert.equal( title.toString(), 'File:Something.PDF' );

		title = new mw.Title( 'NeilK', 3 );
		assert.equal( title.toString(), 'User_talk:NeilK' );
		assert.equal( title.toText(), 'User talk:NeilK' );

		title = new mw.Title( 'Frobisher', 100 );
		assert.equal( title.toString(), 'Penguins:Frobisher' );

		title = new mw.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
		assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );

		title = new mw.Title( 'Penguins:flightless_yet_cute.jpg' );
		assert.equal( title.toString(), 'Penguins:Flightless_yet_cute.jpg' );
	} );

	QUnit.test( 'Throw error on invalid title', 1, function ( assert ) {
		assert.throws( function () {
			return new mw.Title( '' );
		}, 'Throw error on empty string' );
	} );

	QUnit.test( 'Case-sensivity', 3, function ( assert ) {
		var title;

		// Default config
		mw.config.set( 'wgCaseSensitiveNamespaces', [] );

		title = new mw.Title( 'article' );
		assert.equal( title.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );

		// $wgCapitalLinks = false;
		mw.config.set( 'wgCaseSensitiveNamespaces', [ 0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15 ] );

		title = new mw.Title( 'article' );
		assert.equal( title.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );

		title = new mw.Title( 'john', 2 );
		assert.equal( title.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
	} );

	QUnit.test( 'toString / toText', 2, 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 ) {
		function extTest( pagename, ext, description ) {
			var title = new mw.Title( pagename );
			assert.equal( title.getExtension(), ext, description || pagename );
		}

		extTest( 'MediaWiki:Vector.js', 'js' );
		extTest( 'User:Example/common.css', 'css' );
		extTest( 'File:Example.longextension', 'longextension', 'Extension parsing not limited (bug 36151)' );
		extTest( 'Example/information.json', 'json', 'Extension parsing not restricted from any namespace' );
		extTest( 'Foo.', null, 'Trailing dot is not an extension' );
		extTest( 'Foo..', null, 'Trailing dots are not an extension' );
		extTest( 'Foo.a.', null, 'Page name with dots and ending in a dot does not have an extension' );

		// @broken: Throws an exception
		// extTest( '.NET', null, 'Leading dot is (or is not?) an extension' );
	} );

	QUnit.test( 'exists', 3, function ( assert ) {
		var title;

		// Empty registry, checks default to null

		title = new mw.Title( 'Some random page', 4 );
		assert.strictEqual( title.exists(), null, 'Return null with empty existance registry' );

		// Basic registry, checks default to boolean
		mw.Title.exist.set( [ 'Does_exist', 'User_talk:NeilK', 'Wikipedia:Sandbox_rules' ], true );
		mw.Title.exist.set( [ 'Does_not_exist', 'User:John', 'Foobar' ], false );

		title = new mw.Title( 'Project:Sandbox rules' );
		assert.assertTrue( title.exists(), 'Return true for page titles marked as existing' );
		title = new mw.Title( 'Foobar' );
		assert.assertFalse( title.exists(), 'Return false for page titles marked as nonexistent' );

	} );

	QUnit.test( 'getUrl', 3, function ( assert ) {
		var title;

		// Config
		mw.config.set( 'wgArticlePath', '/wiki/$1' );

		title = new mw.Title( 'Foobar' );
		assert.equal( title.getUrl(), '/wiki/Foobar', 'Basic functionality, getUrl uses mw.util.getUrl' );
		assert.equal( title.getUrl( { action: 'edit' } ), '/wiki/Foobar?action=edit', 'Basic functionality, \'params\' parameter' );

		title = new mw.Title( 'John Doe', 3 );
		assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
	} );

	QUnit.test( 'newFromImg', 40, function ( assert ) {
		var title, i, thisCase, prefix,
			cases = [
				{
					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',
					typeOfUrl: 'Hashed thumb with shortened 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',
					nameText: 'Anticlockwise heliotrope\'s',
					prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
				},

				{
					url: '/wiki/images/thumb/8/80/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
					typeOfUrl: 'Normal hashed directory thumbnail with complex thumbnail parameters',
					nameText: 'Wikipedia-logo-v2',
					prefixedText: 'File:Wikipedia-logo-v2.svg'
				},

				{
					url: '//upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/150px-Wikipedia-logo-v2.svg.png',
					typeOfUrl: 'Commons thumbnail',
					nameText: 'Wikipedia-logo-v2',
					prefixedText: 'File:Wikipedia-logo-v2.svg'
				},

				{
					url: '/wiki/images/9/91/Anticlockwise_heliotrope%27s.jpg',
					typeOfUrl: 'Full image',
					nameText: 'Anticlockwise heliotrope\'s',
					prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
				},

				{
					url: 'http://localhost/thumb.php?f=Stuffless_Figaro%27s.jpg&width=180',
					typeOfUrl: 'thumb.php-based thumbnail',
					nameText: 'Stuffless Figaro\'s',
					prefixedText: 'File:Stuffless Figaro\'s.jpg'
				},

				{
					url: '/wikipedia/commons/thumb/Wikipedia-logo-v2.svg/150px-Wikipedia-logo-v2.svg.png',
					typeOfUrl: 'Commons unhashed thumbnail',
					nameText: 'Wikipedia-logo-v2',
					prefixedText: 'File:Wikipedia-logo-v2.svg'
				},

				{
					url: '/wikipedia/commons/thumb/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
					typeOfUrl: 'Commons unhashed thumbnail with complex thumbnail parameters',
					nameText: 'Wikipedia-logo-v2',
					prefixedText: 'File:Wikipedia-logo-v2.svg'
				},

				{
					url: '/wiki/images/Anticlockwise_heliotrope%27s.jpg',
					typeOfUrl: 'Unhashed local file',
					nameText: 'Anticlockwise heliotrope\'s',
					prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
				},

				{
					url: '',
					typeOfUrl: 'Empty string'
				},

				{
					url: 'foo',
					typeOfUrl: 'String with only alphabet characters'
				},

				{
					url: 'foobar.foobar',
					typeOfUrl: 'Not a file path'
				},

				{
					url: '/a/a0/blah blah blah',
					typeOfUrl: 'Space characters'
				}
			];

		for ( i = 0; i < cases.length; i++ ) {
			thisCase = cases[ i ];
			title = mw.Title.newFromImg( { src: thisCase.url } );

			if ( thisCase.nameText !== undefined ) {
				prefix = '[' + thisCase.typeOfUrl + ' URL' + '] ';

				assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
				assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
				assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
				assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
			} else {
				assert.strictEqual( title, null, thisCase.typeOfUrl + ', should not produce an mw.Title object' );
			}
		}
	} );

	QUnit.test( 'getRelativeText', 5, function ( assert ) {
		var i, thisCase, title,
			cases = [
				{
					text: 'asd',
					relativeTo: 123,
					expectedResult: ':Asd'
				},
				{
					text: 'dfg',
					relativeTo: 0,
					expectedResult: 'Dfg'
				},
				{
					text: 'Template:Ghj',
					relativeTo: 0,
					expectedResult: 'Template:Ghj'
				},
				{
					text: 'Template:1',
					relativeTo: 10,
					expectedResult: '1'
				},
				{
					text: 'User:Hi',
					relativeTo: 10,
					expectedResult: 'User:Hi'
				}
			];

		for ( i = 0; i < cases.length; i++ ) {
			thisCase = cases[ i ];

			title = mw.Title.newFromText( thisCase.text );
			assert.equal( title.getRelativeText( thisCase.relativeTo ), thisCase.expectedResult );
		}
	} );

	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',
					expected: 'DCS0001557854455.JPG',
					description: 'Title in normal namespace without anything invalid but with "file extension"'
				},
				{
					title: 'MediaWiki:Msg-awesome',
					expected: 'MediaWiki:Msg-awesome',
					description: 'Full title (page in MediaWiki namespace) supplied as string'
				},
				{
					title: 'The/Mw/Sound.flac',
					defaultNamespace: -2,
					expected: 'Media:The-Mw-Sound.flac',
					description: 'Page in Media-namespace without explicit options'
				},
				{
					title: 'File:The/Mw/Sound.kml',
					defaultNamespace: 6,
					options: {
						forUploading: false
					},
					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'
				}
			];

		for ( i = 0; i < cases.length; i++ ) {
			thisCase = cases[ i ];
			title = mw.Title.newFromUserInput( thisCase.title, thisCase.defaultNamespace, thisCase.options );

			if ( thisCase.expected !== undefined ) {
				prefix = '[' + thisCase.description + '] ';

				assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
				assert.equal( title.toText(), thisCase.expected, prefix + 'Title as expected' );
			} else {
				assert.strictEqual( title, null, thisCase.description + ', should not produce an mw.Title object' );
			}
		}
	} );

	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'
				},
				{
					fileName: 'File:Sample.png',
					typeOfName: 'Carrying namespace',
					nameText: 'File-Sample',
					prefixedText: 'File: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'
				},
				{
					fileName: 'I contain a \ttab.jpg',
					typeOfName: 'Name containing a tab character',
					nameText: 'I contain a tab',
					prefixedText: 'File:I contain a tab.jpg'
				},
				{
					fileName: 'I_contain multiple__ ___ _underscores.jpg',
					typeOfName: 'Name containing multiple underscores',
					nameText: 'I contain multiple underscores',
					prefixedText: 'File:I contain multiple underscores.jpg'
				},
				{
					fileName: 'I like ~~~~~~~~es.jpg',
					typeOfName: 'Name containing more than three consecutive tilde characters',
					nameText: 'I like ~~es',
					prefixedText: 'File:I like ~~es.jpg'
				},
				{
					fileName: 'BI\u200EDI.jpg',
					typeOfName: 'Name containing BIDI overrides',
					nameText: 'BIDI',
					prefixedText: 'File:BIDI.jpg'
				},
				{
					fileName: '100%ab progress.jpg',
					typeOfName: 'File name with URL encoding',
					nameText: '100% ab progress',
					prefixedText: 'File:100% ab progress.jpg'
				},
				{
					fileName: '<([>]):/#.jpg',
					typeOfName: 'File name with characters not permitted in titles that are replaced',
					nameText: '((()))---',
					prefixedText: 'File:((()))---.jpg'
				},
				{
					fileName: 'spaces\u0009\u2000\u200A\u200Bx.djvu',
					typeOfName: 'File name with different kind of spaces',
					nameText: 'Spaces \u200Bx',
					prefixedText: 'File:Spaces \u200Bx.djvu'
				},
				{
					fileName: 'dot.dot.dot.dot.dotdot',
					typeOfName: 'File name with a lot of dots',
					nameText: 'Dot.dot.dot.dot',
					prefixedText: 'File:Dot.dot.dot.dot.dotdot'
				},
				{
					fileName: 'dot. dot ._dot',
					typeOfName: 'File name with multiple dots and spaces',
					nameText: 'Dot. dot',
					prefixedText: 'File:Dot. dot. dot'
				},
				{
					fileName: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂.png',
					typeOfName: 'File name longer than 240 bytes',
					nameText: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵',
					prefixedText: 'File:𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵.png'
				},
				{
					fileName: '',
					typeOfName: 'Empty string'
				},
				{
					fileName: 'foo',
					typeOfName: 'String with only alphabet characters'
				}
			];

		for ( i = 0; i < cases.length; i++ ) {
			thisCase = cases[ i ];
			title = mw.Title.newFromFileName( thisCase.fileName );

			if ( thisCase.nameText !== undefined ) {
				prefix = '[' + thisCase.typeOfName + '] ';

				assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
				assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
				assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
				assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
			} else {
				assert.strictEqual( title, null, thisCase.typeOfName + ', should not produce an mw.Title object' );
			}
		}
	} );

}( mediaWiki, jQuery ) );