<?php
+use Wikimedia\TestingAccessWrapper;
+
+/**
+ * @group Database
+ */
class MessageTest extends MediaWikiLangTestCase {
protected function setUp() {
$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() )
* @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' ) );
}
/**
$this->assertSame( 'example &', $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"><html> tags cannot be' .
+ ' used outside of normal pages.</span>';
+ $this->assertSame( $txt, $msg->parse() );
+ }
+
/**
* @covers Message::params
* @covers Message::toString
/**
* FIXME: This should not need database, but Language#formatExpiry does (T57912)
- * @group Database
* @covers Message::expiryParam
* @covers Message::expiryParams
*/
$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' );