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

86 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2015-08-09 11:14:28 +00:00
class BBCodeTest extends ShimmiePHPUnitTestCase {
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>");
}
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>");
}
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");
}
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");
}
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]"),
"<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]"),
"<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]");
}
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>");
}
public function testAnchor() {
2015-08-09 11:14:28 +00:00
$this->assertEquals(
$this->filter("[anchor=rules]Rules[/anchor]"),
'<span class="anchor">Rules <a class="alink" href="#bb-rules" name="bb-rules" title="link to this anchor"> ¶ </a></span>');
}
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);
}
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
}
}