Merge pull request #8341 from owncloud/template-tests-output-buffering

Improve Template Tests by Removing Manual Output Buffering
This commit is contained in:
Lukas Reschke 2014-04-26 12:29:36 +02:00
commit 96c06c14d8
1 changed files with 14 additions and 34 deletions

View File

@ -27,52 +27,32 @@ class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
$loader->load('OC_Template'); $loader->load('OC_Template');
} }
public function testP() { public function testPJavaScript() {
$badString = '<img onload="alert(1)" />'; $this->expectOutputString('&lt;img onload=&quot;alert(1)&quot; /&gt;');
ob_start(); p('<img onload="alert(1)" />');
p($badString); }
$result = ob_get_clean();
$this->assertEquals('&lt;img onload=&quot;alert(1)&quot; /&gt;', $result);
$badString = "<script>alert('Hacked!');</script>"; public function testPJavaScriptWithScriptTags() {
ob_start(); $this->expectOutputString('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;');
p($badString); p("<script>alert('Hacked!');</script>");
$result = ob_get_clean();
$this->assertEquals('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;', $result);
$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);
} }
public function testPNormalString() { public function testPNormalString() {
$normalString = "This is a good string!"; $string = 'This is a good string without HTML.';
ob_start(); $this->expectOutputString($string);
p($normalString); p($string);
$result = ob_get_clean();
$this->assertEquals("This is a good string!", $result);
} }
public function testPrintUnescaped() { public function testPrintUnescaped() {
$htmlString = "<script>alert('xss');</script>"; $htmlString = "<script>alert('xss');</script>";
$this->expectOutputString($htmlString);
ob_start();
print_unescaped($htmlString); print_unescaped($htmlString);
$result = ob_get_clean();
$this->assertEquals($htmlString, $result);
} }
public function testPrintUnescapedNormalString() { public function testPrintUnescapedNormalString() {
$normalString = "This is a good string!"; $string = 'This is a good string!';
ob_start(); $this->expectOutputString($string);
print_unescaped($normalString); print_unescaped($string);
$result = ob_get_clean();
$this->assertEquals("This is a good string!", $result);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------