wiki.techinc.nl/tests/phpunit/unit/includes/language/LanguageFallbackTest.php
Reedy ead6b1e53f Fix some PSR12.Properties.ConstantVisibility.NotFound in tests/phpunit/
Change-Id: I0f678049dc274f0cd29f543bb293c33da51d8529
2020-05-09 23:55:09 +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', 'hr' ],
];
private function getLanguageNameUtils() {
$mockLangNameUtils = $this->createMock( LanguageNameUtils::class );
$mockLangNameUtils->method( 'isValidBuiltInCode' )
->will( $this->returnCallback( 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;
}
}