2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-12-28 18:17:16 +00:00
|
|
|
class SanitizerTest extends MediaWikiTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
AutoLoader::loadClass( 'Sanitizer' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testDecodeNamedEntities() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"\xc3\xa9cole",
|
|
|
|
|
Sanitizer::decodeCharReferences( 'école' ),
|
|
|
|
|
'decode named entities'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testDecodeNumericEntities() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"\xc4\x88io bonas dans l'\xc3\xa9cole!",
|
|
|
|
|
Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
|
|
|
|
|
'decode numeric entities'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testDecodeMixedEntities() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"\xc4\x88io bonas dans l'\xc3\xa9cole!",
|
|
|
|
|
Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
|
|
|
|
|
'decode mixed numeric/named entities'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testDecodeMixedComplexEntities() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)",
|
|
|
|
|
Sanitizer::decodeCharReferences(
|
|
|
|
|
"Ĉio bonas dans l'école! (mais pas &#x108;io dans l'&eacute;cole)"
|
|
|
|
|
),
|
|
|
|
|
'decode mixed complex entities'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testInvalidAmpersand() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'a & b',
|
|
|
|
|
Sanitizer::decodeCharReferences( 'a & b' ),
|
|
|
|
|
'Invalid ampersand'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testInvalidEntities() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'&foo;',
|
|
|
|
|
Sanitizer::decodeCharReferences( '&foo;' ),
|
|
|
|
|
'Invalid named entity'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testInvalidNumberedEntities() {
|
|
|
|
|
$this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testSelfClosingTag() {
|
|
|
|
|
$GLOBALS['wgUseTidy'] = false;
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'<div>Hello world</div>',
|
|
|
|
|
Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
|
|
|
|
|
'Self-closing closing div'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|