X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2Fcache%2FLocalisationCacheTest.php;h=39526fb9c738055fbd9524ac9059675d2e0eaf20;hb=a158a4fb32b57027f0dece321e4c18af4687454d;hp=697eb2dc817b215f1fa1e1d64514550000bc3c48;hpb=1e3c2e5904d628c001a8d65909b135ea9bf042aa;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/cache/LocalisationCacheTest.php b/tests/phpunit/includes/cache/LocalisationCacheTest.php index 697eb2dc81..39526fb9c7 100644 --- a/tests/phpunit/includes/cache/LocalisationCacheTest.php +++ b/tests/phpunit/includes/cache/LocalisationCacheTest.php @@ -1,4 +1,9 @@ getMockBuilder( 'LocalisationCache' ) - ->setConstructorArgs( [ [ 'store' => 'detect' ] ] ) + + $mockLangNameUtils = $this->createMock( LanguageNameUtils::class ); + $mockLangNameUtils->method( 'isValidBuiltInCode' )->will( $this->returnCallback( + function ( $code ) { + // Copy-paste, but it's only one line + return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code ); + } + ) ); + $mockLangNameUtils->method( 'isSupportedLanguage' )->will( $this->returnCallback( + function ( $code ) { + return in_array( $code, [ + 'ar', + 'arz', + 'ba', + 'de', + 'en', + 'ksh', + 'ru', + ] ); + } + ) ); + $mockLangNameUtils->method( 'getMessagesFileName' )->will( $this->returnCallback( + function ( $code ) { + global $IP; + $code = str_replace( '-', '_', ucfirst( $code ) ); + return "$IP/languages/messages/Messages$code.php"; + } + ) ); + $mockLangNameUtils->expects( $this->never() )->method( $this->anythingBut( + 'isValidBuiltInCode', 'isSupportedLanguage', 'getMessagesFileName' + ) ); + + $lc = $this->getMockBuilder( LocalisationCache::class ) + ->setConstructorArgs( [ + new ServiceOptions( LocalisationCache::$constructorOptions, [ + 'forceRecache' => false, + 'manualRecache' => false, + 'ExtensionMessagesFiles' => [], + 'MessagesDirs' => [], + ] ), + new LCStoreDB( [] ), + new NullLogger, + [], + $mockLangNameUtils + ] ) ->setMethods( [ 'getMessagesDirs' ] ) ->getMock(); $lc->expects( $this->any() )->method( 'getMessagesDirs' ) @@ -31,7 +79,7 @@ class LocalisationCacheTest extends MediaWikiTestCase { return $lc; } - public function testPuralRulesFallback() { + public function testPluralRulesFallback() { $cache = $this->getMockLocalisationCache(); $this->assertEquals( @@ -61,21 +109,21 @@ class LocalisationCacheTest extends MediaWikiTestCase { public function testRecacheFallbacks() { $lc = $this->getMockLocalisationCache(); - $lc->recache( 'uk' ); + $lc->recache( 'ba' ); $this->assertEquals( [ - 'present-uk' => 'uk', + 'present-ba' => 'ba', 'present-ru' => 'ru', 'present-en' => 'en', ], - $lc->getItem( 'uk', 'messages' ), + $lc->getItem( 'ba', 'messages' ), 'Fallbacks are only used to fill missing data' ); } public function testRecacheFallbacksWithHooks() { // Use hook to provide updates for messages. This is what the - // LocalisationUpdate extension does. See bug 68781. + // LocalisationUpdate extension does. See T70781. $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'LocalisationCacheRecacheFallback' => [ function ( @@ -84,7 +132,7 @@ class LocalisationCacheTest extends MediaWikiTestCase { array &$cache ) { if ( $code === 'ru' ) { - $cache['messages']['present-uk'] = 'ru-override'; + $cache['messages']['present-ba'] = 'ru-override'; $cache['messages']['present-ru'] = 'ru-override'; $cache['messages']['present-en'] = 'ru-override'; } @@ -93,14 +141,14 @@ class LocalisationCacheTest extends MediaWikiTestCase { ] ); $lc = $this->getMockLocalisationCache(); - $lc->recache( 'uk' ); + $lc->recache( 'ba' ); $this->assertEquals( [ - 'present-uk' => 'uk', + 'present-ba' => 'ba', 'present-ru' => 'ru-override', 'present-en' => 'ru-override', ], - $lc->getItem( 'uk', 'messages' ), + $lc->getItem( 'ba', 'messages' ), 'Updates provided by hooks follow the normal fallback order.' ); }