3 require_once 'PHPUnit/Framework/TestCase.php';
4 require_once dirname(__FILE__) . '/../../../src/common/include/Error.class.php';
5 require_once dirname(__FILE__) . '/../../../src/common/include/TextSanitizer.class.php';
8 * Simple tests for the text sanitizer class.
11 * @author Alain Peyrat <aljeux@free.fr>
12 * @copyright 2009 Alain Peyrat. All rights reserved.
13 * @license GPL License
15 class TextSanitizerTests extends PHPUnit_Framework_TestCase
21 $this->s = new TextSanitizer();
25 * test purify on good code.
27 public function testPurifyOnValidHtmlCode()
29 $this->assertEquals('<h1>A valid message</h1>', $this->s->purify('<h1>A valid message</h1>'));
30 $this->assertEquals('<h1>A <b>valid</b> message</h1>', $this->s->purify('<h1>A <B>valid</B> message</h1>'));
34 * test purify on repairing damaged code.
36 public function testPurifyOnInvalidHtmlCode()
38 $this->assertEquals('<h1>Missing ending tag</h1>', $this->s->purify('<h1>Missing ending tag'));
39 $this->assertEquals('Invalid tag', $this->s->purify('Invalid <toto> tag'));
43 * test purify on malicious code.
45 public function testPurifyOnMaliciousHtmlCode()
47 $this->assertEquals('Hacker ', $this->s->purify('Hacker <script>hello</script>'));