Index: trunk/testing/selenium/UsabilityInitiative/WikiAutomationTC/testCases/WikiListener.php |
— | — | @@ -0,0 +1,89 @@ |
| 2 | +<?php |
| 3 | + require_once 'PHPUnit/Framework.php'; |
| 4 | + require_once 'PHPUnit/Util/Filter.php'; |
| 5 | + require_once 'PHPUnit/Util/Printer.php'; |
| 6 | + require_once 'PHPUnit/Util/Test.php'; |
| 7 | + |
| 8 | + //PHPUnit to exclude it from code coverage things. |
| 9 | + PHPUnit_Util_Filter::addFileToFilter(__FILE__, "PHPUNIT"); |
| 10 | + |
| 11 | + class WikiListener extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener { |
| 12 | + protected $currentTestSuiteName = ""; |
| 13 | + protected $currentTestName = ""; |
| 14 | + protected $currentTestPass = TRUE; |
| 15 | + /** |
| 16 | + * Triggered when an error occurs on the test case |
| 17 | + */ |
| 18 | + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { |
| 19 | + $this->writeCase( |
| 20 | + 'error', |
| 21 | + $time, |
| 22 | + $e->getMessage() |
| 23 | + ); |
| 24 | + |
| 25 | + $this->currentTestPass = FALSE; |
| 26 | + } |
| 27 | + /** |
| 28 | + * Triggered when one of the unit tests fails. |
| 29 | + */ |
| 30 | + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { |
| 31 | + $this->writeCase( |
| 32 | + 'fail', |
| 33 | + $time, |
| 34 | + $e->getMessage() |
| 35 | + ); |
| 36 | + $this->currentTestPass = FALSE; |
| 37 | + } |
| 38 | + /** |
| 39 | + * Triggered when an incomplete test is encountered. |
| 40 | + */ |
| 41 | + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { |
| 42 | + $this->writeCase('error', $time, array(), 'Incomplete Test'); |
| 43 | + $this->currentTestPass = FALSE; |
| 44 | + } |
| 45 | + /** |
| 46 | + * Triggered when an incomplete test is encountered. |
| 47 | + */ |
| 48 | + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { |
| 49 | + $this->writeCase('error', $time, array(), 'Skipped Test'); |
| 50 | + $this->currentTestPass = FALSE; |
| 51 | + } |
| 52 | + /** |
| 53 | + * Triggered when a testsuite is started |
| 54 | + */ |
| 55 | + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { |
| 56 | + $this->currentTestSuiteName = $suite->getName(); |
| 57 | + $this->currentTestName = ''; |
| 58 | + $this->write("Started Suite: " . $this->currentTestSuiteName . " (" . count($suite) . " tests)n"); |
| 59 | + } |
| 60 | + /** |
| 61 | + * Triggered when a test suite ends. |
| 62 | + */ |
| 63 | + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { |
| 64 | + $this->currentTestSuiteName = ''; |
| 65 | + $this->currentTestName = ''; |
| 66 | + } |
| 67 | + /** |
| 68 | + * Triggered when a testcase starts |
| 69 | + */ |
| 70 | + public function startTest(PHPUnit_Framework_Test $test) { |
| 71 | + $this->currentTestName = PHPUnit_Util_Test::describe($test); |
| 72 | + $this->currentTestPass = TRUE; |
| 73 | + } |
| 74 | + /** |
| 75 | + * Triggered when a testcase ends |
| 76 | + */ |
| 77 | + public function endTest(PHPUnit_Framework_Test $test, $time) { |
| 78 | + if ($this->currentTestPass) { |
| 79 | + $this->writeCase('pass', $time); |
| 80 | + } |
| 81 | + } |
| 82 | + /** |
| 83 | + * To avoide duplicity |
| 84 | + */ |
| 85 | + protected function writeCase($status, $time, $message = '') { |
| 86 | + $m = "Test: " . $this->currentTestName . " - Status: " . $status . " - Time: " . $time . ($message ? " - Message: " . $message: "") . "n"; |
| 87 | + $this->write($m); |
| 88 | + } |
| 89 | + } |
| 90 | +?> |