Use PHPUnit's expectOutputString() instead of performing output buffering.
This commit is contained in:
parent
88778b569e
commit
f45080e811
1 changed files with 11 additions and 26 deletions
|
@ -28,46 +28,31 @@ class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPJavaScript() {
|
public function testPJavaScript() {
|
||||||
$badString = '<img onload="alert(1)" />';
|
$this->expectOutputString('<img onload="alert(1)" />');
|
||||||
ob_start();
|
p('<img onload="alert(1)" />');
|
||||||
p($badString);
|
|
||||||
$result = ob_get_clean();
|
|
||||||
$this->assertEquals('<img onload="alert(1)" />', $result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPJavaScriptWithScriptTags() {
|
public function testPJavaScriptWithScriptTags() {
|
||||||
$badString = "<script>alert('Hacked!');</script>";
|
$this->expectOutputString('<script>alert('Hacked!');</script>');
|
||||||
ob_start();
|
p("<script>alert('Hacked!');</script>");
|
||||||
p($badString);
|
|
||||||
$result = ob_get_clean();
|
|
||||||
$this->assertEquals('<script>alert('Hacked!');</script>', $result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPNormalString() {
|
public function testPNormalString() {
|
||||||
$goodString = 'This is a good string without HTML.';
|
$string = 'This is a good string without HTML.';
|
||||||
ob_start();
|
$this->expectOutputString($string);
|
||||||
p($goodString);
|
p($string);
|
||||||
$result = ob_get_clean();
|
|
||||||
$this->assertEquals('This is a good string without HTML.', $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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue