cakemate / branches / master / vendors / cakemate_reporter.php

history
<?php
 /**
 * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
 * Copyright 2005-2008, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 *  Licensed under The Open Group Test Suite License
 *  Redistributions of files must retain the above copyright notice.
 */
 class CakemateReporter extends HtmlReporter {

	public function CakemateReporter($characterSet = 'UTF-8') {
		parent::HtmlReporter($characterSet);
	}

	public function paintHeader($testName) {
		list($testfile, $extension) = preg_split('/\.test\.php/', $_ENV['TM_FILENAME']);
		$testfile = Inflector::humanize($testfile);

		echo String::insert('<h2>:test-name Test</h2>', array(
				'test-name' => $testfile
			));
		echo "<table><th>Result</th><th>Test case</th><th>Message</th>";
		flush();
	}

	public function paintFooter($testName) {
		$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
		print "</table>\n";
		print "<div style=\"";
		print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";
		print "\">";
		print "<strong>" . $this->getPassCount() . "</strong> passes, ";
		print "<strong>" . $this->getFailCount() . "</strong> fails and ";
		print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
		print "</div>\n";
	}

	public function paintPass($message) {
		parent::paintPass($message);
		echo "<tr>\n\t<td width=\"20\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden;                  border-right: hidden\">\n";
		print "\t\t<span style=\"color: green;\">Pass</span>: \n";
		echo "\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";
		$breadcrumb = $this->getTestList();
		array_shift($breadcrumb);
		array_shift($breadcrumb);
		print implode("-&gt;", $breadcrumb);
		echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";
		$message = split('at \[', $message);
		print "-&gt;$message[0]<br />\n\n";
		echo "\n\t</td>\n</tr>\n\n";
	}

	public function paintFail($message) {
		echo "\n<!-- ";
		parent::paintFail($message);
		echo " -->\n";
		echo "<tr>\n\t<td width=\"20\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";
		print "\t\t<span style=\"color: red;\">Fail</span>: \n";
		echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";
		$breadcrumb = $this->getTestList();
		print implode("-&gt;", $breadcrumb);
		echo "\n\t</td>\n\t<td width=\"40%\" style=\"border: dotted 1px; border-top: hidden; border-left: hidden; border-right: hidden\">\n";
		print "$message";
		echo "\n\t</td>\n</tr>\n\n";
	}

	protected function _getCss() {
		return parent::_getCss() . ' .pass { color: green; }';
	}

}
?>