From cecd961e6638a7552c2fc45a4c98e6dd78e3b9b1 Mon Sep 17 00:00:00 2001 From: shish Date: Sat, 18 Oct 2008 06:03:01 +0000 Subject: [PATCH] bbcode tests git-svn-id: file:///home/shish/svn/shimmie2/trunk@1082 7f39781d-f577-437e-ae19-be835c7a54ca --- ext/bbcode/main.php | 10 +++++----- ext/bbcode/test.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 ext/bbcode/test.php diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 4e535b8d..50ad3838 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -14,12 +14,12 @@ class BBCode implements Extension { $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text); $text = preg_replace("/\[s\](.*?)\[\/s\]/s", "\\1", $text); $text = preg_replace("/\[code\](.*?)\[\/code\]/s", "
\\1
", $text); - $text = preg_replace("/>>(\d+)/s", ">>\\1", $text); + $text = preg_replace("/>>(\d+)/s", ">>\\1", $text); $text = preg_replace("/>>([^\d].+)/", "
\\1
", $text); - $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text); - $text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "\\1", $text); - $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text); - $text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text); + $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text); + $text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "\\1", $text); + $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text); + $text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text); $text = str_replace("\n", "\n
", $text); $text = preg_replace("/\[quote\](.*?)\[\/quote\]/s", "
\\1
", $text); $text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "Quoting \\1
\\2
", $text); diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php new file mode 100644 index 00000000..18348440 --- /dev/null +++ b/ext/bbcode/test.php @@ -0,0 +1,35 @@ +template("[b]bold[/b][i]italic[/i]", "bolditalic"); + } + + public function testStacking() { + $this->template("[b]B[/b][i]I[/i][b]B[/b]", "BIB"); + $this->template("[b]bold[i]bolditalic[/i]bold[/b]", "boldbolditalicbold"); + } + + public function testFailure() { + $this->template("[b]bold[i]italic", "[b]bold[i]italic"); + } + + public function testURL() { + $this->template( + "[url]http://shishnet.org[/url]", + "http://shishnet.org"); + $this->template( + "[url=http://shishnet.org]ShishNet[/url]", + "ShishNet"); + $this->template( + "[url=javascript:alert(\"owned\")]click to fail[/url]", + "[url=javascript:alert("owned")]click to fail[/url]"); + } + + private function template($in, $out) { + $bb = new BBCode(); + $tfe = new TextFormattingEvent($in); + $bb->receive_event($tfe); + $this->assertEqual($tfe->formatted, $out); + } +} +?>