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