Merge "Define 'MW_UPDATER' when running update.php"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
blob9ca434f1ec70e6b521e601b267ca05ba7d18b6b9
1 ( function ( mw, $ ) {
2         'use strict';
4         QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
5                 setup: function () {
6                         this.liveLangData = mw.language.data.values;
7                         mw.language.data.values = $.extend( true, {}, this.liveLangData );
8                 },
9                 teardown: function () {
10                         mw.language.data.values = this.liveLangData;
11                 }
12         } ) );
14         QUnit.test( 'mw.language getData and setData', 2, function ( assert ) {
15                 mw.language.setData( 'en', 'testkey', 'testvalue' );
16                 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
17                 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
18         } );
20         function grammarTest( langCode, test ) {
21                 // The test works only if the content language is opt.language
22                 // because it requires [lang].js to be loaded.
23                 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
24                         QUnit.expect( test.length );
26                         for ( var i = 0; i < test.length; i++ ) {
27                                 assert.equal(
28                                         mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
29                                         test[i].expected,
30                                         test[i].description
31                                 );
32                         }
33                 } );
34         }
36         // These tests run only for the current UI language.
37         var grammarTests = {
38                 bs: [
39                         {
40                                 word: 'word',
41                                 grammarForm: 'instrumental',
42                                 expected: 's word',
43                                 description: 'Grammar test for instrumental case'
44                         },
45                         {
46                                 word: 'word',
47                                 grammarForm: 'lokativ',
48                                 expected: 'o word',
49                                 description: 'Grammar test for lokativ case'
50                         }
51                 ],
53                 he: [
54                         {
55                                 word: 'ויקיפדיה',
56                                 grammarForm: 'prefixed',
57                                 expected: 'וויקיפדיה',
58                                 description: 'Duplicate the "Waw" if prefixed'
59                         },
60                         {
61                                 word: 'וולפגנג',
62                                 grammarForm: 'prefixed',
63                                 expected: 'וולפגנג',
64                                 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
65                         },
66                         {
67                                 word: 'הקובץ',
68                                 grammarForm: 'prefixed',
69                                 expected: 'קובץ',
70                                 description: 'Remove the "He" if prefixed'
71                         },
72                         {
73                                 word: 'Wikipedia',
74                                 grammarForm: 'תחילית',
75                                 expected: '־Wikipedia',
76                                 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
77                         },
78                         {
79                                 word: '1995',
80                                 grammarForm: 'תחילית',
81                                 expected: '־1995',
82                                 description: 'Add a hyphen (maqaf) before numbers'
83                         }
84                 ],
86                 hsb: [
87                         {
88                                 word: 'word',
89                                 grammarForm: 'instrumental',
90                                 expected: 'z word',
91                                 description: 'Grammar test for instrumental case'
92                         },
93                         {
94                                 word: 'word',
95                                 grammarForm: 'lokatiw',
96                                 expected: 'wo word',
97                                 description: 'Grammar test for lokatiw case'
98                         }
99                 ],
101                 dsb: [
102                         {
103                                 word: 'word',
104                                 grammarForm: 'instrumental',
105                                 expected: 'z word',
106                                 description: 'Grammar test for instrumental case'
107                         },
108                         {
109                                 word: 'word',
110                                 grammarForm: 'lokatiw',
111                                 expected: 'wo word',
112                                 description: 'Grammar test for lokatiw case'
113                         }
114                 ],
116                 hy: [
117                         {
118                                 word: 'Մաունա',
119                                 grammarForm: 'genitive',
120                                 expected: 'Մաունայի',
121                                 description: 'Grammar test for genitive case'
122                         },
123                         {
124                                 word: 'հետո',
125                                 grammarForm: 'genitive',
126                                 expected: 'հետոյի',
127                                 description: 'Grammar test for genitive case'
128                         },
129                         {
130                                 word: 'գիրք',
131                                 grammarForm: 'genitive',
132                                 expected: 'գրքի',
133                                 description: 'Grammar test for genitive case'
134                         },
135                         {
136                                 word: 'ժամանակի',
137                                 grammarForm: 'genitive',
138                                 expected: 'ժամանակիի',
139                                 description: 'Grammar test for genitive case'
140                         }
141                 ],
143                 fi: [
144                         {
145                                 word: 'talo',
146                                 grammarForm: 'genitive',
147                                 expected: 'talon',
148                                 description: 'Grammar test for genitive case'
149                         },
150                         {
151                                 word: 'linux',
152                                 grammarForm: 'genitive',
153                                 expected: 'linuxin',
154                                 description: 'Grammar test for genitive case'
155                         },
156                         {
157                                 word: 'talo',
158                                 grammarForm: 'elative',
159                                 expected: 'talosta',
160                                 description: 'Grammar test for elative case'
161                         },
162                         {
163                                 word: 'pastöroitu',
164                                 grammarForm: 'partitive',
165                                 expected: 'pastöroitua',
166                                 description: 'Grammar test for partitive case'
167                         },
168                         {
169                                 word: 'talo',
170                                 grammarForm: 'partitive',
171                                 expected: 'taloa',
172                                 description: 'Grammar test for partitive case'
173                         },
174                         {
175                                 word: 'talo',
176                                 grammarForm: 'illative',
177                                 expected: 'taloon',
178                                 description: 'Grammar test for illative case'
179                         },
180                         {
181                                 word: 'linux',
182                                 grammarForm: 'inessive',
183                                 expected: 'linuxissa',
184                                 description: 'Grammar test for inessive case'
185                         }
186                 ],
188                 ru: [
189                         {
190                                 word: 'тесть',
191                                 grammarForm: 'genitive',
192                                 expected: 'тестя',
193                                 description: 'Grammar test for genitive case, тесть -> тестя'
194                         },
195                         {
196                                 word: 'привилегия',
197                                 grammarForm: 'genitive',
198                                 expected: 'привилегии',
199                                 description: 'Grammar test for genitive case, привилегия -> привилегии'
200                         },
201                         {
202                                 word: 'установка',
203                                 grammarForm: 'genitive',
204                                 expected: 'установки',
205                                 description: 'Grammar test for genitive case, установка -> установки'
206                         },
207                         {
208                                 word: 'похоти',
209                                 grammarForm: 'genitive',
210                                 expected: 'похотей',
211                                 description: 'Grammar test for genitive case, похоти -> похотей'
212                         },
213                         {
214                                 word: 'доводы',
215                                 grammarForm: 'genitive',
216                                 expected: 'доводов',
217                                 description: 'Grammar test for genitive case, доводы -> доводов'
218                         },
219                         {
220                                 word: 'песчаник',
221                                 grammarForm: 'genitive',
222                                 expected: 'песчаника',
223                                 description: 'Grammar test for genitive case, песчаник -> песчаника'
224                         },
225                         {
226                                 word: 'данные',
227                                 grammarForm: 'genitive',
228                                 expected: 'данных',
229                                 description: 'Grammar test for genitive case, данные -> данных'
230                         },
231                         {
232                                 word: 'тесть',
233                                 grammarForm: 'prepositional',
234                                 expected: 'тесте',
235                                 description: 'Grammar test for prepositional case, тесть -> тесте'
236                         },
237                         {
238                                 word: 'привилегия',
239                                 grammarForm: 'prepositional',
240                                 expected: 'привилегии',
241                                 description: 'Grammar test for prepositional case, привилегия -> привилегии'
242                         },
243                         {
244                                 word: 'установка',
245                                 grammarForm: 'prepositional',
246                                 expected: 'установке',
247                                 description: 'Grammar test for prepositional case, установка -> установке'
248                         },
249                         {
250                                 word: 'похоти',
251                                 grammarForm: 'prepositional',
252                                 expected: 'похотях',
253                                 description: 'Grammar test for prepositional case, похоти -> похотях'
254                         },
255                         {
256                                 word: 'доводы',
257                                 grammarForm: 'prepositional',
258                                 expected: 'доводах',
259                                 description: 'Grammar test for prepositional case, доводы -> доводах'
260                         },
261                         {
262                                 word: 'песчаник',
263                                 grammarForm: 'prepositional',
264                                 expected: 'песчанике',
265                                 description: 'Grammar test for prepositional case, песчаник -> песчанике'
266                         },
267                         {
268                                 word: 'данные',
269                                 grammarForm: 'prepositional',
270                                 expected: 'данных',
271                                 description: 'Grammar test for prepositional case, данные -> данных'
272                         }
273                 ],
275                 hu: [
276                         {
277                                 word: 'Wikipédiá',
278                                 grammarForm: 'rol',
279                                 expected: 'Wikipédiáról',
280                                 description: 'Grammar test for rol case'
281                         },
282                         {
283                                 word: 'Wikipédiá',
284                                 grammarForm: 'ba',
285                                 expected: 'Wikipédiába',
286                                 description: 'Grammar test for ba case'
287                         },
288                         {
289                                 word: 'Wikipédiá',
290                                 grammarForm: 'k',
291                                 expected: 'Wikipédiák',
292                                 description: 'Grammar test for k case'
293                         }
294                 ],
296                 ga: [
297                         {
298                                 word: 'an Domhnach',
299                                 grammarForm: 'ainmlae',
300                                 expected: 'Dé Domhnaigh',
301                                 description: 'Grammar test for ainmlae case'
302                         },
303                         {
304                                 word: 'an Luan',
305                                 grammarForm: 'ainmlae',
306                                 expected: 'Dé Luain',
307                                 description: 'Grammar test for ainmlae case'
308                         },
309                         {
310                                 word: 'an Satharn',
311                                 grammarForm: 'ainmlae',
312                                 expected: 'Dé Sathairn',
313                                 description: 'Grammar test for ainmlae case'
314                         }
315                 ],
317                 uk: [
318                         {
319                                 word: 'тесть',
320                                 grammarForm: 'genitive',
321                                 expected: 'тестя',
322                                 description: 'Grammar test for genitive case'
323                         },
324                         {
325                                 word: 'Вікіпедія',
326                                 grammarForm: 'genitive',
327                                 expected: 'Вікіпедії',
328                                 description: 'Grammar test for genitive case'
329                         },
330                         {
331                                 word: 'установка',
332                                 grammarForm: 'genitive',
333                                 expected: 'установки',
334                                 description: 'Grammar test for genitive case'
335                         },
336                         {
337                                 word: 'похоти',
338                                 grammarForm: 'genitive',
339                                 expected: 'похотей',
340                                 description: 'Grammar test for genitive case'
341                         },
342                         {
343                                 word: 'доводы',
344                                 grammarForm: 'genitive',
345                                 expected: 'доводов',
346                                 description: 'Grammar test for genitive case'
347                         },
348                         {
349                                 word: 'песчаник',
350                                 grammarForm: 'genitive',
351                                 expected: 'песчаника',
352                                 description: 'Grammar test for genitive case'
353                         },
354                         {
355                                 word: 'Вікіпедія',
356                                 grammarForm: 'accusative',
357                                 expected: 'Вікіпедію',
358                                 description: 'Grammar test for accusative case'
359                         }
360                 ],
362                 sl: [
363                         {
364                                 word: 'word',
365                                 grammarForm: 'orodnik',
366                                 expected: 'z word',
367                                 description: 'Grammar test for orodnik case'
368                         },
369                         {
370                                 word: 'word',
371                                 grammarForm: 'mestnik',
372                                 expected: 'o word',
373                                 description: 'Grammar test for mestnik case'
374                         }
375                 ],
377                 os: [
378                         {
379                                 word: 'бæстæ',
380                                 grammarForm: 'genitive',
381                                 expected: 'бæсты',
382                                 description: 'Grammar test for genitive case'
383                         },
384                         {
385                                 word: 'бæстæ',
386                                 grammarForm: 'allative',
387                                 expected: 'бæстæм',
388                                 description: 'Grammar test for allative case'
389                         },
390                         {
391                                 word: 'Тигр',
392                                 grammarForm: 'dative',
393                                 expected: 'Тигрæн',
394                                 description: 'Grammar test for dative case'
395                         },
396                         {
397                                 word: 'цъити',
398                                 grammarForm: 'dative',
399                                 expected: 'цъитийæн',
400                                 description: 'Grammar test for dative case'
401                         },
402                         {
403                                 word: 'лæппу',
404                                 grammarForm: 'genitive',
405                                 expected: 'лæппуйы',
406                                 description: 'Grammar test for genitive case'
407                         },
408                         {
409                                 word: '2011',
410                                 grammarForm: 'equative',
411                                 expected: '2011-ау',
412                                 description: 'Grammar test for equative case'
413                         }
414                 ],
416                 la: [
417                         {
418                                 word: 'Translatio',
419                                 grammarForm: 'genitive',
420                                 expected: 'Translationis',
421                                 description: 'Grammar test for genitive case'
422                         },
423                         {
424                                 word: 'Translatio',
425                                 grammarForm: 'accusative',
426                                 expected: 'Translationem',
427                                 description: 'Grammar test for accusative case'
428                         },
429                         {
430                                 word: 'Translatio',
431                                 grammarForm: 'ablative',
432                                 expected: 'Translatione',
433                                 description: 'Grammar test for ablative case'
434                         }
435                 ]
436         };
438         $.each( grammarTests, function ( langCode, test ) {
439                 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
440                         grammarTest( langCode, test );
441                 }
442         } );
443 }( mediaWiki, jQuery ) );