diff options
Diffstat (limited to 'tests/phpunit/includes/MessageTest.php')
-rw-r--r-- | tests/phpunit/includes/MessageTest.php | 29 |
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>', '<span>foo</span>', 'escaped' ], + [ '<span>foo</span>', '<span>foo</span>', 'plain' ], + [ '<script>alert(1)</script>', '<script>alert(1)</script>', 'parse' ], + [ '<script>alert(1)</script>', '<script>alert(1)</script>', '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 */ |