3 class HTMLPurifier_AttrValidator_ErrorsTest
extends HTMLPurifier_ErrorsHarness
6 public function setup() {
8 $config = HTMLPurifier_Config
::createDefault();
9 $this->language
= HTMLPurifier_LanguageFactory
::instance()->create($config, $this->context
);
10 $this->context
->register('Locale', $this->language
);
11 $this->collector
= new HTMLPurifier_ErrorCollector($this->context
);
12 $this->context
->register('Generator', new HTMLPurifier_Generator($config, $this->context
));
15 protected function invoke($input) {
16 $validator = new HTMLPurifier_AttrValidator();
17 $validator->validateToken($input, $this->config
, $this->context
);
20 function testAttributesTransformedGlobalPre() {
21 $def = $this->config
->getHTMLDefinition(true);
22 generate_mock_once('HTMLPurifier_AttrTransform');
23 $transform = new HTMLPurifier_AttrTransformMock();
24 $input = array('original' => 'value');
25 $output = array('class' => 'value'); // must be valid
26 $transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
27 $def->info_attr_transform_pre
[] = $transform;
29 $token = new HTMLPurifier_Token_Start('span', $input, 1);
30 $this->invoke($token);
32 $result = $this->collector
->getRaw();
34 array(1, E_NOTICE
, 'Attributes on <span> transformed from original to class', array()),
36 $this->assertIdentical($result, $expect);
39 function testAttributesTransformedLocalPre() {
40 $this->config
->set('HTML.TidyLevel', 'heavy');
41 $input = array('align' => 'right');
42 $output = array('style' => 'text-align:right;');
43 $token = new HTMLPurifier_Token_Start('p', $input, 1);
44 $this->invoke($token);
45 $result = $this->collector
->getRaw();
47 array(1, E_NOTICE
, 'Attributes on <p> transformed from align to style', array()),
49 $this->assertIdentical($result, $expect);
52 // too lazy to check for global post and global pre
54 function testAttributeRemoved() {
55 $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
56 $this->invoke($token);
57 $result = $this->collector
->getRaw();
59 array(1, E_ERROR
, 'foobar attribute on <p> removed', array()),
61 $this->assertIdentical($result, $expect);