Merge "Update links for software homepages"
[lhc/web/wiklou.git] / tests / phpunit / includes / MessageTest.php
index 44ca3d2..6a36b4b 100644 (file)
@@ -119,9 +119,16 @@ class MessageTest extends MediaWikiLangTestCase {
         */
        public function testInLanguage() {
                $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
-               $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
-               $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() );
-               $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
+               $this->assertEquals( 'Заглавная страница',
+                       wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
+
+               // NOTE: make sure internal caching of the message text is reset appropriately
+               $msg = wfMessage( 'mainpage' );
+               $this->assertEquals( 'Main Page', $msg->inLanguage( Language::factory( 'en' ) )->text() );
+               $this->assertEquals(
+                       'Заглавная страница',
+                       $msg->inLanguage( Language::factory( 'ru' ) )->text()
+               );
        }
 
        /**
@@ -130,8 +137,14 @@ class MessageTest extends MediaWikiLangTestCase {
        public function testMessageParams() {
                $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
                $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
-               $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
-               $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
+               $this->assertEquals(
+                       'You have foo (bar).',
+                       wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
+               );
+               $this->assertEquals(
+                       'You have foo (bar).',
+                       wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text()
+               );
        }
 
        /**
@@ -139,10 +152,22 @@ class MessageTest extends MediaWikiLangTestCase {
         * @covers Message::rawParams
         */
        public function testMessageParamSubstitution() {
-               $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses', 'Заглавная страница' )->plain() );
-               $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses', 'Заглавная страница $1' )->plain() );
-               $this->assertEquals( '(Заглавная страница)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain() );
-               $this->assertEquals( '(Заглавная страница $1)', wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain() );
+               $this->assertEquals(
+                       '(Заглавная страница)',
+                       wfMessage( 'parentheses', 'Заглавная страница' )->plain()
+               );
+               $this->assertEquals(
+                       '(Заглавная страница $1)',
+                       wfMessage( 'parentheses', 'Заглавная страница $1' )->plain()
+               );
+               $this->assertEquals(
+                       '(Заглавная страница)',
+                       wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain()
+               );
+               $this->assertEquals(
+                       '(Заглавная страница $1)',
+                       wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain()
+               );
        }
 
        /**
@@ -153,7 +178,11 @@ class MessageTest extends MediaWikiLangTestCase {
                $msg = new RawMessage( '$1$2$3$4$5$6$7$8$9$10$11$12' );
                // One less than above has placeholders
                $params = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' );
-               $this->assertEquals( 'abcdefghijka2', $msg->params( $params )->plain(), 'Params > 9 are replaced correctly' );
+               $this->assertEquals(
+                       'abcdefghijka2',
+                       $msg->params( $params )->plain(),
+                       'Params > 9 are replaced correctly'
+               );
        }
 
        /**
@@ -245,22 +274,40 @@ class MessageTest extends MediaWikiLangTestCase {
        /**
         * @covers Message::inContentLanguage
         */
-       public function testInContentLanguageDisabled() {
+       public function testInContentLanguage() {
                $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
 
-               $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' );
+               // NOTE: make sure internal caching of the message text is reset appropriately
+               $msg = wfMessage( 'mainpage' );
+               $this->assertEquals( 'Hauptseite', $msg->inLanguage( 'de' )->plain(), "inLanguage( 'de' )" );
+               $this->assertEquals( 'Main Page', $msg->inContentLanguage()->plain(), "inContentLanguage()" );
+               $this->assertEquals( 'Accueil', $msg->inLanguage( 'fr' )->plain(), "inLanguage( 'fr' )" );
        }
 
        /**
         * @covers Message::inContentLanguage
         */
-       public function testInContentLanguageEnabled() {
+       public function testInContentLanguageOverride() {
                $this->setMwGlobals( array(
                        'wgLang' => Language::factory( 'fr' ),
                        'wgForceUIMsgAsContentMsg' => array( 'mainpage' ),
                ) );
 
-               $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' );
+               // NOTE: make sure internal caching of the message text is reset appropriately.
+               // NOTE: wgForceUIMsgAsContentMsg forces the messages *current* language to be used.
+               $msg = wfMessage( 'mainpage' );
+               $this->assertEquals(
+                       'Accueil',
+                       $msg->inContentLanguage()->plain(),
+                       'inContentLanguage() with ForceUIMsg override enabled'
+               );
+               $this->assertEquals( 'Main Page', $msg->inLanguage( 'en' )->plain(), "inLanguage( 'en' )" );
+               $this->assertEquals(
+                       'Main Page',
+                       $msg->inContentLanguage()->plain(),
+                       'inContentLanguage() with ForceUIMsg override enabled'
+               );
+               $this->assertEquals( 'Hauptseite', $msg->inLanguage( 'de' )->plain(), "inLanguage( 'de' )" );
        }
 
        /**