1*6c529606SAndreas Gohr<?php 2*6c529606SAndreas Gohr 3*6c529606SAndreas Gohrclass html_hilight_test extends DokuWikiTest { 4*6c529606SAndreas Gohr 5*6c529606SAndreas Gohr function testHighlightOneWord() { 6*6c529606SAndreas Gohr $html = 'Foo bar Foo'; 7*6c529606SAndreas Gohr $this->assertRegExp( 8*6c529606SAndreas Gohr '/Foo <span.*>bar<\/span> Foo/', 9*6c529606SAndreas Gohr html_hilight($html,'bar') 10*6c529606SAndreas Gohr ); 11*6c529606SAndreas Gohr } 12*6c529606SAndreas Gohr 13*6c529606SAndreas Gohr function testHighlightTwoWords() { 14*6c529606SAndreas Gohr $html = 'Foo bar Foo php Foo'; 15*6c529606SAndreas Gohr $this->assertRegExp( 16*6c529606SAndreas Gohr '/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/', 17*6c529606SAndreas Gohr html_hilight($html,array('bar','php')) 18*6c529606SAndreas Gohr ); 19*6c529606SAndreas Gohr } 20*6c529606SAndreas Gohr 21*6c529606SAndreas Gohr function testHighlightTwoWordsHtml() { 22*6c529606SAndreas Gohr $html = 'Foo <b>bar</b> <i>Foo</i> php Foo'; 23*6c529606SAndreas Gohr $this->assertRegExp( 24*6c529606SAndreas Gohr '/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/', 25*6c529606SAndreas Gohr html_hilight($html,array('bar','php')) 26*6c529606SAndreas Gohr ); 27*6c529606SAndreas Gohr } 28*6c529606SAndreas Gohr 29*6c529606SAndreas Gohr function testNoMatchHtml() { 30*6c529606SAndreas Gohr $html = 'Foo <font>font</font> Bar'; 31*6c529606SAndreas Gohr $this->assertRegExp( 32*6c529606SAndreas Gohr '/Foo <font><span.*>font<\/span><\/font> Bar/', 33*6c529606SAndreas Gohr html_hilight($html,'font') 34*6c529606SAndreas Gohr ); 35*6c529606SAndreas Gohr } 36*6c529606SAndreas Gohr 37*6c529606SAndreas Gohr function testWildcardRight() { 38*6c529606SAndreas Gohr $html = 'foo bar foobar barfoo foobarfoo foo'; 39*6c529606SAndreas Gohr $this->assertRegExp( 40*6c529606SAndreas Gohr '/foo <span.*>bar<\/span> foobar <span.*>bar<\/span>foo foobarfoo foo/', 41*6c529606SAndreas Gohr html_hilight($html,'bar*') 42*6c529606SAndreas Gohr ); 43*6c529606SAndreas Gohr } 44*6c529606SAndreas Gohr 45*6c529606SAndreas Gohr function testWildcardLeft() { 46*6c529606SAndreas Gohr $html = 'foo bar foobar barfoo foobarfoo foo'; 47*6c529606SAndreas Gohr $this->assertRegExp( 48*6c529606SAndreas Gohr '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> barfoo foobarfoo foo/', 49*6c529606SAndreas Gohr html_hilight($html,'*bar') 50*6c529606SAndreas Gohr ); 51*6c529606SAndreas Gohr } 52*6c529606SAndreas Gohr 53*6c529606SAndreas Gohr function testWildcardBoth() { 54*6c529606SAndreas Gohr $html = 'foo bar foobar barfoo foobarfoo foo'; 55*6c529606SAndreas Gohr $this->assertRegExp( 56*6c529606SAndreas Gohr '/foo <span.*>bar<\/span> foo<span.*>bar<\/span> <span.*>bar<\/span>foo foo<span.*>bar<\/span>foo foo/', 57*6c529606SAndreas Gohr html_hilight($html,'*bar*') 58*6c529606SAndreas Gohr ); 59*6c529606SAndreas Gohr } 60*6c529606SAndreas Gohr 61*6c529606SAndreas Gohr function testNoHighlight() { 62*6c529606SAndreas Gohr $html = 'Foo bar Foo'; 63*6c529606SAndreas Gohr $this->assertRegExp( 64*6c529606SAndreas Gohr '/Foo bar Foo/', 65*6c529606SAndreas Gohr html_hilight($html,'php') 66*6c529606SAndreas Gohr ); 67*6c529606SAndreas Gohr } 68*6c529606SAndreas Gohr 69*6c529606SAndreas Gohr function testMatchAttribute() { 70*6c529606SAndreas Gohr $html = 'Foo <b class="x">bar</b> Foo'; 71*6c529606SAndreas Gohr $this->assertRegExp( 72*6c529606SAndreas Gohr '/Foo <b class="x">bar<\/b> Foo/', 73*6c529606SAndreas Gohr html_hilight($html,'class="x"') 74*6c529606SAndreas Gohr ); 75*6c529606SAndreas Gohr } 76*6c529606SAndreas Gohr 77*6c529606SAndreas Gohr function testMatchAttributeWord() { 78*6c529606SAndreas Gohr $html = 'Foo <b class="x">bar</b> Foo'; 79*6c529606SAndreas Gohr $this->assertEquals( 80*6c529606SAndreas Gohr 'Foo <b class="x">bar</b> Foo', 81*6c529606SAndreas Gohr html_hilight($html,'class="x">bar') 82*6c529606SAndreas Gohr ); 83*6c529606SAndreas Gohr } 84*6c529606SAndreas Gohr 85*6c529606SAndreas Gohr function testRegexInjection() { 86*6c529606SAndreas Gohr $html = 'Foo bar Foo'; 87*6c529606SAndreas Gohr $this->assertRegExp( 88*6c529606SAndreas Gohr '/Foo bar Foo/', 89*6c529606SAndreas Gohr html_hilight($html,'*') 90*6c529606SAndreas Gohr ); 91*6c529606SAndreas Gohr } 92*6c529606SAndreas Gohr 93*6c529606SAndreas Gohr function testRegexInjectionSlash() { 94*6c529606SAndreas Gohr $html = 'Foo bar Foo'; 95*6c529606SAndreas Gohr $this->assertRegExp( 96*6c529606SAndreas Gohr '/Foo bar Foo/', 97*6c529606SAndreas Gohr html_hilight($html,'x/') 98*6c529606SAndreas Gohr ); 99*6c529606SAndreas Gohr } 100*6c529606SAndreas Gohr} 101