mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
Add $config and $context to TagTransform transform() calls.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@497 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
8256ca4376
commit
6ff78d2f79
@ -33,7 +33,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
||||
// DEFINITION CALL
|
||||
$token = $definition->
|
||||
info_tag_transform[$token->name]->
|
||||
transform($token);
|
||||
transform($token, $config, $context);
|
||||
} elseif ($escape_invalid_tags) {
|
||||
// invalid tag, generate HTML and insert in
|
||||
$token = new HTMLPurifier_Token_Text(
|
||||
|
@ -17,8 +17,10 @@ class HTMLPurifier_TagTransform
|
||||
/**
|
||||
* Transforms the obsolete tag into the valid tag.
|
||||
* @param $tag Tag to be transformed.
|
||||
* @param $config Mandatory HTMLPurifier_Config object
|
||||
* @param $context Mandatory HTMLPurifier_Context object
|
||||
*/
|
||||
function transform($tag) {
|
||||
function transform($tag, $config, &$context) {
|
||||
trigger_error('Call to abstract function', E_USER_ERROR);
|
||||
}
|
||||
|
||||
@ -37,7 +39,7 @@ class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform
|
||||
$this->transform_to = $transform_to;
|
||||
}
|
||||
|
||||
function transform($tag) {
|
||||
function transform($tag, $config, &$context) {
|
||||
$new_tag = $tag->copy();
|
||||
$new_tag->name = $this->transform_to;
|
||||
return $new_tag;
|
||||
@ -55,7 +57,7 @@ class HTMLPurifier_TagTransform_Center extends HTMLPurifier_TagTransform
|
||||
{
|
||||
var $transform_to = 'div';
|
||||
|
||||
function transform($tag) {
|
||||
function transform($tag, $config, &$context) {
|
||||
if ($tag->type == 'end') {
|
||||
$new_tag = new HTMLPurifier_Token_End($this->transform_to);
|
||||
return $new_tag;
|
||||
@ -106,7 +108,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
|
||||
'+4' => '300%'
|
||||
);
|
||||
|
||||
function transform($tag) {
|
||||
function transform($tag, $config, &$context) {
|
||||
|
||||
if ($tag->type == 'end') {
|
||||
$new_tag = new HTMLPurifier_Token_End($this->transform_to);
|
||||
|
@ -5,44 +5,83 @@ require_once 'HTMLPurifier/TagTransform.php';
|
||||
class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Asserts that a transformation happens
|
||||
*
|
||||
* This assertion performs several tests on the transform:
|
||||
*
|
||||
* -# Transforms a start tag with only $name and no attributes
|
||||
* -# Transforms a start tag with $name and $attributes
|
||||
* -# Transform an end tag
|
||||
* -# Transform an empty tag with only $name and no attributes
|
||||
* -# Transform an empty tag with $name and $attributes
|
||||
*
|
||||
* In its current form, it assumes that start and empty tags would be
|
||||
* treated the same, and is really ensuring that the tag transform doesn't
|
||||
* do anything wonky to the tag type.
|
||||
*
|
||||
* @param $transformer HTMLPurifier_TagTransform class to test
|
||||
* @param $name Name of the original tag
|
||||
* @param $attributes Attributes of the original tag
|
||||
* @param $expect_name Name of output tag
|
||||
* @param $expect_attributes Attributes of output tag when $attributes
|
||||
* is included.
|
||||
* @param $expect_added_attributes Attributes of output tag when $attributes
|
||||
* are omitted.
|
||||
* @param $config_array Configuration array for HTMLPurifier_Config
|
||||
* @param $context_array Context array for HTMLPurifier_Context
|
||||
*/
|
||||
function assertTransformation($transformer,
|
||||
$name, $attributes,
|
||||
$expect_name, $expect_attributes,
|
||||
$expect_added_attributes = array()) {
|
||||
$expect_added_attributes = array(),
|
||||
$config_array = array(), $context_array = array()) {
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->loadArray($config_array);
|
||||
|
||||
$context = new HTMLPurifier_Context();
|
||||
$context->loadArray($context_array);
|
||||
|
||||
// start tag transform
|
||||
$this->assertEqual(
|
||||
new HTMLPurifier_Token_Start($expect_name, $expect_added_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Start($name))
|
||||
new HTMLPurifier_Token_Start($name), $config, $context)
|
||||
);
|
||||
|
||||
// start tag transform with attributes
|
||||
$this->assertEqual(
|
||||
new HTMLPurifier_Token_Start($expect_name, $expect_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Start($name, $attributes)
|
||||
new HTMLPurifier_Token_Start($name, $attributes),
|
||||
$config, $context
|
||||
)
|
||||
);
|
||||
|
||||
// end tag transform
|
||||
$this->assertEqual(
|
||||
new HTMLPurifier_Token_End($expect_name),
|
||||
$transformer->transform(new HTMLPurifier_Token_End($name))
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_End($name), $config, $context
|
||||
)
|
||||
);
|
||||
|
||||
// empty tag transform
|
||||
$this->assertEqual(
|
||||
new HTMLPurifier_Token_Empty($expect_name, $expect_added_attributes),
|
||||
$transformer->transform(new HTMLPurifier_Token_Empty($name))
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Empty($name), $config, $context
|
||||
)
|
||||
);
|
||||
|
||||
// empty tag transform with attributes
|
||||
$this->assertEqual(
|
||||
new HTMLPurifier_Token_Empty($expect_name, $expect_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Empty($name, $attributes))
|
||||
new HTMLPurifier_Token_Empty($name, $attributes),
|
||||
$config, $context
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user