summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorHarry Fuecks <hfuecks@gmail.com>2005-11-01 19:49:08 +0100
committerHarry Fuecks <hfuecks@gmail.com>2005-11-01 19:49:08 +0100
commitd87cece363399d9b656c140b94684ea8b60e2645 (patch)
tree9db645c779fd1179fec862e32d0e82e142a471e3 /_test
parenta337b19bd0f89ebc95b8decba2bcd7acb427bf73 (diff)
downloadrpg-d87cece363399d9b656c140b94684ea8b60e2645.tar.gz
rpg-d87cece363399d9b656c140b94684ea8b60e2645.tar.bz2
html_highlight test cases
darcs-hash:20051101184908-56ad0-ea4c38c9a25dcc245c98b1e8cc001cac1427bbb7.gz
Diffstat (limited to '_test')
-rw-r--r--_test/cases/inc/html_hilight.test.php98
-rw-r--r--_test/debug.note4
2 files changed, 102 insertions, 0 deletions
diff --git a/_test/cases/inc/html_hilight.test.php b/_test/cases/inc/html_hilight.test.php
new file mode 100644
index 000000000..304cc71b8
--- /dev/null
+++ b/_test/cases/inc/html_hilight.test.php
@@ -0,0 +1,98 @@
+<?php
+
+require_once DOKU_INC.'inc/html.php';
+
+if ( !extension_loaded('runkit') ) {
+ SimpleTestOptions::ignore('html_hilight_test');
+ trigger_error('Skipping html_hilight_test - http://www.php.net/runkit required');
+}
+
+function html_hilight_test_unslash($string,$char="'"){
+ $str= str_replace('\\'.$char,$char,$string);
+ return $str;
+}
+
+class html_hilight_test extends UnitTestCase {
+
+ function setup() {
+ runkit_function_rename('html_hilight_test_unslash','unslash');
+ }
+
+ function teardown() {
+ runkit_function_rename('unslash','html_hilight_test_unslash');
+ }
+
+ function testHighlightOneWord() {
+ $html = 'Foo bar Foo';
+ $this->assertPattern(
+ '/Foo <span.*>bar<\/span> Foo/',
+ html_hilight($html,'bar')
+ );
+ }
+
+ function testHighlightTwoWords() {
+ $html = 'Foo bar Foo php Foo';
+ $this->assertPattern(
+ '/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/',
+ html_hilight($html,'bar php')
+ );
+ }
+
+ function testHighlightTwoWordsHtml() {
+ $html = 'Foo <b>bar</b> <i>Foo</i> php Foo';
+ $this->assertPattern(
+ '/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/',
+ html_hilight($html,'bar php')
+ );
+ }
+
+ function testNoHighlight() {
+ $html = 'Foo bar Foo';
+ $this->assertPattern(
+ '/Foo bar Foo/',
+ html_hilight($html,'php')
+ );
+ }
+
+ function testHighlightPHP() {
+ $html = 'Foo $_GET[\'bar\'] Foo';
+ $this->assertPattern(
+ '/Foo <span.*>'.preg_quote('$_GET[\'bar\']').'<\/span> Foo/',
+ html_hilight($html,'$_GET[\'bar\']')
+ );
+ }
+
+ function testMatchAttribute() {
+ $html = 'Foo <b class="x">bar</b> Foo';
+ $this->assertPattern(
+ '/Foo <b class="x">bar<\/b> Foo/',
+ html_hilight($html,'class="x"')
+ );
+ }
+
+ function testMatchAttributeWord() {
+ $html = 'Foo <b class="x">bar</b> Foo';
+ $this->assertPattern(
+ '/Foo <b class="x">bar<\/b> Foo/',
+ html_hilight($html,'class="x">bar')
+ );
+ }
+
+ function testRegexInjection() {
+ $html = 'Foo bar Foo';
+ $this->assertPattern(
+ '/Foo bar Foo/',
+ html_hilight($html,'*')
+ );
+ }
+
+ function testRegexInjectionSlash() {
+ $html = 'Foo bar Foo';
+ $this->assertPattern(
+ '/Foo bar Foo/',
+ html_hilight($html,'x/')
+ );
+ }
+
+}
+
diff --git a/_test/debug.note b/_test/debug.note
new file mode 100644
index 000000000..28c34d8ee
--- /dev/null
+++ b/_test/debug.note
@@ -0,0 +1,4 @@
+print "-----------------------------------------------------\n";
+print_r(array_map('stripbyteindex',$this->H->calls));
+print "-----------------------------------------------------\n";
+print_r($calls);