Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / AttrValidator_ErrorsTest.php
blob98693afb63c588fb008b360ea1ce5846a554be1f
1 <?php
3 class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
6 public function setup()
8 parent::setup();
9 $config = HTMLPurifier_Config::createDefault();
10 $this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
11 $this->context->register('Locale', $this->language);
12 $this->collector = new HTMLPurifier_ErrorCollector($this->context);
13 $gen = new HTMLPurifier_Generator($config, $this->context);
14 $this->context->register('Generator', $gen);
17 protected function invoke($input)
19 $validator = new HTMLPurifier_AttrValidator();
20 $validator->validateToken($input, $this->config, $this->context);
23 public function testAttributesTransformedGlobalPre()
25 $def = $this->config->getHTMLDefinition(true);
26 generate_mock_once('HTMLPurifier_AttrTransform');
27 $transform = new HTMLPurifier_AttrTransformMock();
28 $input = array('original' => 'value');
29 $output = array('class' => 'value'); // must be valid
30 $transform->returns('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
31 $def->info_attr_transform_pre[] = $transform;
33 $token = new HTMLPurifier_Token_Start('span', $input, 1);
34 $this->invoke($token);
36 $result = $this->collector->getRaw();
37 $expect = array(
38 array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
40 $this->assertIdentical($result, $expect);
43 public function testAttributesTransformedLocalPre()
45 $this->config->set('HTML.TidyLevel', 'heavy');
46 $input = array('align' => 'right');
47 $output = array('style' => 'text-align:right;');
48 $token = new HTMLPurifier_Token_Start('p', $input, 1);
49 $this->invoke($token);
50 $result = $this->collector->getRaw();
51 $expect = array(
52 array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
54 $this->assertIdentical($result, $expect);
57 // too lazy to check for global post and global pre
59 public function testAttributeRemoved()
61 $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
62 $this->invoke($token);
63 $result = $this->collector->getRaw();
64 $expect = array(
65 array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
67 $this->assertIdentical($result, $expect);
72 // vim: et sw=4 sts=4