3 // mw.Title relies on these three config vars
4 // Restore them after each test run
6 "wgFormattedNamespaces": {
14 "5": "Wikipedia talk",
18 "9": "MediaWiki talk",
20 "11": "Template talk",
24 "15": "Category talk",
25 // testing custom / localized namespace
51 /* testing custom / alias */
53 "antarctic_waterfowl": 100
55 "wgCaseSensitiveNamespaces": []
58 module( 'mediawiki.Title', QUnit
.newMwEnvironment( config
) );
60 test( '-- Initial check', function () {
62 ok( mw
.Title
, 'mw.Title defined' );
65 test( 'Transformation', function () {
70 title
= new mw
.Title( 'File:quux pif.jpg' );
71 equal( title
.getName(), 'Quux_pif' );
73 title
= new mw
.Title( 'File:Glarg_foo_glang.jpg' );
74 equal( title
.getNameText(), 'Glarg foo glang' );
76 title
= new mw
.Title( 'User:ABC.DEF' );
77 equal( title
.toText(), 'User:ABC.DEF' );
78 equal( title
.getNamespaceId(), 2 );
79 equal( title
.getNamespacePrefix(), 'User:' );
81 title
= new mw
.Title( 'uSEr:hAshAr' );
82 equal( title
.toText(), 'User:HAshAr' );
83 equal( title
.getNamespaceId(), 2 );
85 title
= new mw
.Title( ' MediaWiki: Foo bar .js ' );
86 // Don't ask why, it's the way the backend works. One space is kept of each set
87 equal( title
.getName(), 'Foo_bar_.js', "Merge multiple spaces to a single space." );
90 test( 'Main text for filename', function () {
93 var title
= new mw
.Title( 'File:foo_bar.JPG' );
95 equal( title
.getNamespaceId(), 6 );
96 equal( title
.getNamespacePrefix(), 'File:' );
97 equal( title
.getName(), 'Foo_bar' );
98 equal( title
.getNameText(), 'Foo bar' );
99 equal( title
.getMain(), 'Foo_bar.JPG' );
100 equal( title
.getMainText(), 'Foo bar.JPG' );
101 equal( title
.getExtension(), 'JPG' );
102 equal( title
.getDotExtension(), '.JPG' );
105 test( 'Namespace detection and conversion', function () {
110 title
= new mw
.Title( 'something.PDF', 6 );
111 equal( title
.toString(), 'File:Something.PDF' );
113 title
= new mw
.Title( 'NeilK', 3 );
114 equal( title
.toString(), 'User_talk:NeilK' );
115 equal( title
.toText(), 'User talk:NeilK' );
117 title
= new mw
.Title( 'Frobisher', 100 );
118 equal( title
.toString(), 'Penguins:Frobisher' );
120 title
= new mw
.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
121 equal( title
.toString(), 'Penguins:Flightless_yet_cute.jpg' );
123 title
= new mw
.Title( 'Penguins:flightless_yet_cute.jpg' );
124 equal( title
.toString(), 'Penguins:Flightless_yet_cute.jpg' );
127 test( 'Throw error on invalid title', function () {
131 var title
= new mw
.Title( '' );
132 }, 'Throw error on empty string' );
135 test( 'Case-sensivity', function () {
141 mw
.config
.set( 'wgCaseSensitiveNamespaces', [] );
143 title
= new mw
.Title( 'article' );
144 equal( title
.toString(), 'Article', 'Default config: No sensitive namespaces by default. First-letter becomes uppercase' );
146 // $wgCapitalLinks = false;
147 mw
.config
.set( 'wgCaseSensitiveNamespaces', [0, -2, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15] );
149 title
= new mw
.Title( 'article' );
150 equal( title
.toString(), 'article', '$wgCapitalLinks=false: Article namespace is sensitive, first-letter case stays lowercase' );
152 title
= new mw
.Title( 'john', 2 );
153 equal( title
.toString(), 'User:John', '$wgCapitalLinks=false: User namespace is insensitive, first-letter becomes uppercase' );
156 test( 'toString / toText', function () {
159 var title
= new mw
.Title( 'Some random page' );
161 equal( title
.toString(), title
.getPrefixedDb() );
162 equal( title
.toText(), title
.getPrefixedText() );
165 test( 'Exists', function () {
170 // Empty registry, checks default to null
172 title
= new mw
.Title( 'Some random page', 4 );
173 strictEqual( title
.exists(), null, 'Return null with empty existance registry' );
175 // Basic registry, checks default to boolean
176 mw
.Title
.exist
.set( ['Does_exist', 'User_talk:NeilK', 'Wikipedia:Sandbox_rules'], true );
177 mw
.Title
.exist
.set( ['Does_not_exist', 'User:John', 'Foobar'], false );
179 title
= new mw
.Title( 'Project:Sandbox rules' );
180 assertTrue( title
.exists(), 'Return true for page titles marked as existing' );
181 title
= new mw
.Title( 'Foobar' );
182 assertFalse( title
.exists(), 'Return false for page titles marked as nonexistent' );
186 test( 'Url', function () {
192 mw
.config
.set( 'wgArticlePath', '/wiki/$1' );
194 title
= new mw
.Title( 'Foobar' );
195 equal( title
.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
197 title
= new mw
.Title( 'John Doe', 3 );
198 equal( title
.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );