summaryrefslogtreecommitdiff
path: root/_test/tests/inc/html_hilight.test.php
diff options
context:
space:
mode:
authorGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
committerGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
commit0f8ac4e8c5872a6b68b350f96a9ecde0291edefa (patch)
treead7938bb4143d5e5a38fd7a8d131e4171aec657d /_test/tests/inc/html_hilight.test.php
parent58ec8fa9128e4581749955de87530f432e387588 (diff)
parentb31fcef02fd24b3e746c9618e77152c7b84c2f2a (diff)
downloadrpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.gz
rpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.bz2
Merge branch 'master' into stable
Diffstat (limited to '_test/tests/inc/html_hilight.test.php')
-rw-r--r--_test/tests/inc/html_hilight.test.php132
1 files changed, 132 insertions, 0 deletions
diff --git a/_test/tests/inc/html_hilight.test.php b/_test/tests/inc/html_hilight.test.php
new file mode 100644
index 000000000..fc4eced67
--- /dev/null
+++ b/_test/tests/inc/html_hilight.test.php
@@ -0,0 +1,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,'*куВи*')
+ );
+ }
+}