mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Added ValidateAttributes strategy and associated unit tests. Amended Generator with some sanity checks. Made Definition include all necessary definitions. Note the two elements (bdo and br) that only use coreattrs.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@132 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -74,13 +74,25 @@ class HTMLPurifier_GeneratorTest extends UnitTestCase
|
||||
|
||||
function test_generateFromTokens() {
|
||||
|
||||
$tokens = array(
|
||||
$inputs = array();
|
||||
$expect = array();
|
||||
|
||||
$inputs[0] = array(
|
||||
new HTMLPurifier_Token_Start('b'),
|
||||
new HTMLPurifier_Token_Text('Foobar!'),
|
||||
new HTMLPurifier_Token_End('b')
|
||||
);
|
||||
$expect = '<b>Foobar!</b>';
|
||||
$this->assertEqual($expect, $this->gen->generateFromTokens($tokens));
|
||||
$expect[0] = '<b>Foobar!</b>';
|
||||
|
||||
$inputs[1] = array();
|
||||
$expect[1] = '';
|
||||
|
||||
foreach ($inputs as $i => $input) {
|
||||
$result = $this->gen->generateFromTokens($input);
|
||||
$this->assertEqual($expect[$i], $result);
|
||||
paintIf($result, $result != $expect[$i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
39
tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
Normal file
39
tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once('HTMLPurifier/StrategyAbstractTest.php');
|
||||
require_once('HTMLPurifier/Strategy/ValidateAttributes.php');
|
||||
|
||||
class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
HTMLPurifier_StrategyAbstractTest
|
||||
{
|
||||
|
||||
function test() {
|
||||
|
||||
$strategy = new HTMLPurifier_Strategy_ValidateAttributes();
|
||||
|
||||
$inputs = array();
|
||||
$expect = array();
|
||||
|
||||
$inputs[0] = '';
|
||||
$expect[0] = '';
|
||||
|
||||
$inputs[1] = '<div id="valid">Preserve the ID.</div>';
|
||||
$expect[1] = $inputs[1];
|
||||
|
||||
$inputs[2] = '<div id="0invalid">Kill the ID.</div>';
|
||||
$expect[2] = '<div>Kill the ID.</div>';
|
||||
|
||||
// test accumulator
|
||||
$inputs[3] = '<div id="valid">Valid</div><div id="valid">Invalid</div>';
|
||||
$expect[3] = '<div id="valid">Valid</div><div>Invalid</div>';
|
||||
|
||||
$inputs[4] = '<span dir="up-to-down">Bad dir.</span>';
|
||||
$expect[4] = '<span>Bad dir.</span>';
|
||||
|
||||
$this->assertStrategyWorks($strategy, $inputs, $expect);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user