Add %HTML.TargetNoreferrer, which adds rel="noreferrer" when target attribute is set
[htmlpurifier.git] / tests / HTMLPurifier / AttrValidator_ErrorsTest.php
blob07e25301d8dd73938f7f7e0c008a001a555e24f9
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 $this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
16 protected function invoke($input)
18 $validator = new HTMLPurifier_AttrValidator();
19 $validator->validateToken($input, $this->config, $this->context);
22 public function testAttributesTransformedGlobalPre()
24 $def = $this->config->getHTMLDefinition(true);
25 generate_mock_once('HTMLPurifier_AttrTransform');
26 $transform = new HTMLPurifier_AttrTransformMock();
27 $input = array('original' => 'value');
28 $output = array('class' => 'value'); // must be valid
29 $transform->returns('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
30 $def->info_attr_transform_pre[] = $transform;
32 $token = new HTMLPurifier_Token_Start('span', $input, 1);
33 $this->invoke($token);
35 $result = $this->collector->getRaw();
36 $expect = array(
37 array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
39 $this->assertIdentical($result, $expect);
42 public function testAttributesTransformedLocalPre()
44 $this->config->set('HTML.TidyLevel', 'heavy');
45 $input = array('align' => 'right');
46 $output = array('style' => 'text-align:right;');
47 $token = new HTMLPurifier_Token_Start('p', $input, 1);
48 $this->invoke($token);
49 $result = $this->collector->getRaw();
50 $expect = array(
51 array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
53 $this->assertIdentical($result, $expect);
56 // too lazy to check for global post and global pre
58 public function testAttributeRemoved()
60 $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
61 $this->invoke($token);
62 $result = $this->collector->getRaw();
63 $expect = array(
64 array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
66 $this->assertIdentical($result, $expect);
71 // vim: et sw=4 sts=4