3 * Copyright FusionForge Team
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 require_once 'PHPUnit/Framework/TestCase.php';
23 require_once dirname(__FILE__) . '/../../../src/common/include/FFError.class.php';
24 require_once dirname(__FILE__) . '/../../../src/common/include/TextSanitizer.class.php';
27 * Simple tests for the text sanitizer class.
30 * @author Alain Peyrat <aljeux@free.fr>
31 * @copyright 2009 Alain Peyrat. All rights reserved.
32 * @license GPL License
34 class TextSanitizerTests extends PHPUnit_Framework_TestCase
40 $this->s = new TextSanitizer();
44 * test purify on good code.
46 public function testPurifyOnValidHtmlCode()
48 $this->assertEquals('<h1>A valid message</h1>', $this->s->purify('<h1>A valid message</h1>'));
49 $this->assertEquals('<h1>A <b>valid</b> message</h1>', $this->s->purify('<h1>A <B>valid</B> message</h1>'));
53 * test purify on repairing damaged code.
55 public function testPurifyOnInvalidHtmlCode()
57 $this->assertEquals('<h1>Missing ending tag</h1>', $this->s->purify('<h1>Missing ending tag'));
58 $this->assertEquals('Invalid tag', $this->s->purify('Invalid <toto> tag'));
62 * test purify on malicious code.
64 public function testPurifyOnMaliciousHtmlCode()
66 $this->assertEquals('Hacker ', $this->s->purify('Hacker <script>hello</script>'));
70 * test purify on other html piece of code.
72 public function testPurifyOnMiscCode()
74 $in = "</div>\n<div>> rep > rep</div>\n<div>";
75 $out = "\n<div>> rep > rep</div>\n";
76 $this->assertEquals($out, $this->s->purify($in));
80 * test purify on other html piece of code.
82 public function testPurifyOnMiscCode2()
84 $text = '<b>ceci</b> <i>est</i> <u>une</u> <font color="#cc0000">reponse</font>';
85 $this->assertEquals($text, $this->s->purify($text));