From b216f4e071f44e6585d44de5cd4dbb0648ab0a6e Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Wed, 28 Mar 2018 13:00:27 +0200 Subject: [PATCH] Add MockMessageLocalizer This MessageLocalizer may be used in tests. By default, it sets the language for all messages to 'qqx', to make the tests independent of the $wgLanguageCode of the wiki the tests are running in. Change-Id: I7412ec49b6c0fab8146e09bb8aa599b35d88fc97 --- tests/phpunit/mocks/MockMessageLocalizer.php | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/phpunit/mocks/MockMessageLocalizer.php diff --git a/tests/phpunit/mocks/MockMessageLocalizer.php b/tests/phpunit/mocks/MockMessageLocalizer.php new file mode 100644 index 0000000000..ca0f9251af --- /dev/null +++ b/tests/phpunit/mocks/MockMessageLocalizer.php @@ -0,0 +1,53 @@ +languageCode = $languageCode; + } + + /** + * Get a Message object. + * Parameters are the same as {@link wfMessage()}. + * + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. + * @param mixed $args,... + * @return Message + */ + public function msg( $key ) { + $args = func_get_args(); + + /** @var Message $message */ + $message = call_user_func_array( 'wfMessage', $args ); + + if ( $this->languageCode !== null ) { + $message->inLanguage( $this->languageCode ); + } + + return $message; + } + +} -- 2.20.1