1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
/**
* @group Database
* @group Cache
* @covers LocalisationCache
* @author Niklas Laxström
*/
class LocalisationCacheTest extends MediaWikiTestCase {
protected function setUp() {
global $IP;
parent::setUp();
$this->setMwGlobals( array(
'wgMessagesDirs' => array( "$IP/tests/phpunit/data/localisationcache" ),
'wgExtensionMessagesFiles' => array(),
'wgHooks' => array(),
) );
}
public function testPuralRulesFallback() {
$cache = new LocalisationCache( array( 'store' => 'detect' ) );
$this->assertEquals(
$cache->getItem( 'ar', 'pluralRules' ),
$cache->getItem( 'arz', 'pluralRules' ),
'arz plural rules (undefined) fallback to ar (defined)'
);
$this->assertEquals(
$cache->getItem( 'ar', 'compiledPluralRules' ),
$cache->getItem( 'arz', 'compiledPluralRules' ),
'arz compiled plural rules (undefined) fallback to ar (defined)'
);
$this->assertNotEquals(
$cache->getItem( 'ksh', 'pluralRules' ),
$cache->getItem( 'de', 'pluralRules' ),
'ksh plural rules (defined) dont fallback to de (defined)'
);
$this->assertNotEquals(
$cache->getItem( 'ksh', 'compiledPluralRules' ),
$cache->getItem( 'de', 'compiledPluralRules' ),
'ksh compiled plural rules (defined) dont fallback to de (defined)'
);
}
public function testRecacheFallbacks() {
$lc = new LocalisationCache( array( 'store' => 'detect' ) );
$lc->recache( 'uk' );
$this->assertEquals(
array(
'present-uk' => 'uk',
'present-ru' => 'ru',
'present-en' => 'en',
),
$lc->getItem( 'uk', 'messages' ),
'Fallbacks are only used to fill missing data'
);
}
public function testRecacheFallbacksWithHooks() {
global $wgHooks;
// Use hook to provide updates for messages. This is what the
// LocalisationUpdate extension does. See bug 68781.
$wgHooks['LocalisationCacheRecacheFallback'][] = function (
LocalisationCache $lc,
$code,
array &$cache
) {
if ( $code === 'ru' ) {
$cache['messages']['present-uk'] = 'ru-override';
$cache['messages']['present-ru'] = 'ru-override';
$cache['messages']['present-en'] = 'ru-override';
}
};
$lc = new LocalisationCache( array( 'store' => 'detect' ) );
$lc->recache( 'uk' );
$this->assertEquals(
array(
'present-uk' => 'uk',
'present-ru' => 'ru-override',
'present-en' => 'ru-override',
),
$lc->getItem( 'uk', 'messages' ),
'Updates provided by hooks follow the normal fallback order.'
);
}
}
|