From a31c230f229c9e28438c221a6e585e7b8bf1cda6 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 29 Oct 2012 21:22:25 +0100 Subject: added tests for p and print_unescaped --- tests/lib/template.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/lib/template.php (limited to 'tests/lib') diff --git a/tests/lib/template.php b/tests/lib/template.php new file mode 100644 index 00000000000..27feec13d04 --- /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 -- cgit v1.2.3 From f59138214735b6e0516b35d62a62a144f9b0a3e1 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 29 Oct 2012 21:33:43 +0100 Subject: assert in proper order --- tests/lib/template.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/lib') diff --git a/tests/lib/template.php b/tests/lib/template.php index 27feec13d04..0151ab331d1 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); } -- cgit v1.2.3 From aef3c6010b187a3e2fc018f5854770aef5f5c16a Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 30 Oct 2012 17:30:39 +0100 Subject: 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(-) (limited to 'tests/lib') diff --git a/tests/lib/template.php b/tests/lib/template.php index 0151ab331d1..3f0855de76c 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); - } -- cgit v1.2.3 From 3ca5927b59ea3ef34bf9c6f49405d3263f692198 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 30 Oct 2012 21:20:21 +0100 Subject: 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(-) (limited to 'tests/lib') diff --git a/tests/lib/template.php b/tests/lib/template.php index 3f0855de76c..dadfdba5e0c 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 +} -- cgit v1.2.3 From dca80c55a9c12ccbe1def5ce7cbeae7974525c13 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Wed, 31 Oct 2012 00:21:17 +0100 Subject: fixing Test_TemplateFunctions --- tests/lib/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/lib') diff --git a/tests/lib/template.php b/tests/lib/template.php index dadfdba5e0c..d6d5a122f42 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -20,7 +20,7 @@ * */ -require_once("lib/template.php"); +require_once("../lib/template.php"); class Test_TemplateFunctions extends UnitTestCase { -- cgit v1.2.3