mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +02:00
Migrate AttrValidator to nested error format; modify generator logic in ErrorCollector.
AttrValidator's changes are fairly self-explanatory, but ErrorCollector's changes are worth a little discussion. ErrorCollector can use generators at various points during its flow control; there are two distinct generators that it should use: 1. The one used for the output, and 2. The one used for the error output. These will usually be the same, but in the odd case where they need to be different, getHTMLFormatted() will accept an alterate configuration object with an appropriate doctype. Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -3,6 +3,15 @@
|
||||
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
|
||||
$this->context->register('Locale', $this->language);
|
||||
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
|
||||
$this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
|
||||
}
|
||||
|
||||
protected function invoke($input) {
|
||||
$validator = new HTMLPurifier_AttrValidator();
|
||||
$validator->validateToken($input, $this->config, $this->context);
|
||||
@@ -18,28 +27,40 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
$output = array('class' => 'value'); // must be valid
|
||||
$transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
|
||||
$def->info_attr_transform_pre[] = $transform;
|
||||
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
|
||||
|
||||
$token = new HTMLPurifier_Token_Start('span', $input, 1);
|
||||
$this->invoke($token);
|
||||
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
function testAttributesTransformedLocalPre() {
|
||||
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
||||
$input = array('align' => 'right');
|
||||
$output = array('style' => 'text-align:right;');
|
||||
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
|
||||
$token = new HTMLPurifier_Token_Start('p', $input, 1);
|
||||
$this->invoke($token);
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
// too lazy to check for global post and global pre
|
||||
|
||||
function testAttributeRemoved() {
|
||||
$this->expectErrorCollection(E_ERROR, 'AttrValidator: Attribute removed');
|
||||
$this->expectContext('CurrentAttr', 'foobar');
|
||||
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
|
||||
$this->expectContext('CurrentToken', $token);
|
||||
$this->invoke($token);
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user