wiki.techinc.nl/tests/phpunit/unit/includes/language/LanguageNameUtilsTest.php
Aryeh Gregor 6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00

66 lines
1.8 KiB
PHP

<?php
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Languages\LanguageNameUtils;
class LanguageNameUtilsTest extends MediaWikiUnitTestCase {
/**
* @param array $optionsArray
*/
private static function newObj( array $optionsArray = [] ) : LanguageNameUtils {
return new LanguageNameUtils( new ServiceOptions(
LanguageNameUtils::$constructorOptions,
$optionsArray,
[
'ExtraLanguageNames' => [],
'LanguageCode' => 'en',
'UsePigLatinVariant' => false,
]
) );
}
use LanguageNameUtilsTestTrait;
private function isSupportedLanguage( $code ) {
return $this->newObj()->isSupportedLanguage( $code );
}
private function isValidCode( $code ) {
return $this->newObj()->isValidCode( $code );
}
private function isValidBuiltInCode( $code ) {
return $this->newObj()->isValidBuiltInCode( $code );
}
private function isKnownLanguageTag( $code ) {
return $this->newObj()->isKnownLanguageTag( $code );
}
private function assertGetLanguageNames( array $options, $expected, $code, ...$otherArgs ) {
$this->assertSame( $expected, $this->newObj( $options )
->getLanguageNames( ...$otherArgs )[strtolower( $code )] ?? '' );
$this->assertSame( $expected,
$this->newObj( $options )->getLanguageName( $code, ...$otherArgs ) );
}
private function getLanguageNames( ...$args ) {
return $this->newObj()->getLanguageNames( ...$args );
}
private function getLanguageName( ...$args ) {
return $this->newObj()->getLanguageName( ...$args );
}
private static function getFileName( ...$args ) {
return self::newObj()->getFileName( ...$args );
}
private static function getMessagesFileName( $code ) {
return self::newObj()->getMessagesFileName( $code );
}
private static function getJsonMessagesFileName( $code ) {
return self::newObj()->getJsonMessagesFileName( $code );
}
}