3 namespace MediaWiki\Tests\Message
;
5 use MediaWiki\Message\TextFormatter
;
8 use Wikimedia\Message\MessageValue
;
9 use Wikimedia\Message\ParamType
;
10 use Wikimedia\Message\ScalarParam
;
13 * @covers \MediaWiki\Message\TextFormatter
14 * @covers \Wikimedia\Message\MessageValue
15 * @covers \Wikimedia\Message\ListParam
16 * @covers \Wikimedia\Message\ScalarParam
17 * @covers \Wikimedia\Message\MessageParam
19 class TextFormatterTest
extends MediaWikiTestCase
{
20 private function createTextFormatter( $langCode ) {
21 return new class( $langCode ) extends TextFormatter
{
22 public function __construct( $langCode ) {
23 parent
::__construct( $langCode );
26 protected function createMessage( $key ) {
27 return new FakeMessage( $key );
32 public function testGetLangCode() {
33 $formatter = $this->createTextFormatter( 'fr' );
34 $this->assertSame( 'fr', $formatter->getLangCode() );
37 public function testFormatBitrate() {
38 $formatter = $this->createTextFormatter( 'en' );
39 $mv = ( new MessageValue( 'test' ) )->bitrateParams( 100, 200 );
40 $result = $formatter->format( $mv );
41 $this->assertSame( 'test 100 bps 200 bps', $result );
44 public function testFormatList() {
45 $formatter = $this->createTextFormatter( 'en' );
46 $mv = ( new MessageValue( 'test' ) )->commaListParams( [
48 new ScalarParam( ParamType
::BITRATE
, 100 ),
50 $result = $formatter->format( $mv );
51 $this->assertSame( 'test a, 100 bps $2', $result );
55 class FakeMessage
extends Message
{
56 public function fetchMessage() {
57 return "{$this->getKey()} $1 $2";