test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / MessageTest.php
blob0f74899f733a188407a3b737bc79e3cab009a009
1 <?php
3 class MessageTest extends MediaWikiLangTestCase {
4 protected function setUp() {
5 parent::setUp();
7 $this->setMwGlobals( array(
8 'wgLang' => Language::factory( 'en' ),
9 'wgForceUIMsgAsContentMsg' => array(),
10 ) );
13 function testExists() {
14 $this->assertTrue( wfMessage( 'mainpage' )->exists() );
15 $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() );
16 $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() );
17 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() );
18 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() );
19 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() );
22 function testKey() {
23 $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) );
24 $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) );
25 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() );
26 $this->assertEquals( '&lt;i-dont-exist-evar&gt;', wfMessage( 'i-dont-exist-evar' )->text() );
27 $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->plain() );
28 $this->assertEquals( '&lt;i-dont-exist-evar&gt;', wfMessage( 'i-dont-exist-evar' )->escaped() );
31 function testInLanguage() {
32 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
33 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
34 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() );
35 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
38 function testMessageParams() {
39 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
40 $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
41 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
42 $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
45 function testMessageParamSubstitution() {
46 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() );
47 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() );
48 $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() );
49 $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() );
52 function testDeliciouslyManyParams() {
53 $msg = new RawMessage( '$1$2$3$4$5$6$7$8$9$10$11$12' );
54 // One less than above has placeholders
55 $params = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' );
56 $this->assertEquals( 'abcdefghijka2', $msg->params( $params )->plain(), 'Params > 9 are replaced correctly' );
59 function testInContentLanguageDisabled() {
60 $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
62 $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' );
65 function testInContentLanguageEnabled() {
66 $this->setMwGlobals( array(
67 'wgLang' => Language::factory( 'fr' ),
68 'wgForceUIMsgAsContentMsg' => array( 'mainpage' ),
69 ) );
71 $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' );
74 /**
75 * @expectedException MWException
77 function testInLanguageThrows() {
78 wfMessage( 'foo' )->inLanguage( 123 );