Debian Codegraph @

tests/phpunit/unit/includes/user/TempUser/LocalizedNumericSerialMappingTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\User\TempUser;
4
5 use MediaWiki\Language\Language;
6 use MediaWiki\Languages\LanguageFactory;
7 use MediaWiki\User\TempUser\LocalizedNumericSerialMapping;
8 use MediaWikiUnitTestCase;
9
10 /**
11 * @covers \MediaWiki\User\TempUser\LocalizedNumericSerialMapping
12 */
13 class LocalizedNumericSerialMappingTest extends MediaWikiUnitTestCase {
14
15 protected Language $language;
16 protected array $config;
17
18 protected function setUp(): void {
19 $this->language = $this->createMock( Language::class );
20 $this->config = [ 'language' => 'ar' ];
21 }
22
23 public function testConstruct() {
24 $languageFactory = $this->createMock( LanguageFactory::class );
25 $languageFactory->expects( $this->once() )
26 ->method( 'getLanguage' )
27 ->with( 'ar' )
28 ->willReturn( $this->language );
29
30 $map = new LocalizedNumericSerialMapping( $this->config, $languageFactory );
31 $this->assertInstanceOf( LocalizedNumericSerialMapping::class, $map );
32 }
33
34 /**
35 * Provide data for testGetSerialIdForIndex
36 * @return array
37 */
38 public static function provideGetSerialIdForIndex(): array {
39 return [
40 [
41 [ 'language' => 'ar' ],
42 10,
43 '١٠',
44 ],
45 [
46 [ 'language' => 'ar' ],
47 100,
48 '١٠٠',
49 ],
50 [
51 [ 'language' => 'ar' ],
52 1000,
53 '١٠٠٠',
54 ],
55 ];
56 }
57
58 /**
59 * @dataProvider provideGetSerialIdForIndex
60 *
61 * @param array $config
62 * @param int $id
63 * @param string $expected
64 */
65 public function testGetSerialIdForIndex( array $config, int $id, string $expected ) {
66 $languageFactory = $this->createMock( LanguageFactory::class );
67 $languageFactory->expects( $this->once() )
68 ->method( 'getLanguage' )
69 ->with( 'ar' )
70 ->willReturn( $this->language );
71
72 $map = new LocalizedNumericSerialMapping( $config, $languageFactory );
73 $this->language->expects( $this->once() )
74 ->method( 'formatNum' )
75 ->with( $id )
76 ->willReturn( $expected );
77
78 $this->assertSame( $expected, $map->getSerialIdForIndex( $id ) );
79 }
80 }