summaryrefslogtreecommitdiff
path: root/tests/SanitizerTest.php
blob: 5babf0ae776b45c857907fd9fee39b249ff7fca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

require_once( 'PHPUnit.php' );
require_once( '../includes/Defines.php' );
require_once( '../includes/Profiling.php' );
require_once( '../includes/GlobalFunctions.php' );
require_once( '../includes/Sanitizer.php' );

class SanitizerTest extends PHPUnit_TestCase {
	function SanitizerTest( $name ) {
		$this->PHPUnit_TestCase( $name );
	}

	function setUp() {
	}

	function tearDown() {
	}

	function testDecodeNamed() {
		$this->assertEquals(
			"\xc3\xa9cole",
			Sanitizer::decodeCharReferences( '&eacute;cole' ) );
	}

	function testDecodeNumbered() {
		$this->assertEquals(
			"\xc4\x88io bonas dans l'\xc3\xa9cole!",
			Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ) );
	}

	function testDecodeMixed() {
		$this->assertEquals(
			"\xc4\x88io bonas dans l'\xc3\xa9cole!",
			Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ) );
	}

	function testDecodeMixedComplex() {
		$this->assertEquals(
			"\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
			Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)" ) );
	}

	function testDecodeInvalidAmp() {
		$this->assertEquals(
			"a & b",
			Sanitizer::decodeCharReferences( "a & b" ) );
	}

	function testDecodeInvalidNamed() {
		$this->assertEquals(
			"&foo;",
			Sanitizer::decodeCharReferences( "&foo;" ) );
	}

	function testDecodeInvalidNumbered() {
		$this->assertEquals(
			UTF8_REPLACEMENT,
			Sanitizer::decodeCharReferences( "&#88888888888888;" ) );
	}

	/* TODO: many more! */
}

?>