MediaWiki
REL1_22
|
00001 <?php 00002 00003 class MessageTest extends MediaWikiLangTestCase { 00004 protected function setUp() { 00005 parent::setUp(); 00006 00007 $this->setMwGlobals( array( 00008 'wgLang' => Language::factory( 'en' ), 00009 'wgForceUIMsgAsContentMsg' => array(), 00010 ) ); 00011 } 00012 00013 public function testExists() { 00014 $this->assertTrue( wfMessage( 'mainpage' )->exists() ); 00015 $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() ); 00016 $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() ); 00017 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() ); 00018 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() ); 00019 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() ); 00020 } 00021 00022 public function testKey() { 00023 $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) ); 00024 $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) ); 00025 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() ); 00026 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->text() ); 00027 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->plain() ); 00028 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->escaped() ); 00029 } 00030 00031 public function testInLanguage() { 00032 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() ); 00033 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() ); 00034 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() ); 00035 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() ); 00036 } 00037 00038 public function testMessageParams() { 00039 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() ); 00040 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() ); 00041 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() ); 00042 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() ); 00043 } 00044 00045 public function testMessageParamSubstitution() { 00046 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() ); 00047 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() ); 00048 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() ); 00049 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() ); 00050 } 00051 00052 public function testDeliciouslyManyParams() { 00053 $msg = new RawMessage( '$1$2$3$4$5$6$7$8$9$10$11$12' ); 00054 // One less than above has placeholders 00055 $params = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' ); 00056 $this->assertEquals( 'abcdefghijka2', $msg->params( $params )->plain(), 'Params > 9 are replaced correctly' ); 00057 } 00058 00063 public function testMessageParamTypes() { 00064 $lang = Language::factory( 'en' ); 00065 00066 $msg = new RawMessage( '$1' ); 00067 $this->assertEquals( 00068 $lang->formatNum( 123456.789 ), 00069 $msg->inLanguage( $lang )->numParams( 123456.789 )->plain(), 00070 'numParams is handled correctly' 00071 ); 00072 00073 $msg = new RawMessage( '$1' ); 00074 $this->assertEquals( 00075 $lang->formatDuration( 1234 ), 00076 $msg->inLanguage( $lang )->durationParams( 1234 )->plain(), 00077 'durationParams is handled correctly' 00078 ); 00079 00080 $msg = new RawMessage( '$1' ); 00081 $this->assertEquals( 00082 $lang->formatExpiry( wfTimestampNow() ), 00083 $msg->inLanguage( $lang )->expiryParams( wfTimestampNow() )->plain(), 00084 'expiryParams is handled correctly' 00085 ); 00086 00087 $msg = new RawMessage( '$1' ); 00088 $this->assertEquals( 00089 $lang->formatTimePeriod( 1234 ), 00090 $msg->inLanguage( $lang )->timeperiodParams( 1234 )->plain(), 00091 'timeperiodParams is handled correctly' 00092 ); 00093 00094 $msg = new RawMessage( '$1' ); 00095 $this->assertEquals( 00096 $lang->formatSize( 123456 ), 00097 $msg->inLanguage( $lang )->sizeParams( 123456 )->plain(), 00098 'sizeParams is handled correctly' 00099 ); 00100 00101 $msg = new RawMessage( '$1' ); 00102 $this->assertEquals( 00103 $lang->formatBitrate( 123456 ), 00104 $msg->inLanguage( $lang )->bitrateParams( 123456 )->plain(), 00105 'bitrateParams is handled correctly' 00106 ); 00107 } 00108 00109 public function testInContentLanguageDisabled() { 00110 $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) ); 00111 00112 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' ); 00113 } 00114 00115 public function testInContentLanguageEnabled() { 00116 $this->setMwGlobals( array( 00117 'wgLang' => Language::factory( 'fr' ), 00118 'wgForceUIMsgAsContentMsg' => array( 'mainpage' ), 00119 ) ); 00120 00121 $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' ); 00122 } 00123 00127 public function testInLanguageThrows() { 00128 wfMessage( 'foo' )->inLanguage( 123 ); 00129 } 00130 }