From a124addf961a7743c9b106d8fe859aaa7f7abbec Mon Sep 17 00:00:00 2001
From: shish <shish@7f39781d-f577-437e-ae19-be835c7a54ca>
Date: Sat, 18 Oct 2008 06:05:06 +0000
Subject: [PATCH] test specific extensions

git-svn-id: file:///home/shish/svn/shimmie2/trunk@1085 7f39781d-f577-437e-ae19-be835c7a54ca
---
 contrib/simpletest/main.php  | 13 ++++++++-----
 contrib/simpletest/theme.php | 21 ++++++++++++++++++---
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php
index 52df5dce..997cb3c0 100644
--- a/contrib/simpletest/main.php
+++ b/contrib/simpletest/main.php
@@ -7,12 +7,15 @@
  */
 
 require_once('simpletest/web_tester.php');
+require_once('simpletest/unit_tester.php');
 require_once('simpletest/reporter.php');
 
-class AllTests extends TestSuite {
-	function AllTests() {
+class TestFinder extends TestSuite {
+	function TestFinder($hint) {
+		$dir = "*";
+		if(file_exists("ext/$hint/test.php")) $dir = $hint; // FIXME: check for ..
 		$this->TestSuite('All tests');
-		foreach(glob("ext/*/test.php") as $file) {
+		foreach(glob("ext/$dir/test.php") as $file) {
 			$this->addFile($file);
 		}
 	}
@@ -24,12 +27,12 @@ class SimpleSCoreTest implements Extension {
 	public function receive_event(Event $event) {
 		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 
-		if(($event instanceof PageRequestEvent) && $event->page_matches("test/all")) {
+		if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
 			$event->page->set_title("Test Results");
 			$event->page->set_heading("Test Results");
 			$event->page->add_block(new NavBlock());
 
-			$all = new AllTests();
+			$all = new TestFinder($event->get_arg(0));
 			$all->run(new SCoreReporter($event->page));
 		}
 
diff --git a/contrib/simpletest/theme.php b/contrib/simpletest/theme.php
index c8879bd7..5a4049fd 100644
--- a/contrib/simpletest/theme.php
+++ b/contrib/simpletest/theme.php
@@ -9,6 +9,7 @@ class SCoreReporter extends HtmlReporter {
 
 	public function SCoreReporter($page) {
 		$this->page = $page;
+		$this->_fails = 0;
 	}
 
 	function paintHeader($test_name) {
@@ -18,10 +19,18 @@ class SCoreReporter extends HtmlReporter {
 
 	function paintFooter($test_name) {
 		//parent::paintFooter($test_name);
-		$html = "".
+		$fail = $this->getFailCount() > 0;
+		if($fail) {
+			$style = "background: red;";
+		}
+		else {
+			$style = "background: green;";
+		}
+		$html = "<div style=\"padding: 4px; $style\">".
 			$this->getPassCount() . " passes, " .
 			$this->getFailCount() . " failures" .
-			"<br>Passed modules: " . $this->clear_modules;
+			"<br>Passed modules: " . $this->clear_modules .
+			"</div>";
 		$this->page->add_block(new Block("Results", $html, "main", 40));
 	}
 	
@@ -31,13 +40,19 @@ class SCoreReporter extends HtmlReporter {
 	}
 
 	function paintGroupEnd($name) {
-		$name = substr($name, 4, strlen($name)-13);
+		$matches = array();
+		if(preg_match("#ext/(.*)/test.php#", $name, $matches)) {
+			$name = $matches[1];
+			$link = "<a href=\"".make_link("test/$name")."\"></a>";
+		}
 		parent::paintGroupEnd($name);
 		if($this->current_html == "") {
 			$this->clear_modules .= "$name, ";
 		}
 		else {
+			$this->current_html .= "<p>$link";
 			$this->page->add_block(new Block($name, $this->current_html, "main", 50));
+			$this->current_html = "";
 		}
 	}