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 @include_once '/usr/local/share/php/vendor/autoload.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 TextSanitizerTest extends PHPUnit\Framework\TestCase {
37 function setUp():void {
38 $this->s = new TextSanitizer();
42 * test purify on good code.
44 public function testPurifyOnValidHtmlCode() {
45 $this->assertEquals('<h1>A valid message</h1>', $this->s->purify('<h1>A valid message</h1>'));
46 $this->assertEquals('<h1>A <b>valid</b> message</h1>', $this->s->purify('<h1>A <B>valid</B> message</h1>'));
50 * test purify on repairing damaged code.
52 public function testPurifyOnInvalidHtmlCode() {
53 $this->assertEquals('<h1>Missing ending tag</h1>', $this->s->purify('<h1>Missing ending tag'));
54 $this->assertEquals('Invalid tag', $this->s->purify('Invalid <toto> tag'));
58 * test purify on malicious code.
60 public function testPurifyOnMaliciousHtmlCode() {
61 $this->assertEquals('Hacker ', $this->s->purify('Hacker <script>hello</script>'));
65 * test purify on other html piece of code.
67 public function testPurifyOnMiscCode() {
68 $in = "</div>\n<div>> rep > rep</div>\n<div>";
69 $out = "\n<div>> rep > rep</div>\n";
70 $this->assertEquals($out, $this->s->purify($in));
74 * test purify on other html piece of code.
76 public function testPurifyOnMiscCode2() {
77 $text = '<b>ceci</b> <i>est</i> <u>une</u> <font color="#cc0000">reponse</font>';
78 $this->assertEquals($text, $this->s->purify($text));