call assert() from the right place

This commit is contained in:
Shish 2009-01-25 12:42:21 +00:00 committed by Shish
parent 63a4ca2587
commit a9ca976afd

View file

@ -1,45 +1,55 @@
<?php <?php
class BBCodeUnitTest extends UnitTestCase { class BBCodeUnitTest extends UnitTestCase {
public function testBasics() { 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() { public function testStacking() {
$this->template("[b]B[/b][i]I[/i][b]B[/b]", "<b>B</b><i>I</i><b>B</b>"); $this->assertEqual(
$this->template("[b]bold[i]bolditalic[/i]bold[/b]", "<b>bold<i>bolditalic</i>bold</b>"); $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() { 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() { 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() { public function testNestedList() {
$this->template( $this->assertEqual(
"[list][*]a[list][*]a[*]b[/list][*]b[/list]", $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"),
"<ul><li>a<ul><li>a<li>b</ul><li>b</ul>"); "<ul><li>a<ul><li>a<li>b</ul><li>b</ul>");
} }
public function testURL() { public function testURL() {
$this->template( $this->assertEqual(
"[url]http://shishnet.org[/url]", $this->filter("[url]http://shishnet.org[/url]"),
"<a href=\"http://shishnet.org\">http://shishnet.org</a>"); "<a href=\"http://shishnet.org\">http://shishnet.org</a>");
$this->template( $this->assertEqual(
"[url=http://shishnet.org]ShishNet[/url]", $this->filter("[url=http://shishnet.org]ShishNet[/url]"),
"<a href=\"http://shishnet.org\">ShishNet</a>"); "<a href=\"http://shishnet.org\">ShishNet</a>");
$this->template( $this->assertEqual(
"[url=javascript:alert(\"owned\")]click to fail[/url]", $this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"),
"[url=javascript:alert(&quot;owned&quot;)]click to fail[/url]"); "[url=javascript:alert(&quot;owned&quot;)]click to fail[/url]");
} }
private function template($in, $out) { private function filter($in) {
$bb = new BBCode(); $bb = new WordFilter();
$tfe = new TextFormattingEvent($in); $tfe = new TextFormattingEvent($in);
$bb->receive_event($tfe); $bb->receive_event($tfe);
$this->assertEqual($tfe->formatted, $out); return $tfe->formatted;
} }
} }
?> ?>