wiki.techinc.nl/tests/phpunit/unit/includes/language/LanguageFallbackTest.php
Fomafix 6839b85994 Step 1 of renaming sr-ec and sr-el to sr-cyrl and sr-latn
The language codes sr-ec and sr-el are not conform to BCP 47.
BCP 47 explicit mentions sr-Latn and sr-Cyrl as examples.

This change adds support for the language codes sr-cyrl and sr-latn
as fallback languages of the language codes sr-ec and sr-el. This
allows to rename the message files and the system messages without
changing the language codes yet.

The next step is to rename the language codes in Translatewiki as
described in https://translatewiki.net/wiki/Renaming_language_codes
Also local system messages in MediaWiki:*/sr-ec and MediaWiki:*/sr-el
can moved to MediaWiki:*/sr-cyrl and MediaWiki:*/sr-latn.

The final step is the change I75da0af35a2066e7963e50c56c99daf1e07c55e6
to complete the rename of the language codes.

Bug: T117845
Change-Id: I666fbdea89ccf21aab6ca1849adf22813dec052e
2022-07-10 21:19:34 +00:00

52 lines
1.3 KiB
PHP

<?php
use MediaWiki\Languages\LanguageFallback;
use MediaWiki\Languages\LanguageNameUtils;
/**
* @coversDefaultClass MediaWiki\Languages\LanguageFallback
* @covers ::__construct
*/
class LanguageFallbackTest extends MediaWikiUnitTestCase {
use LanguageFallbackTestTrait;
private const DATA = [
'en' => [],
'fr' => [],
'sco' => [ 'en' ],
'yi' => [ 'he' ],
'ruq' => [ 'ruq-latn', 'ro' ],
'sh' => [ 'bs', 'sr-el', 'sr-latn', 'hr' ],
];
private function getLanguageNameUtils() {
$mockLangNameUtils = $this->createMock( LanguageNameUtils::class );
$mockLangNameUtils->method( 'isValidBuiltInCode' )
->willReturnCallback( static function ( $code ) {
// One-line copy-paste
return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code );
} );
$mockLangNameUtils->expects( $this->never() )
->method( $this->anythingBut( 'isValidBuiltInCode' ) );
return $mockLangNameUtils;
}
private function getCallee( array $options = [] ): LanguageFallback {
return new LanguageFallback(
$options['siteLangCode'] ?? 'en',
$this->getMockLocalisationCache(
$options['expectedGets'] ?? 1,
$options['fallbackMap'] ?? self::DATA
),
$this->getLanguageNameUtils()
);
}
private function getMessagesKey() {
return LanguageFallback::MESSAGES;
}
private function getStrictKey() {
return LanguageFallback::STRICT;
}
}