mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
Implement EntityLookup and put in the Lexer. Some behavior was migrated, since it looks like it will have to be used in all Lexers, not just DirectLex (which is the only one that uses it).
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@105 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
29
tests/HTMLPurifier/EntityLookupTest.php
Normal file
29
tests/HTMLPurifier/EntityLookupTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// this page is UTF-8 encoded!
|
||||
|
||||
require_once 'HTMLPurifier/EntityLookup.php';
|
||||
|
||||
class HTMLPurifier_EntityLookupTest extends UnitTestCase
|
||||
{
|
||||
|
||||
function test() {
|
||||
|
||||
$lookup = HTMLPurifier_EntityLookup::instance();
|
||||
|
||||
// latin char
|
||||
$this->assertIdentical('â', $lookup->table['acirc']);
|
||||
|
||||
// special char
|
||||
$this->assertIdentical('"', $lookup->table['quot']);
|
||||
$this->assertIdentical('“', $lookup->table['ldquo']);
|
||||
$this->assertIdentical('<', $lookup->table['lt']); //expressed strangely
|
||||
|
||||
// symbol char
|
||||
$this->assertIdentical('θ', $lookup->table['theta']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -7,6 +7,7 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
{
|
||||
|
||||
var $DirectLex, $PEARSax3, $DOMLex;
|
||||
var $_entity_lookup;
|
||||
var $_has_dom;
|
||||
|
||||
function setUp() {
|
||||
@@ -14,12 +15,13 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
$this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3();
|
||||
|
||||
$this->_has_dom = version_compare(PHP_VERSION, '5', '>=');
|
||||
|
||||
if ($this->_has_dom) {
|
||||
require_once 'HTMLPurifier/Lexer/DOMLex.php';
|
||||
$this->DOMLex = new HTMLPurifier_Lexer_DOMLex();
|
||||
}
|
||||
|
||||
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
||||
|
||||
}
|
||||
|
||||
function test_tokenizeHTML() {
|
||||
@@ -152,8 +154,12 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
// compare with this valid one:
|
||||
$input[12] = '"';
|
||||
$expect[12] = array( new HTMLPurifier_Token_Text('"') );
|
||||
$sax_expect[12] = false;
|
||||
// SAX chokes on this? We do have entity parsing on, so it should work!
|
||||
$sax_expect[12] = false; // choked!
|
||||
|
||||
// DOM and SAX choke on this
|
||||
//$char_circ = $this->_entity_lookup->table['circ'];
|
||||
//$input[13] = 'ˆ';
|
||||
//$expect[13] = array( new HTMLPurifier_Token_Text($char_circ) );
|
||||
|
||||
foreach($input as $i => $discard) {
|
||||
$result = $this->DirectLex->tokenizeHTML($input[$i]);
|
||||
|
Reference in New Issue
Block a user