Ver código fonte

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

Improve Template Tests by Removing Manual Output Buffering
tags/v7.0.0alpha2
Lukas Reschke 10 anos atrás
pai
commit
96c06c14d8
1 arquivos alterados com 15 adições e 35 exclusões
  1. 15
    35
      tests/lib/template.php

+ 15
- 35
tests/lib/template.php Ver arquivo

@@ -27,52 +27,32 @@ class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
$loader->load('OC_Template');
}

public function testP() {
$badString = '<img onload="alert(1)" />';
ob_start();
p($badString);
$result = ob_get_clean();
$this->assertEquals('&lt;img onload=&quot;alert(1)&quot; /&gt;', $result);

$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);

$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 testPJavaScript() {
$this->expectOutputString('&lt;img onload=&quot;alert(1)&quot; /&gt;');
p('<img onload="alert(1)" />');
}

public function testPNormalString() {
$normalString = "This is a good string!";
ob_start();
p($normalString);
$result = ob_get_clean();
public function testPJavaScriptWithScriptTags() {
$this->expectOutputString('&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;');
p("<script>alert('Hacked!');</script>");
}

$this->assertEquals("This is a good string!", $result);
public function testPNormalString() {
$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);
}

// ---------------------------------------------------------------------------

Carregando…
Cancelar
Salvar