resourceloader: Restore test case for ResourceLoaderImage
Follows-up 043d88f680 which had to disable this due to changes
in Language.php internals.
Change-Id: I5272142a8291449619bbcad8c99c751bdc51d757
This commit is contained in:
parent
e8a58a3356
commit
3ef19d20fb
2 changed files with 23 additions and 9 deletions
|
|
@ -18,6 +18,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Languages\LanguageFallback;
|
||||
use MediaWiki\Shell\Shell;
|
||||
|
||||
/**
|
||||
|
|
@ -141,6 +143,17 @@ class ResourceLoaderImage {
|
|||
return array_keys( $this->variants );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal For unit testing overrride
|
||||
* @param string $lang
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getLangFallbacks( string $lang ) : array {
|
||||
return MediaWikiServices::getInstance()
|
||||
->getLanguageFallback()
|
||||
->getAll( $lang, LanguageFallback::STRICT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to image file for given context.
|
||||
*
|
||||
|
|
@ -158,7 +171,7 @@ class ResourceLoaderImage {
|
|||
if ( isset( $desc['lang'][$contextLang] ) ) {
|
||||
return $this->getLocalPath( $desc['lang'][$contextLang] );
|
||||
}
|
||||
$fallbacks = Language::getFallbacksFor( $contextLang, Language::STRICT_FALLBACKS );
|
||||
$fallbacks = $this->getLangFallbacks( $contextLang );
|
||||
foreach ( $fallbacks as $lang ) {
|
||||
if ( isset( $desc['lang'][$lang] ) ) {
|
||||
return $this->getLocalPath( $desc['lang'][$lang] );
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
|
|||
* @dataProvider provideGetPath
|
||||
*/
|
||||
public function testGetPath( $imageName, $languageCode, $path ) {
|
||||
$this->markTestSkipped( 'Depends on overriding LanguageFallback/LocalisationCache' );
|
||||
static $dirMap = [
|
||||
'en' => 'ltr',
|
||||
'en-gb' => 'ltr',
|
||||
|
|
@ -70,13 +69,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
|
|||
);
|
||||
$context->setLanguage( $languageCode );
|
||||
$context->setDirection( $dirMap[$languageCode] );
|
||||
Language::$dataCache = $this->createMock( LocalisationCache::class );
|
||||
Language::$dataCache->method( 'getItem' )->will( $this->returnCallback( function ( $code ) {
|
||||
return ( [
|
||||
'en-gb' => [ 'en' ],
|
||||
'de-formal' => [ 'de' ],
|
||||
] )[ $code ] ?? [];
|
||||
} ) );
|
||||
|
||||
$this->assertEquals( $image->getPath( $context ), $this->imagesPath . '/' . $path );
|
||||
}
|
||||
|
|
@ -121,6 +113,11 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
class ResourceLoaderImageTestable extends ResourceLoaderImage {
|
||||
private $mockFallbacks = [
|
||||
'en-gb' => [ 'en' ],
|
||||
'de-formal' => [ 'de' ],
|
||||
];
|
||||
|
||||
// Make some protected methods public
|
||||
public function massageSvgPathdata( $svg ) {
|
||||
return parent::massageSvgPathdata( $svg );
|
||||
|
|
@ -130,4 +127,8 @@ class ResourceLoaderImageTestable extends ResourceLoaderImage {
|
|||
public function rasterize( $svg ) {
|
||||
return 'RASTERIZESTUB';
|
||||
}
|
||||
|
||||
protected function getLangFallbacks( string $code ) : array {
|
||||
return $this->mockFallbacks[$code] ?? [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue