aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/AttrValidator_ErrorsTest.php
blob: 307d3292bc661077ab3fc76e92a4dcdba6a5fd14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

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);
    }

    function testAttributesTransformedGlobalPre() {
        $def = $this->config->getHTMLDefinition(true);
        generate_mock_once('HTMLPurifier_AttrTransform');
        $transform = new HTMLPurifier_AttrTransformMock();
        $input = array('original' => 'value');
        $output = array('class' => 'value'); // must be valid
        $transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
        $def->info_attr_transform_pre[] = $transform;

        $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;');
        $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() {
        $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
        $this->invoke($token);
        $result = $this->collector->getRaw();
        $expect = array(
            array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
        );
        $this->assertIdentical($result, $expect);
    }

}

// vim: et sw=4 sts=4