xref: /dokuwiki/_test/tests/inc/html_hilight.test.php (revision 9ad2b9131dcbe90c5d256acd8f9f347b14d958fb)
16c529606SAndreas Gohr<?php
26c529606SAndreas Gohr
36c529606SAndreas Gohrclass html_hilight_test extends DokuWikiTest {
46c529606SAndreas Gohr
56c529606SAndreas Gohr    function testHighlightOneWord() {
66c529606SAndreas Gohr        $html = 'Foo bar Foo';
7*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
86c529606SAndreas Gohr            '/Foo <span.*>bar<\/span> Foo/',
96c529606SAndreas Gohr            html_hilight($html,'bar')
106c529606SAndreas Gohr        );
116c529606SAndreas Gohr    }
126c529606SAndreas Gohr
136c529606SAndreas Gohr    function testHighlightTwoWords() {
146c529606SAndreas Gohr        $html = 'Foo bar Foo php Foo';
15*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
166c529606SAndreas Gohr            '/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/',
176c529606SAndreas Gohr            html_hilight($html,array('bar','php'))
186c529606SAndreas Gohr        );
196c529606SAndreas Gohr    }
206c529606SAndreas Gohr
216c529606SAndreas Gohr    function testHighlightTwoWordsHtml() {
226c529606SAndreas Gohr        $html = 'Foo <b>bar</b> <i>Foo</i> php Foo';
23*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
246c529606SAndreas Gohr            '/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/',
256c529606SAndreas Gohr            html_hilight($html,array('bar','php'))
266c529606SAndreas Gohr        );
276c529606SAndreas Gohr    }
286c529606SAndreas Gohr
296c529606SAndreas Gohr    function testNoMatchHtml() {
306c529606SAndreas Gohr        $html = 'Foo <font>font</font> Bar';
31*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
326c529606SAndreas Gohr            '/Foo <font><span.*>font<\/span><\/font> Bar/',
336c529606SAndreas Gohr            html_hilight($html,'font')
346c529606SAndreas Gohr        );
356c529606SAndreas Gohr    }
366c529606SAndreas Gohr
376c529606SAndreas Gohr    function testWildcardRight() {
386c529606SAndreas Gohr        $html = 'foo bar foobar barfoo foobarfoo foo';
39*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
406c529606SAndreas Gohr            '/foo <span.*>bar<\/span> foobar <span.*>bar<\/span>foo foobarfoo foo/',
416c529606SAndreas Gohr            html_hilight($html,'bar*')
426c529606SAndreas Gohr        );
436c529606SAndreas Gohr    }
446c529606SAndreas Gohr
456c529606SAndreas Gohr    function testWildcardLeft() {
466c529606SAndreas Gohr        $html = 'foo bar foobar barfoo foobarfoo foo';
47*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
486c529606SAndreas Gohr            '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> barfoo foobarfoo foo/',
496c529606SAndreas Gohr            html_hilight($html,'*bar')
506c529606SAndreas Gohr        );
516c529606SAndreas Gohr    }
526c529606SAndreas Gohr
536c529606SAndreas Gohr    function testWildcardBoth() {
546c529606SAndreas Gohr        $html = 'foo bar foobar barfoo foobarfoo foo';
55*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
566c529606SAndreas Gohr            '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> <span.*>bar<\/span>foo foo<span.*>bar<\/span>foo foo/',
576c529606SAndreas Gohr            html_hilight($html,'*bar*')
586c529606SAndreas Gohr        );
596c529606SAndreas Gohr    }
606c529606SAndreas Gohr
616c529606SAndreas Gohr    function testNoHighlight() {
626c529606SAndreas Gohr        $html = 'Foo bar Foo';
63*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
646c529606SAndreas Gohr            '/Foo bar Foo/',
656c529606SAndreas Gohr            html_hilight($html,'php')
666c529606SAndreas Gohr        );
676c529606SAndreas Gohr    }
686c529606SAndreas Gohr
696c529606SAndreas Gohr    function testMatchAttribute() {
706c529606SAndreas Gohr        $html = 'Foo <b class="x">bar</b> Foo';
71*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
726c529606SAndreas Gohr            '/Foo <b class="x">bar<\/b> Foo/',
736c529606SAndreas Gohr            html_hilight($html,'class="x"')
746c529606SAndreas Gohr        );
756c529606SAndreas Gohr    }
766c529606SAndreas Gohr
776c529606SAndreas Gohr    function testMatchAttributeWord() {
786c529606SAndreas Gohr        $html = 'Foo <b class="x">bar</b> Foo';
796c529606SAndreas Gohr        $this->assertEquals(
806c529606SAndreas Gohr            'Foo <b class="x">bar</b> Foo',
816c529606SAndreas Gohr            html_hilight($html,'class="x">bar')
826c529606SAndreas Gohr        );
836c529606SAndreas Gohr    }
846c529606SAndreas Gohr
856c529606SAndreas Gohr    function testRegexInjection() {
866c529606SAndreas Gohr        $html = 'Foo bar Foo';
87*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
886c529606SAndreas Gohr            '/Foo bar Foo/',
896c529606SAndreas Gohr            html_hilight($html,'*')
906c529606SAndreas Gohr        );
916c529606SAndreas Gohr    }
926c529606SAndreas Gohr
936c529606SAndreas Gohr    function testRegexInjectionSlash() {
946c529606SAndreas Gohr        $html = 'Foo bar Foo';
95*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
966c529606SAndreas Gohr            '/Foo bar Foo/',
976c529606SAndreas Gohr            html_hilight($html,'x/')
986c529606SAndreas Gohr        );
996c529606SAndreas Gohr    }
1000483f97fSAndreas Gohr
1010483f97fSAndreas Gohr    function testMB() {
1020483f97fSAndreas Gohr        $html = 'foo ДокуВики bar';
103*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
1040483f97fSAndreas Gohr            '/foo <span.*>ДокуВики<\/span> bar/',
1050483f97fSAndreas Gohr            html_hilight($html,'ДокуВики')
1060483f97fSAndreas Gohr        );
1070483f97fSAndreas Gohr    }
1080483f97fSAndreas Gohr
1090483f97fSAndreas Gohr    function testMBright() {
1100483f97fSAndreas Gohr        $html = 'foo ДокуВики bar';
111*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
1120483f97fSAndreas Gohr            '/foo <span.*>Доку<\/span>Вики bar/',
1130483f97fSAndreas Gohr            html_hilight($html,'Доку*')
1140483f97fSAndreas Gohr        );
1150483f97fSAndreas Gohr    }
1160483f97fSAndreas Gohr
1170483f97fSAndreas Gohr    function testMBleft() {
1180483f97fSAndreas Gohr        $html = 'foo ДокуВики bar';
119*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
1200483f97fSAndreas Gohr            '/foo Доку<span.*>Вики<\/span> bar/',
1210483f97fSAndreas Gohr            html_hilight($html,'*Вики')
1220483f97fSAndreas Gohr        );
1230483f97fSAndreas Gohr    }
1240483f97fSAndreas Gohr
1250483f97fSAndreas Gohr    function testMBboth() {
1260483f97fSAndreas Gohr        $html = 'foo ДокуВики bar';
127*9ad2b913SAndreas Gohr        $this->assertMatchesRegularExpression(
1280483f97fSAndreas Gohr            '/foo До<span.*>куВи<\/span>ки bar/',
1290483f97fSAndreas Gohr            html_hilight($html,'*куВи*')
1300483f97fSAndreas Gohr        );
1310483f97fSAndreas Gohr    }
1326c529606SAndreas Gohr}
133