* Replace wfMungeToUtf8 and do_html_entity_decode with a single function
[lhc/web/wiklou.git] / tests / SanitizerTest.php
1 <?php
2
3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 require_once( '../includes/Profiling.php' );
6 require_once( '../includes/GlobalFunctions.php' );
7 require_once( '../includes/Sanitizer.php' );
8
9 class SanitizerTest extends PHPUnit_TestCase {
10 function SanitizerTest( $name ) {
11 $this->PHPUnit_TestCase( $name );
12 }
13
14 function setUp() {
15 }
16
17 function tearDown() {
18 }
19
20 function testDecodeNamed() {
21 $this->assertEquals(
22 "\xc3\xa9cole",
23 Sanitizer::decodeCharReferences( '&eacute;cole' ) );
24 }
25
26 function testDecodeNumbered() {
27 $this->assertEquals(
28 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
29 Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ) );
30 }
31
32 function testDecodeMixed() {
33 $this->assertEquals(
34 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
35 Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ) );
36 }
37
38 function testDecodeMixedComplex() {
39 $this->assertEquals(
40 "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
41 Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)" ) );
42 }
43
44 function testDecodeInvalidAmp() {
45 $this->assertEquals(
46 "a & b",
47 Sanitizer::decodeCharReferences( "a & b" ) );
48 }
49
50 function testDecodeInvalidNamed() {
51 $this->assertEquals(
52 "&foo;",
53 Sanitizer::decodeCharReferences( "&foo;" ) );
54 }
55
56 function testDecodeInvalidNumbered() {
57 $this->assertEquals(
58 UTF8_REPLACEMENT,
59 Sanitizer::decodeCharReferences( "&#88888888888888;" ) );
60 }
61
62 /* TODO: many more! */
63 }
64
65 ?>