summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2014-04-24 15:45:07 +0200
committerAndreas Fischer <bantu@owncloud.com>2014-04-24 15:45:07 +0200
commitf45080e8116bc06a95c5ff2b2bfa92029fdb2590 (patch)
treea6ebb9b184b97730cf06059e135db0a3095ad928 /tests
parent88778b569e73dd2319c547be53df6aab6b8fa667 (diff)
downloadnextcloud-server-f45080e8116bc06a95c5ff2b2bfa92029fdb2590.tar.gz
nextcloud-server-f45080e8116bc06a95c5ff2b2bfa92029fdb2590.zip
Use PHPUnit's expectOutputString() instead of performing output buffering.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/template.php37
1 files changed, 11 insertions, 26 deletions
diff --git a/tests/lib/template.php b/tests/lib/template.php
index 299eb2b9369..eedf688721d 100644
--- a/tests/lib/template.php
+++ b/tests/lib/template.php
@@ -28,46 +28,31 @@ class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
}
public function testPJavaScript() {
- $badString = '<img onload="alert(1)" />';
- ob_start();
- p($badString);
- $result = ob_get_clean();
- $this->assertEquals('&lt;img onload=&quot;alert(1)&quot; /&gt;', $result);
+ $this->expectOutputString('&lt;img onload=&quot;alert(1)&quot; /&gt;');
+ p('<img onload="alert(1)" />');
}
public function testPJavaScriptWithScriptTags() {
- $badString = "<script>alert('Hacked!');</script>";
- ob_start();
- p($badString);
- $result = ob_get_clean();
- $this->assertEquals('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;', $result);
+ $this->expectOutputString('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;');
+ p("<script>alert('Hacked!');</script>");
}
public function testPNormalString() {
- $goodString = 'This is a good string without HTML.';
- ob_start();
- p($goodString);
- $result = ob_get_clean();
- $this->assertEquals('This is a good string without HTML.', $result);
+ $string = 'This is a good string without HTML.';
+ $this->expectOutputString($string);
+ p($string);
}
public function testPrintUnescaped() {
$htmlString = "<script>alert('xss');</script>";
-
- ob_start();
+ $this->expectOutputString($htmlString);
print_unescaped($htmlString);
- $result = ob_get_clean();
-
- $this->assertEquals($htmlString, $result);
}
public function testPrintUnescapedNormalString() {
- $normalString = "This is a good string!";
- ob_start();
- print_unescaped($normalString);
- $result = ob_get_clean();
-
- $this->assertEquals("This is a good string!", $result);
+ $string = 'This is a good string!';
+ $this->expectOutputString($string);
+ print_unescaped($string);
}
// ---------------------------------------------------------------------------