Copy a test from parserTests.txt
[lhc/web/wiklou.git] / t / inc / Sanitizer.t
1 #!/usr/bin/env php
2 <?php
3
4 require 'Test.php';
5
6 plan( 13 );
7
8 require_ok( 'includes/Defines.php' );
9 require_ok( 'includes/GlobalFunctions.php' );
10 require_ok( 'includes/Sanitizer.php' );
11 require_ok( 'includes/normal/UtfNormal.php' );
12 require_ok( 'includes/ProfilerStub.php' ); # For removeHTMLtags
13
14
15 #
16 # decodeCharReferences
17 #
18
19 cmp_ok(
20 Sanitizer::decodeCharReferences( '&eacute;cole' ),
21 '==',
22 "\xc3\xa9cole",
23 'decode named entities'
24 );
25
26 cmp_ok(
27 Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
28 '==',
29 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
30 'decode numeric entities'
31 );
32
33 cmp_ok(
34 Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
35 '==',
36 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
37 'decode mixed numeric/named entities'
38 );
39
40 cmp_ok(
41 Sanitizer::decodeCharReferences(
42 "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)"
43 ),
44 '==',
45 "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
46 'decode mixed complex entities'
47 );
48
49 cmp_ok( Sanitizer::decodeCharReferences( 'a & b' ), '==', 'a & b', 'Invalid ampersand' );
50
51 cmp_ok( Sanitizer::decodeCharReferences( '&foo;' ), '==', '&foo;', 'Invalid named entity' );
52
53 cmp_ok( Sanitizer::decodeCharReferences( "&#88888888888888;" ), '==', UTF8_REPLACEMENT, 'Invalid numbered entity' );
54
55 $wgUseTidy = false;
56 $wgUserHtml = true;
57 cmp_ok(
58 Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
59 '==',
60 '<div>Hello world</div>',
61 'Self-closing closing div'
62 );