This commit refactors the LocalizedNumericSerialMappingTest to make use of mocks for Language and LanguageFactory. Introduced a data provider for comprehensive testing of getSerialIdForIndex with various scenarios. Added testConstruct to verify constructor functionality and LanguageFactory integration. This refactor changes the base test class from MediaWikiIntegrationTestCase to MediaWikiUnitTestCase, shifting focus to unit testing. Change-Id: I00d80d0a1d6d0bb8f7fc5c6e7c6fa4732ef04abb
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
||
|
||
namespace MediaWiki\Tests\User\TempUser;
|
||
|
||
use Language;
|
||
use MediaWiki\Languages\LanguageFactory;
|
||
use MediaWiki\User\TempUser\LocalizedNumericSerialMapping;
|
||
use MediaWikiUnitTestCase;
|
||
|
||
/**
|
||
* @covers \MediaWiki\User\TempUser\LocalizedNumericSerialMapping
|
||
*/
|
||
class LocalizedNumericSerialMappingTest extends MediaWikiUnitTestCase {
|
||
|
||
protected Language $language;
|
||
protected array $config;
|
||
|
||
protected function setUp(): void {
|
||
$this->language = $this->createMock( Language::class );
|
||
$this->config = [ 'language' => 'ar' ];
|
||
}
|
||
|
||
public function testConstruct() {
|
||
$languageFactory = $this->createMock( LanguageFactory::class );
|
||
$languageFactory->expects( $this->once() )
|
||
->method( 'getLanguage' )
|
||
->with( 'ar' )
|
||
->willReturn( $this->language );
|
||
|
||
$map = new LocalizedNumericSerialMapping( $this->config, $languageFactory );
|
||
$this->assertInstanceOf( LocalizedNumericSerialMapping::class, $map );
|
||
}
|
||
|
||
/**
|
||
* Provide data for testGetSerialIdForIndex
|
||
* @return array
|
||
*/
|
||
public static function provideGetSerialIdForIndex(): array {
|
||
return [
|
||
[
|
||
[ 'language' => 'ar' ],
|
||
10,
|
||
'١٠',
|
||
],
|
||
[
|
||
[ 'language' => 'ar' ],
|
||
100,
|
||
'١٠٠',
|
||
],
|
||
[
|
||
[ 'language' => 'ar' ],
|
||
1000,
|
||
'١٠٠٠',
|
||
],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @dataProvider provideGetSerialIdForIndex
|
||
*
|
||
* @param array $config
|
||
* @param int $id
|
||
* @param string $expected
|
||
*/
|
||
public function testGetSerialIdForIndex( array $config, int $id, string $expected ) {
|
||
$languageFactory = $this->createMock( LanguageFactory::class );
|
||
$languageFactory->expects( $this->once() )
|
||
->method( 'getLanguage' )
|
||
->with( 'ar' )
|
||
->willReturn( $this->language );
|
||
|
||
$map = new LocalizedNumericSerialMapping( $config, $languageFactory );
|
||
$this->language->expects( $this->once() )
|
||
->method( 'formatNum' )
|
||
->with( $id )
|
||
->willReturn( $expected );
|
||
|
||
$this->assertSame( $expected, $map->getSerialIdForIndex( $id ) );
|
||
}
|
||
}
|