summaryrefslogtreecommitdiff
path: root/_test/tests/inc/html_hilight.test.php
blob: fc4eced67dc5dafadc12858ae1ef13ad24490313 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

class html_hilight_test extends DokuWikiTest {

    function testHighlightOneWord() {
        $html = 'Foo bar Foo';
        $this->assertRegExp(
            '/Foo <span.*>bar<\/span> Foo/',
            html_hilight($html,'bar')
        );
    }

    function testHighlightTwoWords() {
        $html = 'Foo bar Foo php Foo';
        $this->assertRegExp(
            '/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/',
            html_hilight($html,array('bar','php'))
        );
    }

    function testHighlightTwoWordsHtml() {
        $html = 'Foo <b>bar</b> <i>Foo</i> php Foo';
        $this->assertRegExp(
            '/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/',
            html_hilight($html,array('bar','php'))
        );
    }

    function testNoMatchHtml() {
        $html = 'Foo <font>font</font> Bar';
        $this->assertRegExp(
            '/Foo <font><span.*>font<\/span><\/font> Bar/',
            html_hilight($html,'font')
        );
    }

    function testWildcardRight() {
        $html = 'foo bar foobar barfoo foobarfoo foo';
        $this->assertRegExp(
            '/foo <span.*>bar<\/span> foobar <span.*>bar<\/span>foo foobarfoo foo/',
            html_hilight($html,'bar*')
        );
    }

    function testWildcardLeft() {
        $html = 'foo bar foobar barfoo foobarfoo foo';
        $this->assertRegExp(
            '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> barfoo foobarfoo foo/',
            html_hilight($html,'*bar')
        );
    }

    function testWildcardBoth() {
        $html = 'foo bar foobar barfoo foobarfoo foo';
        $this->assertRegExp(
            '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> <span.*>bar<\/span>foo foo<span.*>bar<\/span>foo foo/',
            html_hilight($html,'*bar*')
        );
    }

    function testNoHighlight() {
        $html = 'Foo bar Foo';
        $this->assertRegExp(
            '/Foo bar Foo/',
            html_hilight($html,'php')
        );
    }

    function testMatchAttribute() {
        $html = 'Foo <b class="x">bar</b> Foo';
        $this->assertRegExp(
            '/Foo <b class="x">bar<\/b> Foo/',
            html_hilight($html,'class="x"')
        );
    }

    function testMatchAttributeWord() {
        $html = 'Foo <b class="x">bar</b> Foo';
        $this->assertEquals(
            'Foo <b class="x">bar</b> Foo',
            html_hilight($html,'class="x">bar')
        );
    }

    function testRegexInjection() {
        $html = 'Foo bar Foo';
        $this->assertRegExp(
            '/Foo bar Foo/',
            html_hilight($html,'*')
        );
    }

    function testRegexInjectionSlash() {
        $html = 'Foo bar Foo';
        $this->assertRegExp(
            '/Foo bar Foo/',
            html_hilight($html,'x/')
        );
    }

    function testMB() {
        $html = 'foo ДокуВики bar';
        $this->assertRegExp(
            '/foo <span.*>ДокуВики<\/span> bar/',
            html_hilight($html,'ДокуВики')
        );
    }

    function testMBright() {
        $html = 'foo ДокуВики bar';
        $this->assertRegExp(
            '/foo <span.*>Доку<\/span>Вики bar/',
            html_hilight($html,'Доку*')
        );
    }

    function testMBleft() {
        $html = 'foo ДокуВики bar';
        $this->assertRegExp(
            '/foo Доку<span.*>Вики<\/span> bar/',
            html_hilight($html,'*Вики')
        );
    }

    function testMBboth() {
        $html = 'foo ДокуВики bar';
        $this->assertRegExp(
            '/foo До<span.*>куВи<\/span>ки bar/',
            html_hilight($html,'*куВи*')
        );
    }
}