5 * @covers LocalisationCache
6 * @author Niklas Laxström
8 class LocalisationCacheTest
extends MediaWikiTestCase
{
9 protected function setUp() {
13 $this->setMwGlobals( array(
14 'wgMessagesDirs' => array( "$IP/tests/phpunit/data/localisationcache" ),
15 'wgExtensionMessagesFiles' => array(),
20 public function testPuralRulesFallback() {
21 $cache = new LocalisationCache( array( 'store' => 'detect' ) );
24 $cache->getItem( 'ar', 'pluralRules' ),
25 $cache->getItem( 'arz', 'pluralRules' ),
26 'arz plural rules (undefined) fallback to ar (defined)'
30 $cache->getItem( 'ar', 'compiledPluralRules' ),
31 $cache->getItem( 'arz', 'compiledPluralRules' ),
32 'arz compiled plural rules (undefined) fallback to ar (defined)'
35 $this->assertNotEquals(
36 $cache->getItem( 'ksh', 'pluralRules' ),
37 $cache->getItem( 'de', 'pluralRules' ),
38 'ksh plural rules (defined) dont fallback to de (defined)'
41 $this->assertNotEquals(
42 $cache->getItem( 'ksh', 'compiledPluralRules' ),
43 $cache->getItem( 'de', 'compiledPluralRules' ),
44 'ksh compiled plural rules (defined) dont fallback to de (defined)'
48 public function testRecacheFallbacks() {
49 $lc = new LocalisationCache( array( 'store' => 'detect' ) );
57 $lc->getItem( 'uk', 'messages' ),
58 'Fallbacks are only used to fill missing data'
62 public function testRecacheFallbacksWithHooks() {
65 // Use hook to provide updates for messages. This is what the
66 // LocalisationUpdate extension does. See bug 68781.
67 $wgHooks['LocalisationCacheRecacheFallback'][] = function (
68 LocalisationCache
$lc,
72 if ( $code === 'ru' ) {
73 $cache['messages']['present-uk'] = 'ru-override';
74 $cache['messages']['present-ru'] = 'ru-override';
75 $cache['messages']['present-en'] = 'ru-override';
79 $lc = new LocalisationCache( array( 'store' => 'detect' ) );
84 'present-ru' => 'ru-override',
85 'present-en' => 'ru-override',
87 $lc->getItem( 'uk', 'messages' ),
88 'Updates provided by hooks follow the normal fallback order.'