16c529606SAndreas Gohr<?php 26c529606SAndreas Gohr 36c529606SAndreas Gohrclass html_hilight_test extends DokuWikiTest { 46c529606SAndreas Gohr 56c529606SAndreas Gohr function testHighlightOneWord() { 66c529606SAndreas Gohr $html = 'Foo bar Foo'; 76c529606SAndreas Gohr $this->assertRegExp( 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'; 156c529606SAndreas Gohr $this->assertRegExp( 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'; 236c529606SAndreas Gohr $this->assertRegExp( 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'; 316c529606SAndreas Gohr $this->assertRegExp( 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'; 396c529606SAndreas Gohr $this->assertRegExp( 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'; 476c529606SAndreas Gohr $this->assertRegExp( 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'; 556c529606SAndreas Gohr $this->assertRegExp( 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'; 636c529606SAndreas Gohr $this->assertRegExp( 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'; 716c529606SAndreas Gohr $this->assertRegExp( 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'; 876c529606SAndreas Gohr $this->assertRegExp( 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'; 956c529606SAndreas Gohr $this->assertRegExp( 966c529606SAndreas Gohr '/Foo bar Foo/', 976c529606SAndreas Gohr html_hilight($html,'x/') 986c529606SAndreas Gohr ); 996c529606SAndreas Gohr } 100*0483f97fSAndreas Gohr 101*0483f97fSAndreas Gohr function testMB() { 102*0483f97fSAndreas Gohr $html = 'foo ДокуВики bar'; 103*0483f97fSAndreas Gohr $this->assertRegExp( 104*0483f97fSAndreas Gohr '/foo <span.*>ДокуВики<\/span> bar/', 105*0483f97fSAndreas Gohr html_hilight($html,'ДокуВики') 106*0483f97fSAndreas Gohr ); 107*0483f97fSAndreas Gohr } 108*0483f97fSAndreas Gohr 109*0483f97fSAndreas Gohr function testMBright() { 110*0483f97fSAndreas Gohr $html = 'foo ДокуВики bar'; 111*0483f97fSAndreas Gohr $this->assertRegExp( 112*0483f97fSAndreas Gohr '/foo <span.*>Доку<\/span>Вики bar/', 113*0483f97fSAndreas Gohr html_hilight($html,'Доку*') 114*0483f97fSAndreas Gohr ); 115*0483f97fSAndreas Gohr } 116*0483f97fSAndreas Gohr 117*0483f97fSAndreas Gohr function testMBleft() { 118*0483f97fSAndreas Gohr $html = 'foo ДокуВики bar'; 119*0483f97fSAndreas Gohr $this->assertRegExp( 120*0483f97fSAndreas Gohr '/foo Доку<span.*>Вики<\/span> bar/', 121*0483f97fSAndreas Gohr html_hilight($html,'*Вики') 122*0483f97fSAndreas Gohr ); 123*0483f97fSAndreas Gohr } 124*0483f97fSAndreas Gohr 125*0483f97fSAndreas Gohr function testMBboth() { 126*0483f97fSAndreas Gohr $html = 'foo ДокуВики bar'; 127*0483f97fSAndreas Gohr $this->assertRegExp( 128*0483f97fSAndreas Gohr '/foo До<span.*>куВи<\/span>ки bar/', 129*0483f97fSAndreas Gohr html_hilight($html,'*куВи*') 130*0483f97fSAndreas Gohr ); 131*0483f97fSAndreas Gohr } 1326c529606SAndreas Gohr} 133