Fix the old XmlTest.php test bug in the dateMenu() when the wiki is configured for...
[lhc/web/wiklou.git] / tests / phpunit / includes / MessageTest.php
1 <?php
2
3 class MessageTest extends MediaWikiLangTestCase {
4
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() );
12 }
13
14 function testKey() {
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( '&lt;i-dont-exist-evar&gt;', wfMessage( 'i-dont-exist-evar' )->text() );
19 }
20
21 function testInLanguage() {
22 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
23 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
24 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() );
25 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
26 }
27
28 function testMessageParams() {
29 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
30 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
31 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
32 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
33 }
34
35 function testMessageParamSubstitution() {
36 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() );
37 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() );
38 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() );
39 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() );
40
41 }
42
43 /**
44 * @expectedException MWException
45 */
46 function testInLanguageThrows() {
47 wfMessage( 'foo' )->inLanguage( 123 );
48 }
49 }