From f6165f2794d668a420a31f7b11059dbaf1573c63 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 7 Aug 2018 16:16:21 +0100 Subject: [PATCH] Html: Add test coverage for inlineScript() This asserts current behaviour in preparation for changing it in a later commit (see T200506). Bug: T200506 Change-Id: I76fd15c32c763754d0825d02a49de3d9973c4f8f --- tests/phpunit/includes/HtmlTest.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 3c8fa25daf..dc32a6fff3 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -785,6 +785,45 @@ class HtmlTest extends MediaWikiTestCase { public function testSrcSet( $images, $expected, $message ) { $this->assertEquals( Html::srcSet( $images ), $expected, $message ); } + + public static function provideInlineScript() { + return [ + 'Empty' => [ + '', + '' + ], + 'Simple' => [ + 'EXAMPLE.label("foo");', + '' + ], + 'Ampersand' => [ + 'EXAMPLE.is(a && b);', + '' + ], + 'HTML' => [ + 'EXAMPLE.label("");', + '' + ], + 'Script closing string' => [ + 'EXAMPLE.label("");', + // Broken: First ends the script in HTML + '");/*]]>*/' + ], + 'CDATA string' => [ + 'EXAMPLE.label("&> CDATA ]]>");', + // Broken: Works in HTML, but is invalid XML. + '' + ], + ]; + } + + /** + * @dataProvider provideInlineScript + * @covers Html::inlineScript + */ + public function testInlineScript( $code, $expected ) { + $this->assertSame( Html::inlineScript( $code ), $expected ); + } } class HtmlTestValue { -- 2.20.1