mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-20 12:31:53 +00:00
[1.7.0] Unit test for ElementDef created, ElementDef behavior modified to be more flexible
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1038 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
ce013e2962
commit
ac50d333a5
2
NEWS
2
NEWS
@ -10,6 +10,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
==========================
|
==========================
|
||||||
|
|
||||||
1.7.0, unknown release date
|
1.7.0, unknown release date
|
||||||
|
. Unit test for ElementDef created, ElementDef behavior modified to
|
||||||
|
be more flexible
|
||||||
|
|
||||||
1.6.1, released 2007-05-05
|
1.6.1, released 2007-05-05
|
||||||
! Support for more deprecated attributes via transformations:
|
! Support for more deprecated attributes via transformations:
|
||||||
|
@ -99,16 +99,20 @@ class HTMLPurifier_ElementDef
|
|||||||
// merge in the includes
|
// merge in the includes
|
||||||
// sorry, no way to override an include
|
// sorry, no way to override an include
|
||||||
foreach ($v as $v2) {
|
foreach ($v as $v2) {
|
||||||
$def->attr[0][] = $v2;
|
$this->attr[0][] = $v2;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($v === false) {
|
||||||
|
if (isset($this->attr[$k])) unset($this->attr[$k]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->attr[$k] = $v;
|
$this->attr[$k] = $v;
|
||||||
}
|
}
|
||||||
foreach($def->attr_transform_pre as $k => $v) $this->attr_transform_pre[$k] = $v;
|
$this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre);
|
||||||
foreach($def->attr_transform_post as $k => $v) $this->attr_transform_post[$k] = $v;
|
$this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post);
|
||||||
foreach($def->auto_close as $k => $v) $this->auto_close[$k] = $v;
|
$this->_mergeAssocArray($this->auto_close, $def->auto_close);
|
||||||
foreach($def->excludes as $k => $v) $this->excludes[$k] = $v;
|
$this->_mergeAssocArray($this->excludes, $def->excludes);
|
||||||
|
|
||||||
if(!is_null($def->child)) $this->child = $def->child;
|
if(!is_null($def->child)) $this->child = $def->child;
|
||||||
if(!empty($def->content_model)) $this->content_model .= ' | ' . $def->content_model;
|
if(!empty($def->content_model)) $this->content_model .= ' | ' . $def->content_model;
|
||||||
@ -117,6 +121,21 @@ class HTMLPurifier_ElementDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges one array into another, removes values which equal false
|
||||||
|
* @param $a1 Array by reference that is merged into
|
||||||
|
* @param $a2 Array that merges into $a1
|
||||||
|
*/
|
||||||
|
function _mergeAssocArray(&$a1, $a2) {
|
||||||
|
foreach ($a2 as $k => $v) {
|
||||||
|
if ($v === false) {
|
||||||
|
if (isset($a1[$k])) unset($a1[$k]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$a1[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
105
tests/HTMLPurifier/ElementDefTest.php
Normal file
105
tests/HTMLPurifier/ElementDefTest.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/ElementDef.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_ElementDefTest extends UnitTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
function test_mergeIn() {
|
||||||
|
|
||||||
|
$def1 = new HTMLPurifier_ElementDef();
|
||||||
|
$def2 = new HTMLPurifier_ElementDef();
|
||||||
|
$def3 = new HTMLPurifier_ElementDef();
|
||||||
|
|
||||||
|
$old = 1;
|
||||||
|
$new = 2;
|
||||||
|
$overloaded_old = 3;
|
||||||
|
$overloaded_new = 4;
|
||||||
|
$removed = 5;
|
||||||
|
|
||||||
|
$def1->standalone = true;
|
||||||
|
$def1->attr = array(
|
||||||
|
0 => array('old-include'),
|
||||||
|
'old-attr' => $old,
|
||||||
|
'overloaded-attr' => $overloaded_old,
|
||||||
|
'removed-attr' => $removed,
|
||||||
|
);
|
||||||
|
$def1->attr_transform_pre =
|
||||||
|
$def1->attr_transform_post = array(
|
||||||
|
'old-transform' => $old,
|
||||||
|
'overloaded-transform' => $overloaded_old,
|
||||||
|
'removed-transform' => $removed,
|
||||||
|
);
|
||||||
|
$def1->child = $overloaded_old;
|
||||||
|
$def1->content_model = 'old';
|
||||||
|
$def1->content_model_type = $overloaded_old;
|
||||||
|
$def1->auto_close = array(
|
||||||
|
'old' => true,
|
||||||
|
'removed-old' => true
|
||||||
|
);
|
||||||
|
$def1->descendants_are_inline = $overloaded_old;
|
||||||
|
$def1->excludes = array(
|
||||||
|
'old' => true,
|
||||||
|
'removed-old' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
$def2->standalone = false;
|
||||||
|
$def2->attr = array(
|
||||||
|
0 => array('new-include'),
|
||||||
|
'new-attr' => $new,
|
||||||
|
'overloaded-attr' => $overloaded_new,
|
||||||
|
'removed-attr' => false,
|
||||||
|
);
|
||||||
|
$def2->attr_transform_pre =
|
||||||
|
$def2->attr_transform_post = array(
|
||||||
|
'new-transform' => $new,
|
||||||
|
'overloaded-transform' => $overloaded_new,
|
||||||
|
'removed-transform' => false,
|
||||||
|
);
|
||||||
|
$def2->child = $new;
|
||||||
|
$def2->content_model = 'new';
|
||||||
|
$def2->content_model_type = $overloaded_new;
|
||||||
|
$def2->auto_close = array(
|
||||||
|
'new' => true,
|
||||||
|
'removed-old' => false
|
||||||
|
);
|
||||||
|
$def2->descendants_are_inline = $overloaded_new;
|
||||||
|
$def2->excludes = array(
|
||||||
|
'new' => true,
|
||||||
|
'removed-old' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$def1->mergeIn($def2);
|
||||||
|
$def1->mergeIn($def3); // empty, has no effect
|
||||||
|
|
||||||
|
$this->assertIdentical($def1->standalone, true);
|
||||||
|
$this->assertIdentical($def1->attr, array(
|
||||||
|
0 => array('old-include', 'new-include'),
|
||||||
|
'old-attr' => $old,
|
||||||
|
'overloaded-attr' => $overloaded_new,
|
||||||
|
'new-attr' => $new,
|
||||||
|
));
|
||||||
|
$this->assertIdentical($def1->attr_transform_pre, $def1->attr_transform_post);
|
||||||
|
$this->assertIdentical($def1->attr_transform_pre, array(
|
||||||
|
'old-transform' => $old,
|
||||||
|
'overloaded-transform' => $overloaded_new,
|
||||||
|
'new-transform' => $new,
|
||||||
|
));
|
||||||
|
$this->assertIdentical($def1->child, $new);
|
||||||
|
$this->assertIdentical($def1->content_model, 'old | new');
|
||||||
|
$this->assertIdentical($def1->content_model_type, $overloaded_new);
|
||||||
|
$this->assertIdentical($def1->auto_close, array(
|
||||||
|
'old' => true,
|
||||||
|
'new' => true
|
||||||
|
));
|
||||||
|
$this->assertIdentical($def1->descendants_are_inline, $overloaded_new);
|
||||||
|
$this->assertIdentical($def1->excludes, array(
|
||||||
|
'old' => true,
|
||||||
|
'new' => true
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -55,6 +55,7 @@ $test_files[] = 'ChildDef/TableTest.php';
|
|||||||
$test_files[] = 'ConfigSchemaTest.php';
|
$test_files[] = 'ConfigSchemaTest.php';
|
||||||
$test_files[] = 'ConfigTest.php';
|
$test_files[] = 'ConfigTest.php';
|
||||||
$test_files[] = 'ContextTest.php';
|
$test_files[] = 'ContextTest.php';
|
||||||
|
$test_files[] = 'ElementDefTest.php';
|
||||||
$test_files[] = 'EncoderTest.php';
|
$test_files[] = 'EncoderTest.php';
|
||||||
$test_files[] = 'EntityLookupTest.php';
|
$test_files[] = 'EntityLookupTest.php';
|
||||||
$test_files[] = 'EntityParserTest.php';
|
$test_files[] = 'EntityParserTest.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user