From b0b0973e2dce0f430639aaf73b0fc538e1df44ab Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 2 Jul 2023 19:12:09 +0200 Subject: unit tests: Cosmetic fixes in AntiXSSTest.php - Start comments with capital letter - Fix indentation - Add missing doc comments --- tests/unit/AntiXSSTest.php | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'tests/unit/AntiXSSTest.php') diff --git a/tests/unit/AntiXSSTest.php b/tests/unit/AntiXSSTest.php index 09642726f..f4ee984bc 100644 --- a/tests/unit/AntiXSSTest.php +++ b/tests/unit/AntiXSSTest.php @@ -1,6 +1,6 @@ '; @@ -24,28 +24,30 @@ class AntiXSSTest extends TestCase { $this->assertEquals("<submit type="button" onclick="alert('failed!');" />", $escapedString); } - /** - * @dataProvider urlTestProvider - */ - public function testEscapeURL($url, $expected) : void { - $this->assertEquals($expected, escape_url($url)); - } - - public function urlTestProvider() : array { - return [ - [ - "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'>", - "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'><script>alert('boom')</script>" - ], - [ - "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='", - "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='" - ], - ]; - } + /** + * Test escaping URL's to make them safe for use in html and attributes. + * + * @dataProvider urlTestProvider + */ + public function testEscapeURL($url, $expected) : void { + $this->assertEquals($expected, escape_url($url)); + } + + public function urlTestProvider() : array { + return [ + [ + "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'>", + "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'><script>alert('boom')</script>" + ], + [ + "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='", + "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='" + ], + ]; + } /** - *xmlify and unxmlify + * Test xmlify and unxmlify */ public function testXmlify() { $text="I want to break\n this!11!"; @@ -56,7 +58,7 @@ class AntiXSSTest extends TestCase { } /** - * xmlify and put in a document + * Test xmlify and put in a document */ public function testXmlifyDocument() { $tag="I want to break"; @@ -65,7 +67,9 @@ class AntiXSSTest extends TestCase { $xml_parser=xml_parser_create(); //should be possible to parse it - $values=array(); $index=array(); + $values=array(); + $index=array(); + $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index)); $this->assertEquals(array('TEXT'=>array(0)), @@ -77,7 +81,7 @@ class AntiXSSTest extends TestCase { } /** - * test hex2bin and reverse + * Test hex2bin and reverse */ public function testHex2Bin() { $this->assertEquals(-3, hex2bin(bin2hex(-3))); -- cgit v1.2.3