Split some Language methods to LanguageNameUtils
[lhc/web/wiklou.git] / tests / phpunit / includes / cache / LocalisationCacheTest.php
index 5eed01c..4dd819a 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+
+use MediaWiki\Config\ServiceOptions;
+use MediaWiki\Languages\LanguageNameUtils;
+use Psr\Log\NullLogger;
+
 /**
  * @group Database
  * @group Cache
@@ -19,8 +24,51 @@ class LocalisationCacheTest extends MediaWikiTestCase {
         */
        protected function getMockLocalisationCache() {
                global $IP;
-               $lc = $this->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::CONSTRUCTOR_OPTIONS, [
+                                       '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(