aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/MessageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/MessageTest.php')
-rw-r--r--tests/phpunit/includes/MessageTest.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php
index 4c689abb0410..9b9a73a88652 100644
--- a/tests/phpunit/includes/MessageTest.php
+++ b/tests/phpunit/includes/MessageTest.php
@@ -256,6 +256,35 @@ class MessageTest extends MediaWikiLangTestCase {
$this->assertEquals( $expect, $msg->__toString() );
}
+ public static function provideToString_raw() {
+ return [
+ [ '<span>foo</span>', '<span>foo</span>', 'parse' ],
+ [ '<span>foo</span>', '&lt;span&gt;foo&lt;/span&gt;', 'escaped' ],
+ [ '<span>foo</span>', '<span>foo</span>', 'plain' ],
+ [ '<script>alert(1)</script>', '&lt;script&gt;alert(1)&lt;/script&gt;', 'parse' ],
+ [ '<script>alert(1)</script>', '&lt;script&gt;alert(1)&lt;/script&gt;', 'escaped' ],
+ [ '<script>alert(1)</script>', '<script>alert(1)</script>', 'plain' ],
+ ];
+ }
+
+ /**
+ * @covers Message::toString
+ * @covers Message::__toString
+ * @dataProvider provideToString_raw
+ */
+ public function testToString_raw( $key, $expect, $format ) {
+ // make the message behave like RawMessage and use the key as-is
+ $msg = $this->getMockBuilder( Message::class )->setMethods( [ 'fetchMessage' ] )
+ ->setConstructorArgs( [ $key ] )
+ ->getMock();
+ $msg->expects( $this->any() )->method( 'fetchMessage' )->willReturn( $key );
+ /** @var Message $msg */
+ $msg->$format();
+ $this->assertEquals( $expect, $msg->toString() );
+ $this->assertEquals( $expect, $msg->__toString() );
+ $this->assertEquals( $expect, $msg->toString() );
+ }
+
/**
* @covers Message::inLanguage
*/