summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-04-20 21:56:11 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-04-20 21:56:11 +0200
commit6c529606747ce4e9dab0c1e3424910b7966e5e4b (patch)
tree36c88f8b797c317895db603f68657b650e35d9e7 /_test
parent73d2d14ce0b465ec7117c8dc6ab39a59f6ed7b5a (diff)
downloadrpg-6c529606747ce4e9dab0c1e3424910b7966e5e4b.tar.gz
rpg-6c529606747ce4e9dab0c1e3424910b7966e5e4b.tar.bz2
added html_hilight test
This didn't really need runkit. The way runkit was used didn't add any more credibility to the test result
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/html_hilight.test.php100
1 files changed, 100 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..bb0cdd424
--- /dev/null
+++ b/_test/tests/inc/html_hilight.test.php
@@ -0,0 +1,100 @@
+<?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/')
+ );
+ }
+}