3 class MessageTest
extends MediaWikiLangTestCase
{
5 function testExists() {
6 $this->assertTrue( wfMessage( 'mainpage' )->exists() );
7 $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() );
8 $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() );
9 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() );
10 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() );
11 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() );
15 $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) );
16 $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) );
17 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() );
18 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->text() );
19 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->plain() );
20 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->escaped() );
23 function testInLanguage() {
24 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
25 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
26 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language
::factory( 'en' ) )->text() );
27 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language
::factory( 'ru' ) )->text() );
30 function testMessageParams() {
31 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
32 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
33 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
34 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
37 function testMessageParamSubstitution() {
38 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() );
39 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() );
40 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() );
41 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() );
44 function testInContentLanguage() {
45 global $wgLang, $wgForceUIMsgAsContentMsg;
47 $wgLang = Language
::factory( 'fr' );
49 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' );
50 $wgForceUIMsgAsContentMsg['testInContentLanguage'] = 'mainpage';
51 $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' );
55 unset( $wgForceUIMsgAsContentMsg['testInContentLanguage'] );
59 * @expectedException MWException
61 function testInLanguageThrows() {
62 wfMessage( 'foo' )->inLanguage( 123 );