Localisation updates from http://translatewiki.net.
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.Title.test.js
blob7ff0fb82d9ce57051b80e9d9ebea485dfab3b7f2
1 ( function () {
3 // mw.Title relies on these three config vars
4 // Restore them after each test run
5 var config = {
6         "wgFormattedNamespaces": {
7                 "-2": "Media",
8                 "-1": "Special",
9                 "0": "",
10                 "1": "Talk",
11                 "2": "User",
12                 "3": "User talk",
13                 "4": "Wikipedia",
14                 "5": "Wikipedia talk",
15                 "6": "File",
16                 "7": "File talk",
17                 "8": "MediaWiki",
18                 "9": "MediaWiki talk",
19                 "10": "Template",
20                 "11": "Template talk",
21                 "12": "Help",
22                 "13": "Help talk",
23                 "14": "Category",
24                 "15": "Category talk",
25                 // testing custom / localized namespace
26                 "100": "Penguins"
27         },
28         "wgNamespaceIds": {
29                 "media": -2,
30                 "special": -1,
31                 "": 0,
32                 "talk": 1,
33                 "user": 2,
34                 "user_talk": 3,
35                 "wikipedia": 4,
36                 "wikipedia_talk": 5,
37                 "file": 6,
38                 "file_talk": 7,
39                 "mediawiki": 8,
40                 "mediawiki_talk": 9,
41                 "template": 10,
42                 "template_talk": 11,
43                 "help": 12,
44                 "help_talk": 13,
45                 "category": 14,
46                 "category_talk": 15,
47                 "image": 6,
48                 "image_talk": 7,
49                 "project": 4,
50                 "project_talk": 5,
51                 /* testing custom / alias */
52                 "penguins": 100,
53                 "antarctic_waterfowl": 100
54         },
55         "wgCaseSensitiveNamespaces": []
58 module( 'mediawiki.Title', QUnit.newMwEnvironment({ config: config }) );
60 test( '-- Initial check', function () {
61         expect(1);
62         ok( mw.Title, 'mw.Title defined' );
63 });
65 test( 'Transformation', function () {
66         expect(8);
68         var title;
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." );
88 });
90 test( 'Main text for filename', function () {
91         expect(8);
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 () {
106         expect(6);
108         var title;
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 () {
128         expect(1);
130         raises(function () {
131                 var title = new mw.Title( '' );
132         }, 'Throw error on empty string' );
135 test( 'Case-sensivity', function () {
136         expect(3);
138         var title;
140         // Default config
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 () {
157         expect(2);
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 () {
166         expect(3);
168         var title;
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 () {
187         expect(2);
189         var title;
191         // Config
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' );
201 }() );