X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMessageTest.php;h=1de9c23a367d4fdd6a1372036eeea2ead176cb96;hp=e8afb4ccee7d1a938100acff2b1cec86eaaff91e;hb=af614d2c3bebbf35e383e02bb957e41a295c159c;hpb=f9e3c2d046babc7309077816b0fe9961880f4e96 diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index e8afb4ccee..1de9c23a36 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -51,6 +51,10 @@ class MessageTest extends MediaWikiLangTestCase { [], [], ], + [ + [], + [ [] ], + ], [ [ 'foo' ], [ 'foo' ], @@ -68,19 +72,37 @@ class MessageTest extends MediaWikiLangTestCase { [ [ 'baz', 'foo' ] ], ], [ - [ 'baz', 'foo' ], + [ Message::rawParam( 'baz' ) ], + [ Message::rawParam( 'baz' ) ], + ], + [ + [ Message::rawParam( 'baz' ), 'foo' ], + [ Message::rawParam( 'baz' ), 'foo' ], + ], + [ + [ Message::rawParam( 'baz' ) ], + [ [ Message::rawParam( 'baz' ) ] ], + ], + [ + [ Message::rawParam( 'baz' ), 'foo' ], + [ [ Message::rawParam( 'baz' ), 'foo' ] ], + ], + + // Test handling of erroneous input, to detect if it changes + [ + [ [ 'baz', 'foo' ], 'hhh' ], [ [ 'baz', 'foo' ], 'hhh' ], ], [ - [ 'baz', 'foo' ], + [ [ 'baz', 'foo' ], 'hhh', [ 'ahahahahha' ] ], [ [ 'baz', 'foo' ], 'hhh', [ 'ahahahahha' ] ], ], [ - [ 'baz', 'foo' ], + [ [ 'baz', 'foo' ], [ 'ahahahahha' ] ], [ [ 'baz', 'foo' ], [ 'ahahahahha' ] ], ], [ - [ 'baz' ], + [ [ 'baz' ], [ 'ahahahahha' ] ], [ [ 'baz' ], [ 'ahahahahha' ] ], ], ]; @@ -192,6 +214,14 @@ class MessageTest extends MediaWikiLangTestCase { public function testWfMessageParams() { $this->assertSame( 'Return to $1.', wfMessage( 'returnto' )->text() ); $this->assertSame( 'Return to $1.', wfMessage( 'returnto', [] )->text() ); + $this->assertSame( + 'Return to 1,024.', + wfMessage( 'returnto', Message::numParam( 1024 ) )->text() + ); + $this->assertSame( + 'Return to 1,024.', + wfMessage( 'returnto', [ Message::numParam( 1024 ) ] )->text() + ); $this->assertSame( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() @@ -200,6 +230,27 @@ class MessageTest extends MediaWikiLangTestCase { 'You have foo (bar).', wfMessage( 'youhavenewmessages', [ 'foo', 'bar' ] )->text() ); + $this->assertSame( + 'You have 1,024 (bar).', + wfMessage( + 'youhavenewmessages', + Message::numParam( 1024 ), 'bar' + )->text() + ); + $this->assertSame( + 'You have foo (2,048).', + wfMessage( + 'youhavenewmessages', + 'foo', Message::numParam( 2048 ) + )->text() + ); + $this->assertSame( + 'You have 1,024 (2,048).', + wfMessage( + 'youhavenewmessages', + [ Message::numParam( 1024 ), Message::numParam( 2048 ) ] + )->text() + ); } /** @@ -512,6 +563,108 @@ class MessageTest extends MediaWikiLangTestCase { ); } + public static function provideListParam() { + $lang = Language::factory( 'de' ); + $msg1 = new Message( 'mainpage', [], $lang ); + $msg2 = new RawMessage( "''link''", [], $lang ); + + return [ + 'Simple comma list' => [ + [ 'a', 'b', 'c' ], + 'comma', + 'text', + 'a, b, c' + ], + + 'Simple semicolon list' => [ + [ 'a', 'b', 'c' ], + 'semicolon', + 'text', + 'a; b; c' + ], + + 'Simple pipe list' => [ + [ 'a', 'b', 'c' ], + 'pipe', + 'text', + 'a | b | c' + ], + + 'Simple text list' => [ + [ 'a', 'b', 'c' ], + 'text', + 'text', + 'a, b and c' + ], + + 'Empty list' => [ + [], + 'comma', + 'text', + '' + ], + + 'List with all "before" params, ->text()' => [ + [ "''link''", Message::numParam( 12345678 ) ], + 'semicolon', + 'text', + '\'\'link\'\'; 12,345,678' + ], + + 'List with all "before" params, ->parse()' => [ + [ "''link''", Message::numParam( 12345678 ) ], + 'semicolon', + 'parse', + 'link; 12,345,678' + ], + + 'List with all "after" params, ->text()' => [ + [ $msg1, $msg2, Message::rawParam( '[[foo]]' ) ], + 'semicolon', + 'text', + 'Main Page; \'\'link\'\'; [[foo]]' + ], + + 'List with all "after" params, ->parse()' => [ + [ $msg1, $msg2, Message::rawParam( '[[foo]]' ) ], + 'semicolon', + 'parse', + 'Main Page; link; [[foo]]' + ], + + 'List with both "before" and "after" params, ->text()' => [ + [ $msg1, $msg2, Message::rawParam( '[[foo]]' ), "''link''", Message::numParam( 12345678 ) ], + 'semicolon', + 'text', + 'Main Page; \'\'link\'\'; [[foo]]; \'\'link\'\'; 12,345,678' + ], + + 'List with both "before" and "after" params, ->parse()' => [ + [ $msg1, $msg2, Message::rawParam( '[[foo]]' ), "''link''", Message::numParam( 12345678 ) ], + 'semicolon', + 'parse', + 'Main Page; link; [[foo]]; link; 12,345,678' + ], + ]; + } + + /** + * @covers Message::listParam + * @covers Message::extractParam + * @covers Message::formatListParam + * @dataProvider provideListParam + */ + public function testListParam( $list, $type, $format, $expect ) { + $lang = Language::factory( 'en' ); + + $msg = new RawMessage( '$1' ); + $msg->params( [ Message::listParam( $list, $type ) ] ); + $this->assertEquals( + $expect, + $msg->inLanguage( $lang )->$format() + ); + } + /** * @covers Message::extractParam */