diff --git a/docs/progress.html b/docs/progress.html index 83722e62..d3faab2d 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -80,7 +80,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
to
// DEFINITION CALL - foreach ($this->definition->info[$token->name]->attr_transform + foreach ($this->definition->info[$token->name]->attr_transform_pre as $transform ) { - $attr = $transform->transform($attr); + $attr = $transform->transform($attr, $config); } // create alias to this element's attribute definition array, see @@ -115,6 +115,14 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy // others would prepend themselves). } + // post transforms + foreach ($this->definition->info_attr_transform_post as $transform) { + $attr = $transform->transform($attr, $config); + } + foreach ($this->definition->info[$token->name]->attr_transform_post as $transform) { + $attr = $transform->transform($attr, $config); + } + // commit changes // could interfere with flyweight implementation $tokens[$key]->attributes = $attr; diff --git a/tests/HTMLPurifier/AttrTransform/BdoDirTest.php b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php new file mode 100644 index 00000000..0762359d --- /dev/null +++ b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php @@ -0,0 +1,36 @@ +transform = new HTMLPurifier_AttrTransform_BdoDir(); + + $inputs = array(); + $expect = array(); + $config = array(); + + // add dir + $inputs[0] = array(); + $expect[0] = array('dir' => 'ltr'); + + // leave existing dir alone + $inputs[1] = array('dir' => 'rtl'); + $expect[1] = array('dir' => 'rtl'); + + $config_rtl = HTMLPurifier_Config::createDefault(); + $config_rtl->set('Attr', 'DefaultTextDir', 'rtl'); + $inputs[2] = array(); + $expect[2] = array('dir' => 'rtl'); + $config[2] = $config_rtl; + + $this->assertTransform($inputs, $expect, $config); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php new file mode 100644 index 00000000..c410b29f --- /dev/null +++ b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php @@ -0,0 +1,35 @@ +transform = new HTMLPurifier_AttrTransform_ImgRequired(); + + $inputs = $expect = $config = array(); + + $inputs[0] = array(); + $expect[0] = array('src' => '', 'alt' => 'Invalid image'); + + $inputs[1] = array(); + $expect[1] = array('src' => 'blank.png', 'alt' => 'Pawned!'); + $config[1] = HTMLPurifier_Config::createDefault(); + $config[1]->set('Attr', 'DefaultInvalidImage', 'blank.png'); + $config[1]->set('Attr', 'DefaultInvalidImageAlt', 'Pawned!'); + + $inputs[2] = array('src' => '/path/to/foobar.png'); + $expect[2] = array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png'); + + $inputs[3] = array('alt' => 'intrigue'); + $expect[3] = array('src' => '', 'alt' => 'intrigue'); + + $this->assertTransform($inputs, $expect, $config); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransformHarness.php b/tests/HTMLPurifier/AttrTransformHarness.php index 138d9280..ceff33b7 100644 --- a/tests/HTMLPurifier/AttrTransformHarness.php +++ b/tests/HTMLPurifier/AttrTransformHarness.php @@ -5,14 +5,13 @@ class HTMLPurifier_AttrTransformHarness extends UnitTestCase var $transform; - function assertTransform($inputs, $expect) { + function assertTransform($inputs, $expect, $config = array()) { + $default_config = HTMLPurifier_Config::createDefault(); foreach ($inputs as $i => $input) { - $result = $this->transform->transform($input); - if ($expect[$i] === true) { - $this->assertEqual($input, $result, "Test $i: %s"); - } else { - $this->assertEqual($expect[$i], $result, "Test $i: %s"); - } + if (!isset($config[$i])) $config[$i] = $default_config; + $result = $this->transform->transform($input, $config[$i]); + if ($expect[$i] === true) $expect[$i] = $input; + $this->assertEqual($expect[$i], $result, "Test $i: %s"); } } diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index beb847dc..6e610fb7 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -12,6 +12,9 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends $strategy = new HTMLPurifier_Strategy_ValidateAttributes(); + // attribute order is VERY fragile, perhaps we should define + // an ordering scheme! + $inputs = array(); $expect = array(); $config = array(); @@ -68,8 +71,9 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends $expect[12] = '
Taken off the market |