5 * @covers LocalisationCache
6 * @author Niklas Laxström
8 class LocalisationCacheTest
extends MediaWikiTestCase
{
9 protected function setUp() {
13 $this->setMwGlobals( array(
14 'wgExtensionMessagesFiles' => array(),
20 * @return PHPUnit_Framework_MockObject_MockObject|LocalisationCache
22 protected function getMockLocalisationCache() {
24 $lc = $this->getMockBuilder( 'LocalisationCache' )
25 ->setConstructorArgs( array( array( 'store' => 'detect' ) ) )
26 ->setMethods( array( 'getMessagesDirs' ) )
28 $lc->expects( $this->any() )->method( 'getMessagesDirs' )
29 ->will( $this->returnValue(
30 array( "$IP/tests/phpunit/data/localisationcache" )
36 public function testPuralRulesFallback() {
37 $cache = $this->getMockLocalisationCache();
40 $cache->getItem( 'ar', 'pluralRules' ),
41 $cache->getItem( 'arz', 'pluralRules' ),
42 'arz plural rules (undefined) fallback to ar (defined)'
46 $cache->getItem( 'ar', 'compiledPluralRules' ),
47 $cache->getItem( 'arz', 'compiledPluralRules' ),
48 'arz compiled plural rules (undefined) fallback to ar (defined)'
51 $this->assertNotEquals(
52 $cache->getItem( 'ksh', 'pluralRules' ),
53 $cache->getItem( 'de', 'pluralRules' ),
54 'ksh plural rules (defined) dont fallback to de (defined)'
57 $this->assertNotEquals(
58 $cache->getItem( 'ksh', 'compiledPluralRules' ),
59 $cache->getItem( 'de', 'compiledPluralRules' ),
60 'ksh compiled plural rules (defined) dont fallback to de (defined)'
64 public function testRecacheFallbacks() {
65 $lc = $this->getMockLocalisationCache();
73 $lc->getItem( 'uk', 'messages' ),
74 'Fallbacks are only used to fill missing data'
78 public function testRecacheFallbacksWithHooks() {
79 // Use hook to provide updates for messages. This is what the
80 // LocalisationUpdate extension does. See bug 68781.
81 $this->mergeMwGlobalArrayValue( 'wgHooks', array(
82 'LocalisationCacheRecacheFallback' => array(
84 LocalisationCache
$lc,
88 if ( $code === 'ru' ) {
89 $cache['messages']['present-uk'] = 'ru-override';
90 $cache['messages']['present-ru'] = 'ru-override';
91 $cache['messages']['present-en'] = 'ru-override';
97 $lc = $this->getMockLocalisationCache();
101 'present-uk' => 'uk',
102 'present-ru' => 'ru-override',
103 'present-en' => 'ru-override',
105 $lc->getItem( 'uk', 'messages' ),
106 'Updates provided by hooks follow the normal fallback order.'