aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php
blob: 69d3c628d456dcd8615a2c13b5cae3803d4da35f (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
<?php

class HTMLPurifier_Lexer_DirectLex_ErrorsTest extends HTMLPurifier_ErrorsHarness
{

    function invoke($input) {
        $lexer = new HTMLPurifier_Lexer_DirectLex();
        $lexer->tokenizeHTML($input, $this->config, $this->context);
    }

    function invokeAttr($input) {
        $lexer = new HTMLPurifier_Lexer_DirectLex();
        $lexer->parseAttributeString($input, $this->config, $this->context);
    }

    function testExtractBody() {
        $this->expectErrorCollection(E_WARNING, 'Lexer: Extracted body');
        $this->invoke('<body>foo</body>');
    }

    function testUnclosedComment() {
        $this->expectErrorCollection(E_WARNING, 'Lexer: Unclosed comment');
        $this->expectContext('CurrentLine', 1);
        $this->invoke('<!-- >');
    }

    function testUnescapedLt() {
        $this->expectErrorCollection(E_NOTICE, 'Lexer: Unescaped lt');
        $this->expectContext('CurrentLine', 1);
        $this->invoke('< foo>');
    }

    function testMissingGt() {
        $this->expectErrorCollection(E_WARNING, 'Lexer: Missing gt');
        $this->expectContext('CurrentLine', 1);
        $this->invoke('<a href=""');
    }

    // these are sub-errors, will only be thrown in context of collector

    function testMissingAttributeKey1() {
        $this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
        $this->invokeAttr('=""');
    }

    function testMissingAttributeKey2() {
        $this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
        $this->invokeAttr('foo="bar" =""');
    }

    function testMissingEndQuote() {
        $this->expectErrorCollection(E_ERROR, 'Lexer: Missing end quote');
        $this->invokeAttr('src="foo');
    }

}

// vim: et sw=4 sts=4