MediaWiki
REL1_24
|
00001 <?php 00008 class LocalisationCacheTest extends MediaWikiTestCase { 00009 protected function setUp() { 00010 global $IP; 00011 00012 parent::setUp(); 00013 $this->setMwGlobals( array( 00014 'wgMessagesDirs' => array( "$IP/tests/phpunit/data/localisationcache" ), 00015 'wgExtensionMessagesFiles' => array(), 00016 'wgHooks' => array(), 00017 ) ); 00018 } 00019 00020 public function testPuralRulesFallback() { 00021 $cache = new LocalisationCache( array( 'store' => 'detect' ) ); 00022 00023 $this->assertEquals( 00024 $cache->getItem( 'ar', 'pluralRules' ), 00025 $cache->getItem( 'arz', 'pluralRules' ), 00026 'arz plural rules (undefined) fallback to ar (defined)' 00027 ); 00028 00029 $this->assertEquals( 00030 $cache->getItem( 'ar', 'compiledPluralRules' ), 00031 $cache->getItem( 'arz', 'compiledPluralRules' ), 00032 'arz compiled plural rules (undefined) fallback to ar (defined)' 00033 ); 00034 00035 $this->assertNotEquals( 00036 $cache->getItem( 'ksh', 'pluralRules' ), 00037 $cache->getItem( 'de', 'pluralRules' ), 00038 'ksh plural rules (defined) dont fallback to de (defined)' 00039 ); 00040 00041 $this->assertNotEquals( 00042 $cache->getItem( 'ksh', 'compiledPluralRules' ), 00043 $cache->getItem( 'de', 'compiledPluralRules' ), 00044 'ksh compiled plural rules (defined) dont fallback to de (defined)' 00045 ); 00046 } 00047 00048 public function testRecacheFallbacks() { 00049 $lc = new LocalisationCache( array( 'store' => 'detect' ) ); 00050 $lc->recache( 'uk' ); 00051 $this->assertEquals( 00052 array( 00053 'present-uk' => 'uk', 00054 'present-ru' => 'ru', 00055 'present-en' => 'en', 00056 ), 00057 $lc->getItem( 'uk', 'messages' ), 00058 'Fallbacks are only used to fill missing data' 00059 ); 00060 } 00061 00062 public function testRecacheFallbacksWithHooks() { 00063 global $wgHooks; 00064 00065 // Use hook to provide updates for messages. This is what the 00066 // LocalisationUpdate extension does. See bug 68781. 00067 $wgHooks['LocalisationCacheRecacheFallback'][] = function ( 00068 LocalisationCache $lc, 00069 $code, 00070 array &$cache 00071 ) { 00072 if ( $code === 'ru' ) { 00073 $cache['messages']['present-uk'] = 'ru-override'; 00074 $cache['messages']['present-ru'] = 'ru-override'; 00075 $cache['messages']['present-en'] = 'ru-override'; 00076 } 00077 }; 00078 00079 $lc = new LocalisationCache( array( 'store' => 'detect' ) ); 00080 $lc->recache( 'uk' ); 00081 $this->assertEquals( 00082 array( 00083 'present-uk' => 'uk', 00084 'present-ru' => 'ru-override', 00085 'present-en' => 'ru-override', 00086 ), 00087 $lc->getItem( 'uk', 'messages' ), 00088 'Updates provided by hooks follow the normal fallback order.' 00089 ); 00090 } 00091 }