Merge "Use PHPUnit 4/6 compat in VersionCheckerTest"
[lhc/web/wiklou.git] / tests / phpunit / includes / MessageTest.php
index 424218e..70f4af9 100644 (file)
@@ -1,5 +1,11 @@
 <?php
 
+use Wikimedia\ObjectFactory;
+use Wikimedia\TestingAccessWrapper;
+
+/**
+ * @group Database
+ */
 class MessageTest extends MediaWikiLangTestCase {
 
        protected function setUp() {
@@ -22,7 +28,7 @@ class MessageTest extends MediaWikiLangTestCase {
                $this->assertSame( $params, $message->getParams() );
                $this->assertEquals( $expectedLang, $message->getLanguage() );
 
-               $messageSpecifier = $this->getMockForAbstractClass( 'MessageSpecifier' );
+               $messageSpecifier = $this->getMockForAbstractClass( MessageSpecifier::class );
                $messageSpecifier->expects( $this->any() )
                        ->method( 'getKey' )->will( $this->returnValue( $key ) );
                $messageSpecifier->expects( $this->any() )
@@ -195,16 +201,16 @@ class MessageTest extends MediaWikiLangTestCase {
         * @covers ::wfMessage
         */
        public function testWfMessage() {
-               $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) );
-               $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) );
+               $this->assertInstanceOf( Message::class, wfMessage( 'mainpage' ) );
+               $this->assertInstanceOf( Message::class, wfMessage( 'i-dont-exist-evar' ) );
        }
 
        /**
         * @covers Message::newFromKey
         */
        public function testNewFromKey() {
-               $this->assertInstanceOf( 'Message', Message::newFromKey( 'mainpage' ) );
-               $this->assertInstanceOf( 'Message', Message::newFromKey( 'i-dont-exist-evar' ) );
+               $this->assertInstanceOf( Message::class, Message::newFromKey( 'mainpage' ) );
+               $this->assertInstanceOf( Message::class, Message::newFromKey( 'i-dont-exist-evar' ) );
        }
 
        /**
@@ -394,6 +400,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
@@ -449,7 +471,6 @@ class MessageTest extends MediaWikiLangTestCase {
 
        /**
         * FIXME: This should not need database, but Language#formatExpiry does (T57912)
-        * @group Database
         * @covers Message::expiryParam
         * @covers Message::expiryParams
         */
@@ -792,7 +813,7 @@ class MessageTest extends MediaWikiLangTestCase {
                $msg = unserialize( serialize( $msg ) );
                $this->assertSame( '(<a>foo</a>)', $msg->parse() );
                $title = TestingAccessWrapper::newFromObject( $msg )->title;
-               $this->assertInstanceOf( 'Title', $title );
+               $this->assertInstanceOf( Title::class, $title );
                $this->assertSame( 'Testing', $title->getFullText() );
 
                $msg = new Message( 'mainpage' );