2008-10-18 06:03:01 +00:00
|
|
|
<?php
|
2015-08-09 11:14:28 +00:00
|
|
|
class BBCodeTest extends ShimmiePHPUnitTestCase {
|
2008-10-18 06:03:01 +00:00
|
|
|
public function testBasics() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[b]bold[/b][i]italic[/i]"),
|
|
|
|
"<b>bold</b><i>italic</i>");
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testStacking() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[b]B[/b][i]I[/i][b]B[/b]"),
|
|
|
|
"<b>B</b><i>I</i><b>B</b>");
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[b]bold[i]bolditalic[/i]bold[/b]"),
|
|
|
|
"<b>bold<i>bolditalic</i>bold</b>");
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFailure() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[b]bold[i]italic"),
|
|
|
|
"[b]bold[i]italic");
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 12:26:07 +00:00
|
|
|
public function testCode() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[code][b]bold[/b][/code]"),
|
|
|
|
"<pre>[b]bold[/b]</pre>");
|
2009-01-25 12:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNestedList() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$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>");
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2010-03-12 18:39:08 +00:00
|
|
|
$this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]"),
|
|
|
|
"<ul><li>a<ol><li>a<li>b</ol><li>b</ul>");
|
2009-01-25 12:26:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-19 19:23:48 +00:00
|
|
|
public function testSpoiler() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-09-19 19:23:48 +00:00
|
|
|
$this->filter("[spoiler]ShishNet[/spoiler]"),
|
|
|
|
"<span style=\"background-color:#000; color:#000;\">ShishNet</span>");
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-09-19 19:23:48 +00:00
|
|
|
$this->strip("[spoiler]ShishNet[/spoiler]"),
|
|
|
|
"FuvfuArg");
|
2015-08-09 11:14:28 +00:00
|
|
|
#$this->assertEquals(
|
2009-09-19 19:23:48 +00:00
|
|
|
# $this->filter("[spoiler]ShishNet"),
|
|
|
|
# "[spoiler]ShishNet");
|
|
|
|
}
|
|
|
|
|
2008-10-18 06:03:01 +00:00
|
|
|
public function testURL() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[url]http://shishnet.org[/url]"),
|
2008-10-18 06:03:01 +00:00
|
|
|
"<a href=\"http://shishnet.org\">http://shishnet.org</a>");
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[url=http://shishnet.org]ShishNet[/url]"),
|
2008-10-18 06:03:01 +00:00
|
|
|
"<a href=\"http://shishnet.org\">ShishNet</a>");
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-01-25 12:42:21 +00:00
|
|
|
$this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"),
|
2012-03-09 18:15:58 +00:00
|
|
|
"[url=javascript:alert(\"owned\")]click to fail[/url]");
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 09:54:01 +00:00
|
|
|
public function testEmailURL() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2009-12-30 09:13:57 +00:00
|
|
|
$this->filter("[email]spam@shishnet.org[/email]"),
|
|
|
|
"<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>");
|
|
|
|
}
|
|
|
|
|
2014-08-24 15:55:00 +00:00
|
|
|
public function testAnchor() {
|
2015-08-09 11:14:28 +00:00
|
|
|
$this->assertEquals(
|
2014-08-24 15:55:00 +00:00
|
|
|
$this->filter("[anchor=rules]Rules[/anchor]"),
|
2014-08-30 12:18:14 +00:00
|
|
|
'<span class="anchor">Rules <a class="alink" href="#bb-rules" name="bb-rules" title="link to this anchor"> ¶ </a></span>');
|
2014-08-24 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 12:42:21 +00:00
|
|
|
private function filter($in) {
|
2009-05-08 10:05:15 +00:00
|
|
|
$bb = new BBCode();
|
2012-03-09 18:15:58 +00:00
|
|
|
return $bb->format($in);
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
2009-09-19 19:23:48 +00:00
|
|
|
|
|
|
|
private function strip($in) {
|
|
|
|
$bb = new BBCode();
|
2012-03-09 18:15:58 +00:00
|
|
|
return $bb->strip($in);
|
2009-09-19 19:23:48 +00:00
|
|
|
}
|
2008-10-18 06:03:01 +00:00
|
|
|
}
|
2014-04-26 02:54:51 +00:00
|
|
|
|