Merge "RCFilters: Style the Saved Links placeholder and add a title"
[lhc/web/wiklou.git] / tests / phpunit / includes / MessageTest.php
index 2d45c2e..912bffe 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 class MessageTest extends MediaWikiLangTestCase {
 
        protected function setUp() {
@@ -214,6 +216,14 @@ class MessageTest extends MediaWikiLangTestCase {
        public function testWfMessageParams() {
                $this->assertSame( 'Return to $1.', wfMessage( 'returnto' )->text() );
                $this->assertSame( 'Return to $1.', wfMessage( 'returnto', [] )->text() );
+               $this->assertSame(
+                       'Return to 1,024.',
+                       wfMessage( 'returnto', Message::numParam( 1024 ) )->text()
+               );
+               $this->assertSame(
+                       'Return to 1,024.',
+                       wfMessage( 'returnto', [ Message::numParam( 1024 ) ] )->text()
+               );
                $this->assertSame(
                        'You have foo (bar).',
                        wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
@@ -222,6 +232,27 @@ class MessageTest extends MediaWikiLangTestCase {
                        'You have foo (bar).',
                        wfMessage( 'youhavenewmessages', [ 'foo', 'bar' ] )->text()
                );
+               $this->assertSame(
+                       'You have 1,024 (bar).',
+                       wfMessage(
+                               'youhavenewmessages',
+                               Message::numParam( 1024 ), 'bar'
+                       )->text()
+               );
+               $this->assertSame(
+                       'You have foo (2,048).',
+                       wfMessage(
+                               'youhavenewmessages',
+                               'foo', Message::numParam( 2048 )
+                       )->text()
+               );
+               $this->assertSame(
+                       'You have 1,024 (2,048).',
+                       wfMessage(
+                               'youhavenewmessages',
+                               [ Message::numParam( 1024 ), Message::numParam( 2048 ) ]
+                       )->text()
+               );
        }
 
        /**
@@ -286,14 +317,14 @@ class MessageTest extends MediaWikiLangTestCase {
                return [
                        [ '<span>foo</span>', 'parse', '<span>foo</span>', '<span>foo</span>' ],
                        [ '<span>foo</span>', 'escaped', '&lt;span&gt;foo&lt;/span&gt;',
-                         '<span>foo</span>' ],
+                               '<span>foo</span>' ],
                        [ '<span>foo</span>', 'plain', '<span>foo</span>', '<span>foo</span>' ],
                        [ '<script>alert(1)</script>', 'parse', '&lt;script&gt;alert(1)&lt;/script&gt;',
                                '&lt;script&gt;alert(1)&lt;/script&gt;' ],
                        [ '<script>alert(1)</script>', 'escaped', '&lt;script&gt;alert(1)&lt;/script&gt;',
                                '&lt;script&gt;alert(1)&lt;/script&gt;' ],
                        [ '<script>alert(1)</script>', 'plain', '<script>alert(1)</script>',
-                         '&lt;script&gt;alert(1)&lt;/script&gt;' ],
+                               '&lt;script&gt;alert(1)&lt;/script&gt;' ],
                ];
        }
 
@@ -365,6 +396,22 @@ class MessageTest extends MediaWikiLangTestCase {
                $this->assertSame( 'example &amp;', $msg->escaped() );
        }
 
+       public function testRawHtmlInMsg() {
+               global $wgParserConf;
+               $this->setMwGlobals( 'wgRawHtml', true );
+               // We have to reset the core hook registration.
+               // to register the html hook
+               MessageCache::destroyInstance();
+               $this->setMwGlobals( 'wgParser',
+                       ObjectFactory::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
+               );
+
+               $msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
+               $txt = '<span class="error">&lt;html&gt; tags cannot be' .
+                       ' used outside of normal pages.</span>';
+               $this->assertSame( $txt, $msg->parse() );
+       }
+
        /**
         * @covers Message::params
         * @covers Message::toString
@@ -419,7 +466,7 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * FIXME: This should not need database, but Language#formatExpiry does (bug 55912)
+        * FIXME: This should not need database, but Language#formatExpiry does (T57912)
         * @group Database
         * @covers Message::expiryParam
         * @covers Message::expiryParams