MediaWiki
REL1_19
|
00001 <?php 00002 00003 class MessageTest extends MediaWikiLangTestCase { 00004 00005 function testExists() { 00006 $this->assertTrue( wfMessage( 'mainpage' )->exists() ); 00007 $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() ); 00008 $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() ); 00009 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() ); 00010 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() ); 00011 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() ); 00012 } 00013 00014 function testKey() { 00015 $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) ); 00016 $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) ); 00017 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() ); 00018 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->text() ); 00019 } 00020 00021 function testInLanguage() { 00022 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() ); 00023 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() ); 00024 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() ); 00025 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() ); 00026 } 00027 00028 function testMessageParams() { 00029 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() ); 00030 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() ); 00031 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() ); 00032 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() ); 00033 } 00034 00035 function testMessageParamSubstitution() { 00036 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() ); 00037 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() ); 00038 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() ); 00039 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() ); 00040 } 00041 00042 function testInContentLanguage() { 00043 global $wgLang, $wgForceUIMsgAsContentMsg; 00044 $oldLang = $wgLang; 00045 $wgLang = Language::factory( 'fr' ); 00046 00047 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' ); 00048 $wgForceUIMsgAsContentMsg['testInContentLanguage'] = 'mainpage'; 00049 $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' ); 00050 00051 /* Restore globals */ 00052 $wgLang = $oldLang; 00053 unset( $wgForceUIMsgAsContentMsg['testInContentLanguage'] ); 00054 } 00055 00059 function testInLanguageThrows() { 00060 wfMessage( 'foo' )->inLanguage( 123 ); 00061 } 00062 }