mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +02:00
[1.7.0] Finish implementing legacy elements, begin implementing legacy attributes
- Migrated most unit tests over to XHTML 1.0 Strict to preserve transformation behavior - Created %Core.ColorKeywords to be shared between CSS_Color and HTML_Color - Added AttrDef_HTML_Color as AttrType Color - HTMLPurifier_Config::create(HTMLPurifier_Config $config) now clones the object - Attribute minimization for HTML implemented in Generator - Move div@align fix from proprietary to regular set - Color keywords now map to full six digit hexadecimal codes - Harness will now tack on per-use-case configuration git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1084 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -10,9 +10,9 @@ class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Border($config);
|
||||
|
||||
$this->assertDef('thick solid red', 'thick solid #F00');
|
||||
$this->assertDef('thick solid red', 'thick solid #FF0000');
|
||||
$this->assertDef('thick solid');
|
||||
$this->assertDef('solid red', 'solid #F00');
|
||||
$this->assertDef('solid red', 'solid #FF0000');
|
||||
$this->assertDef('1px solid #000');
|
||||
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
|
||||
$this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)');
|
||||
|
||||
// color keywords, of course
|
||||
$this->assertDef('red', '#F00');
|
||||
$this->assertDef('red', '#FF0000');
|
||||
|
||||
// maybe hex transformations would be another nice feature
|
||||
// at the very least transform rgb percent to rgb integer
|
||||
|
23
tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
Normal file
23
tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/Color.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
function test() {
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Color();
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo', false);
|
||||
$this->assertDef('43', false);
|
||||
$this->assertDef('red', '#FF0000');
|
||||
$this->assertDef('#FF0000');
|
||||
$this->assertDef('#453443');
|
||||
$this->assertDef('453443', '#453443');
|
||||
$this->assertDef('#345', '#334455');
|
||||
$this->assertDef('120', '#112200');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -89,13 +89,21 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
$expect[4] = 'title="Theta is ' . $theta_char . '"';
|
||||
|
||||
foreach ($inputs as $i => $input) {
|
||||
$result = $this->obj->generateAttributes($input);
|
||||
$result = $this->obj->generateAttributes($input, 'irrelevant');
|
||||
$this->assertIdentical($result, $expect[$i]);
|
||||
paintIf($result, $result != $expect[$i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_generateAttributes_minimized() {
|
||||
$gen = new HTMLPurifier_Generator();
|
||||
$context = new HTMLPurifier_Context();
|
||||
$gen->generateFromTokens(array(), HTMLPurifier_Config::create(array('HTML.Doctype' => 'HTML 4.01 Transitional')), $context);
|
||||
$result = $gen->generateAttributes(array('compact' => 'compact'), 'menu');
|
||||
$this->assertIdentical($result, 'compact');
|
||||
}
|
||||
|
||||
function test_generateFromTokens() {
|
||||
|
||||
$this->func = 'generateFromTokens';
|
||||
|
@@ -63,12 +63,13 @@ class HTMLPurifier_Harness extends UnitTestCase
|
||||
* context object.
|
||||
*/
|
||||
function assertResult($input, $expect = true,
|
||||
$config_array = false, $context_array = array()
|
||||
$config_array = array(), $context_array = array()
|
||||
) {
|
||||
|
||||
// setup config
|
||||
if ($this->config) {
|
||||
$config = HTMLPurifier_Config::create($this->config);
|
||||
$config->loadArray($config_array);
|
||||
} else {
|
||||
$config = HTMLPurifier_Config::create($config_array);
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
||||
|
||||
function test() {
|
||||
|
||||
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
|
||||
|
||||
// legal inline
|
||||
$this->assertResult('<b>Bold text</b>');
|
||||
|
||||
|
@@ -13,6 +13,8 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
|
||||
|
||||
function test() {
|
||||
|
||||
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
|
||||
|
||||
$this->assertResult('');
|
||||
$this->assertResult('This is <b>bold text</b>.');
|
||||
|
||||
|
@@ -14,6 +14,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest
|
||||
|
||||
function test() {
|
||||
|
||||
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
|
||||
|
||||
$this->assertResult('');
|
||||
|
||||
|
@@ -11,6 +11,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
|
||||
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
|
||||
}
|
||||
|
||||
function testEmpty() {
|
||||
@@ -297,7 +298,8 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
$this->assertResult(
|
||||
'<a href="foo" target="_top" />',
|
||||
true,
|
||||
array('Attr.AllowedFrameTargets' => '_top')
|
||||
array('Attr.AllowedFrameTargets' => '_top',
|
||||
'HTML.Doctype' => 'XHTML 1.0 Transitional')
|
||||
);
|
||||
$this->assertResult(
|
||||
'<a href="foo" target="_top" />',
|
||||
|
Reference in New Issue
Block a user