call assert() from the right place
This commit is contained in:
parent
63a4ca2587
commit
a9ca976afd
1 changed files with 26 additions and 16 deletions
|
@ -1,45 +1,55 @@
|
|||
<?php
|
||||
class BBCodeUnitTest extends UnitTestCase {
|
||||
public function testBasics() {
|
||||
$this->template("[b]bold[/b][i]italic[/i]", "<b>bold</b><i>italic</i>");
|
||||
$this->assertEqual(
|
||||
$this->filter("[b]bold[/b][i]italic[/i]"),
|
||||
"<b>bold</b><i>italic</i>");
|
||||
}
|
||||
|
||||
public function testStacking() {
|
||||
$this->template("[b]B[/b][i]I[/i][b]B[/b]", "<b>B</b><i>I</i><b>B</b>");
|
||||
$this->template("[b]bold[i]bolditalic[/i]bold[/b]", "<b>bold<i>bolditalic</i>bold</b>");
|
||||
$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() {
|
||||
$this->template("[b]bold[i]italic", "[b]bold[i]italic");
|
||||
$this->assertEqual(
|
||||
$this->filter("[b]bold[i]italic"),
|
||||
"[b]bold[i]italic");
|
||||
}
|
||||
|
||||
public function testCode() {
|
||||
$this->template("[code][b]bold[/b][/code]", "<pre>[b]bold[/b]</pre>");
|
||||
$this->assertEqual(
|
||||
$this->filter("[code][b]bold[/b][/code]"),
|
||||
"<pre>[b]bold[/b]</pre>");
|
||||
}
|
||||
|
||||
public function testNestedList() {
|
||||
$this->template(
|
||||
"[list][*]a[list][*]a[*]b[/list][*]b[/list]",
|
||||
$this->assertEqual(
|
||||
$this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"),
|
||||
"<ul><li>a<ul><li>a<li>b</ul><li>b</ul>");
|
||||
}
|
||||
|
||||
public function testURL() {
|
||||
$this->template(
|
||||
"[url]http://shishnet.org[/url]",
|
||||
$this->assertEqual(
|
||||
$this->filter("[url]http://shishnet.org[/url]"),
|
||||
"<a href=\"http://shishnet.org\">http://shishnet.org</a>");
|
||||
$this->template(
|
||||
"[url=http://shishnet.org]ShishNet[/url]",
|
||||
$this->assertEqual(
|
||||
$this->filter("[url=http://shishnet.org]ShishNet[/url]"),
|
||||
"<a href=\"http://shishnet.org\">ShishNet</a>");
|
||||
$this->template(
|
||||
"[url=javascript:alert(\"owned\")]click to fail[/url]",
|
||||
$this->assertEqual(
|
||||
$this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"),
|
||||
"[url=javascript:alert("owned")]click to fail[/url]");
|
||||
}
|
||||
|
||||
private function template($in, $out) {
|
||||
$bb = new BBCode();
|
||||
private function filter($in) {
|
||||
$bb = new WordFilter();
|
||||
$tfe = new TextFormattingEvent($in);
|
||||
$bb->receive_event($tfe);
|
||||
$this->assertEqual($tfe->formatted, $out);
|
||||
return $tfe->formatted;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Reference in a new issue