X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMessageTest.php;h=c2acec039642decb2d98548d85fc3dbc3e80cc0e;hb=7275af4b5d8c9c68671c78ed027ae44a82cc2d39;hp=6a36b4beda69f03505910fde8b62189b9f53facf;hpb=25b73462a10fa359e917926cab49bf9bc5575ee5;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index 6a36b4beda..c2acec0396 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -317,4 +317,52 @@ class MessageTest extends MediaWikiLangTestCase { public function testInLanguageThrows() { wfMessage( 'foo' )->inLanguage( 123 ); } + + public function keyProvider() { + return array( + 'string' => array( + 'key' => 'mainpage', + 'expected' => array( 'mainpage' ), + ), + 'single' => array( + 'key' => array( 'mainpage' ), + 'expected' => array( 'mainpage' ), + ), + 'multi' => array( + 'key' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ), + 'expected' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ), + ), + 'empty' => array( + 'key' => array(), + 'expected' => null, + 'exception' => 'InvalidArgumentException', + ), + 'null' => array( + 'key' => null, + 'expected' => null, + 'exception' => 'InvalidArgumentException', + ), + 'bad type' => array( + 'key' => 17, + 'expected' => null, + 'exception' => 'InvalidArgumentException', + ), + ); + } + + /** + * @dataProvider keyProvider() + * + * @covers Message::getKey + */ + public function testGetKey( $key, $expected, $exception = null ) { + if ( $exception ) { + $this->setExpectedException( $exception ); + } + + $msg = new Message( $key ); + $this->assertEquals( $expected, $msg->getKeysToTry() ); + $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() ); + $this->assertContains( $msg->getKey(), $expected ); + } }