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