0edb1279cb8428ba040474e358b09a09fbace233
1 module( 'mediawiki.Title' );
3 // mw.Title relies on these three config vars
4 // Restore them after each test run
5 var _titleConfig = function() {
8 "wgFormattedNamespaces": {
16 "5": "Wikipedia talk",
20 "9": "MediaWiki talk",
22 "11": "Template talk",
26 "15": "Category talk",
27 /* testing custom / localized */
53 /* testing custom / alias */
55 "antarctic_waterfowl": 100
57 "wgCaseSensitiveNamespaces": []
61 test( '-- Initial check', function() {
63 ok( mw
.Title
, 'mw.Title defined' );
66 test( 'Transformation', function() {
72 title
= new mw
.Title( 'File:quux pif.jpg' );
73 equal( title
.getName(), 'Quux_pif' );
75 title
= new mw
.Title( 'File:Glarg_foo_glang.jpg' );
76 equal( title
.getNameText(), 'Glarg foo glang' );
78 title
= new mw
.Title( 'User:ABC.DEF' );
79 equal( title
.toText(), 'User:ABC.DEF' );
81 title
= new mw
.Title( ' MediaWiki: Foo bar .js ' );
82 // Don't ask why, it's the way the backend works. One space is kept of each set
83 equal( title
.getName(), 'Foo_bar_.js', "Merge multiple spaces to a single space." );
86 test( 'Main text for filename', function() {
90 var title
= new mw
.Title( 'File:foo_bar.JPG' );
92 equal( title
.getNamespaceId(), 6 );
93 equal( title
.getNamespacePrefix(), 'File:' );
94 equal( title
.getName(), 'Foo_bar' );
95 equal( title
.getNameText(), 'Foo bar' );
96 equal( title
.getMain(), 'Foo_bar.jpg' );
97 equal( title
.getMainText(), 'Foo bar.jpg' );
98 equal( title
.getExtension(), 'jpg' );
99 equal( title
.getDotExtension(), '.jpg' );
102 test( 'Namespace detection and conversion', function() {
108 title
= new mw
.Title( 'something.PDF', 6 );
109 equal( title
.toString(), 'File:Something.pdf' );
111 title
= new mw
.Title( 'NeilK', 3 );
112 equal( title
.toString(), 'User_talk:NeilK' );
113 equal( title
.toText(), 'User talk:NeilK' );
115 title
= new mw
.Title( 'Frobisher', 100 );
116 equal( title
.toString(), 'Penguins:Frobisher' );
118 title
= new mw
.Title( 'antarctic_waterfowl:flightless_yet_cute.jpg' );
119 equal( title
.toString(), 'Penguins:Flightless_yet_cute.jpg' );
121 title
= new mw
.Title( 'Penguins:flightless_yet_cute.jpg' );
122 equal( title
.toString(), 'Penguins:Flightless_yet_cute.jpg' );
125 test( 'Throw error on invalid title', function() {
130 var title
= new mw
.Title( '' );
131 }, 'Throw error on empty string' );
134 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() {
160 var title
= new mw
.Title( 'Some random page' );
162 equal( title
.toString(), title
.getPrefixedDb() );
163 equal( title
.toText(), title
.getPrefixedText() );
166 test( 'Exists', function() {
172 // Empty registry, checks default to null
174 title
= new mw
.Title( 'Some random page', 4 );
175 strictEqual( title
.exists(), null, 'Return null with empty existance registry' );
177 // Basic registry, checks default to boolean
178 mw
.Title
.exist
.set( ['Does_exist', 'User_talk:NeilK', 'Wikipedia:Sandbox_rules'], true );
179 mw
.Title
.exist
.set( ['Does_not_exist', 'User:John', 'Foobar'], false );
181 title
= new mw
.Title( 'Project:Sandbox rules' );
182 assertTrue( title
.exists(), 'Return true for page titles marked as existing' );
183 title
= new mw
.Title( 'Foobar' );
184 assertFalse( title
.exists(), 'Return false for page titles marked as inexisting' );
188 test( 'Url', function() {
195 mw
.config
.set( 'wgArticlePath', '/wiki/$1' );
197 title
= new mw
.Title( 'Foobar' );
198 equal( title
.getUrl(), '/wiki/Foobar', 'Basic functionally, toString passing to wikiGetlink' );
200 title
= new mw
.Title( 'John Doe', 3 );
201 equal( title
.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );