89021ddfacc94a75d97a70fa7795824fe0dff6e2
7 class MessageCacheTest
extends MediaWikiLangTestCase
{
9 protected function setUp() {
11 MessageCache
::singleton()->enable();
14 function addDBData() {
15 // Set up messages and fallbacks ab -> ru -> en
16 $this->makePage( 'FallbackLanguageTest-Full', 'ab' );
17 $this->makePage( 'FallbackLanguageTest-Full', 'ru' );
18 $this->makePage( 'FallbackLanguageTest-Full', 'en' );
20 // Fallbacks where ab does not exist
21 $this->makePage( 'FallbackLanguageTest-Partial', 'ru' );
22 $this->makePage( 'FallbackLanguageTest-Partial', 'en' );
24 // Fallback to english
25 $this->makePage( 'FallbackLanguageTest-English', 'en' );
27 // Full key tests -- always want russian
28 $this->makePage( 'MessageCacheTest-FullKeyTest', 'ab' );
29 $this->makePage( 'MessageCacheTest-FullKeyTest', 'ru' );
33 * Helper function for addDBData -- adds a simple page to the database
35 * @param string $title Title of page to be created
36 * @param string $lang Language and content of the created page
38 protected function makePage( $title, $lang ) {
41 $title = Title
::newFromText(
42 ($lang == $wgContLang->getCode()) ?
$title : "$title/$lang",
45 $wikiPage = new WikiPage( $title );
46 $content = ContentHandler
::makeContent( $lang, $title );
47 $wikiPage->doEditContent( $content, "$lang translation test case" );
51 * Test message fallbacks, bug #1495
53 * @dataProvider provideMessagesForFallback
55 function testMessageFallbacks( $message, $lang, $expectedContent ) {
56 $result = MessageCache
::singleton()->get( $message, true, $lang );
57 $this->assertEquals( $expectedContent, $result, "Message fallback failed." );
60 function provideMessagesForFallback() {
62 array( 'FallbackLanguageTest-Full', 'ab', 'ab' ),
63 array( 'FallbackLanguageTest-Partial', 'ab', 'ru' ),
64 array( 'FallbackLanguageTest-English', 'ab', 'en' ),
65 array( 'FallbackLanguageTest-None', 'ab', false ),
70 * There's a fallback case where the message key is given as fully qualified -- this
71 * should ignore the passed $lang and use the language from the key
73 * @dataProvider provideMessagesForFullKeys
75 function testFullKeyBehaviour( $message, $lang, $expectedContent ) {
76 $result = MessageCache
::singleton()->get( $message, true, $lang, true );
77 $this->assertEquals( $expectedContent, $result, "Full key message fallback failed." );
80 function provideMessagesForFullKeys() {
82 array( 'MessageCacheTest-FullKeyTest/ru', 'ru', 'ru' ),
83 array( 'MessageCacheTest-FullKeyTest/ru', 'ab', 'ru' ),
84 array( 'MessageCacheTest-FullKeyTest/ru/foo', 'ru', false ),