From a31c230f229c9e28438c221a6e585e7b8bf1cda6 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 29 Oct 2012 21:22:25 +0100 Subject: [PATCH 1/4] added tests for p and print_unescaped --- tests/lib/template.php | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/lib/template.php diff --git a/tests/lib/template.php b/tests/lib/template.php new file mode 100644 index 0000000000..27feec13d0 --- /dev/null +++ b/tests/lib/template.php @@ -0,0 +1,67 @@ +. +* +*/ + +require_once("lib/template.php"); + +class Test_TemplateFunctions extends UnitTestCase { + + public function testP(){ + // FIXME: do we need more testcases? + $htmlString = ""; + ob_start(); + p($htmlString); + $result = ob_get_clean(); + + $this->assertEqual($result, "<script>alert('xss');</script>"); + + ob_end_clean(); + $normalString = "This is a good string!"; + ob_start(); + p($normalString); + $result = ob_get_clean(); + + $this->assertEqual($result, "This is a good string!"); + + } + + + public function testPrintUnescaped(){ + $htmlString = ""; + + ob_start(); + print_unescaped($htmlString); + $result = ob_get_clean(); + + $this->assertEqual($result, $htmlString); + + ob_end_clean(); + $normalString = "This is a good string!"; + ob_start(); + p($normalString); + $result = ob_get_clean(); + + $this->assertEqual($result, "This is a good string!"); + + } + + +} \ No newline at end of file From f59138214735b6e0516b35d62a62a144f9b0a3e1 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 29 Oct 2012 21:33:43 +0100 Subject: [PATCH 2/4] assert in proper order --- tests/lib/template.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/lib/template.php b/tests/lib/template.php index 27feec13d0..0151ab331d 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -31,7 +31,7 @@ class Test_TemplateFunctions extends UnitTestCase { p($htmlString); $result = ob_get_clean(); - $this->assertEqual($result, "<script>alert('xss');</script>"); + $this->assertEqual("<script>alert('xss');</script>", $result); ob_end_clean(); $normalString = "This is a good string!"; @@ -39,7 +39,7 @@ class Test_TemplateFunctions extends UnitTestCase { p($normalString); $result = ob_get_clean(); - $this->assertEqual($result, "This is a good string!"); + $this->assertEqual("This is a good string!", $result); } @@ -51,7 +51,7 @@ class Test_TemplateFunctions extends UnitTestCase { print_unescaped($htmlString); $result = ob_get_clean(); - $this->assertEqual($result, $htmlString); + $this->assertEqual($htmlString, $result); ob_end_clean(); $normalString = "This is a good string!"; @@ -59,7 +59,7 @@ class Test_TemplateFunctions extends UnitTestCase { p($normalString); $result = ob_get_clean(); - $this->assertEqual($result, "This is a good string!"); + $this->assertEqual("This is a good string!", $result); } From aef3c6010b187a3e2fc018f5854770aef5f5c16a Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 30 Oct 2012 17:30:39 +0100 Subject: [PATCH 3/4] splitted two tests with two assertions each into four tests with one assertion --- tests/lib/template.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/lib/template.php b/tests/lib/template.php index 0151ab331d..3f0855de76 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -30,17 +30,19 @@ class Test_TemplateFunctions extends UnitTestCase { ob_start(); p($htmlString); $result = ob_get_clean(); + ob_end_clean(); $this->assertEqual("<script>alert('xss');</script>", $result); + } - ob_end_clean(); + public function testPNormalString(){ $normalString = "This is a good string!"; ob_start(); p($normalString); $result = ob_get_clean(); + ob_end_clean(); $this->assertEqual("This is a good string!", $result); - } @@ -50,17 +52,19 @@ class Test_TemplateFunctions extends UnitTestCase { ob_start(); print_unescaped($htmlString); $result = ob_get_clean(); + ob_end_clean(); $this->assertEqual($htmlString, $result); + } - ob_end_clean(); + public function testPrintUnescapedNormalString(){ $normalString = "This is a good string!"; ob_start(); p($normalString); $result = ob_get_clean(); + ob_end_clean(); $this->assertEqual("This is a good string!", $result); - } From 3ca5927b59ea3ef34bf9c6f49405d3263f692198 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 30 Oct 2012 21:20:21 +0100 Subject: [PATCH 4/4] fixed copy paste error. 4th test will now test print_unescaped instead of p --- tests/lib/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/template.php b/tests/lib/template.php index 3f0855de76..dadfdba5e0 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -60,7 +60,7 @@ class Test_TemplateFunctions extends UnitTestCase { public function testPrintUnescapedNormalString(){ $normalString = "This is a good string!"; ob_start(); - p($normalString); + print_unescaped($normalString); $result = ob_get_clean(); ob_end_clean(); @@ -68,4 +68,4 @@ class Test_TemplateFunctions extends UnitTestCase { } -} \ No newline at end of file +}