This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/bbcode/test.php

56 lines
1.5 KiB
PHP
Raw Normal View History

<?php
class BBCodeUnitTest extends UnitTestCase {
public function testBasics() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[b]bold[/b][i]italic[/i]"),
"<b>bold</b><i>italic</i>");
}
public function testStacking() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[b]B[/b][i]I[/i][b]B[/b]"),
"<b>B</b><i>I</i><b>B</b>");
$this->assertEqual(
$this->filter("[b]bold[i]bolditalic[/i]bold[/b]"),
"<b>bold<i>bolditalic</i>bold</b>");
}
public function testFailure() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[b]bold[i]italic"),
"[b]bold[i]italic");
}
2009-01-25 12:26:07 +00:00
public function testCode() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[code][b]bold[/b][/code]"),
"<pre>[b]bold[/b]</pre>");
2009-01-25 12:26:07 +00:00
}
public function testNestedList() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"),
2009-01-25 12:26:07 +00:00
"<ul><li>a<ul><li>a<li>b</ul><li>b</ul>");
}
public function testURL() {
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[url]http://shishnet.org[/url]"),
"<a href=\"http://shishnet.org\">http://shishnet.org</a>");
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[url=http://shishnet.org]ShishNet[/url]"),
"<a href=\"http://shishnet.org\">ShishNet</a>");
2009-01-25 12:42:21 +00:00
$this->assertEqual(
$this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"),
"[url=javascript:alert(&quot;owned&quot;)]click to fail[/url]");
}
2009-01-25 12:42:21 +00:00
private function filter($in) {
2009-05-08 10:05:15 +00:00
$bb = new BBCode();
$tfe = new TextFormattingEvent($in);
$bb->receive_event($tfe);
2009-01-25 12:42:21 +00:00
return $tfe->formatted;
}
}
?>