Permalink
Browse files

Refactoring methods from CakeTestMenu into CakeHtmlReporter.

Updating CakeTestSuiteDispatcher to reflect removed methods.
  • Loading branch information...
1 parent f228990 commit 3c57dbee04ca1774fae1ae7cf07e6d4a282cb6e8 @markstory markstory committed Jan 6, 2010
@@ -18,83 +18,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
class CakeTestMenu {
-/**
- * Provides the "Run More" links in the testsuite interface
- *
- * @return void
- * @access public
- */
- function runMore() {
- switch (CAKE_TEST_OUTPUT) {
- case CAKE_TEST_OUTPUT_HTML:
- if (isset($_GET['group'])) {
- if (isset($_GET['app'])) {
- $show = '?show=groups&app=true';
- } else if (isset($_GET['plugin'])) {
- $show = '?show=groups&plugin=' . $_GET['plugin'];
- } else {
- $show = '?show=groups';
- }
- $query = '?group='.$_GET['group'];
- if (isset($_GET['app'])) {
- $query .= '&app=true';
- } elseif (isset($_GET['plugin'])) {
- $query .= '&plugin=' . $_GET['plugin'];
- }
- }
- if (isset($_GET['case'])) {
- if (isset($_GET['app'])) {
- $show = '?show=cases&app=true';
- } else if (isset($_GET['plugin'])) {
- $show = '?show=cases&plugin=' . $_GET['plugin'];
- } else {
- $show = '?show=cases';
- }
- $query = '?case='.$_GET['case'];
- if (isset($_GET['app'])) {
- $query .= '&app=true';
- } elseif (isset($_GET['plugin'])) {
- $query .= '&plugin=' . $_GET['plugin'];
- }
- }
- ob_start();
- echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
-
- break;
- }
- }
-
-/**
- * Provides the links to analyzing code coverage
- *
- * @return void
- * @access public
- */
- function analyzeCodeCoverage() {
- switch (CAKE_TEST_OUTPUT) {
- case CAKE_TEST_OUTPUT_HTML:
- if (isset($_GET['case'])) {
- $query = '?case=' . $_GET['case'];
- if (isset($_GET['app'])) {
- $query .= '&amp;app=true';
- } elseif (isset($_GET['plugin'])) {
- $query .= '&amp;plugin=' . $_GET['plugin'];
- }
- } else {
- $query = '?group='.$_GET['group'];
- if (isset($_GET['app'])) {
- $query .= '&amp;app=true';
- } elseif (isset($_GET['plugin'])) {
- $query .= '&amp;plugin=' . $_GET['plugin'];
- }
- }
- $query .= '&amp;code_coverage=true';
- ob_start();
- echo " <a href='" . RUN_TEST_LINK . $query . "'>Analyze Code Coverage</a></p>\n";
-
- break;
- }
- }
/**
* Prints a list of test cases
@@ -38,7 +38,8 @@ class CakeTestSuiteDispatcher {
'app' => false,
'plugin' => null,
'output' => 'html',
- 'show' => 'groups'
+ 'show' => 'groups',
+ 'show_passes' => false
);
/**
@@ -143,9 +144,9 @@ function &getReporter() {
$appClass = $this->params['output'] . 'Reporter';
$appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php';
if (include_once $coreFile) {
- $Reporter =& new $coreClass();
+ $Reporter =& new $coreClass(null, $this->params);
} elseif (include_once $appFile) {
- $Reporter =& new $appClass();
+ $Reporter =& new $appClass(null, $this->params);
}
}
return $Reporter;
@@ -191,8 +192,6 @@ function _runGroupTest() {
CodeCoverageManager::report();
}
}
- CakeTestMenu::runMore();
- CakeTestMenu::analyzeCodeCoverage();
}
/**
@@ -211,8 +210,6 @@ function _runTestCase() {
if ($this->params['codeCoverage']) {
CodeCoverageManager::report();
}
- CakeTestMenu::runMore();
- CakeTestMenu::analyzeCodeCoverage();
}
}
?>
@@ -68,18 +68,32 @@ class CakeHtmlReporter extends SimpleReporter {
var $_timeDuration = 0;
/**
+ * Array of request parameters. Usually parsed GET params.
+ *
+ * @var array
+ */
+ var $params = array();
+
+/**
* Does nothing yet. The first output will
* be sent on the first test start. For use
* by a web browser.
*
+ * ### Params
+ *
+ * - show_passes - Should passes be shown
+ * - plugin - Plugin test being run?
+ * - app - App test being run.
+ * - case - The case being run
+ *
+ * @param string $character_set The character set to output with. Defaults to ISO-8859-1
+ * @param array $params Array of request parameters the reporter should use. See above.
* @access public
*/
- function CakeHtmlReporter($character_set = 'ISO-8859-1') {
- if (isset($_GET['show_passes']) && $_GET['show_passes']) {
- $this->_show_passes = true;
- }
+ function CakeHtmlReporter($character_set = 'ISO-8859-1', $params = array()) {
$this->SimpleReporter();
- $this->_character_set = $character_set;
+ $this->_character_set = !empty($character_set) ? $character_set : 'ISO-8859-1';
+ $this->params = $params;
}
/**
@@ -139,10 +153,57 @@ function paintFooter($test_name) {
if (function_exists('memory_get_peak_usage')) {
echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
}
+ echo $this->_paintLinks();
echo '</div>';
}
/**
+ * Renders the links that for accessing things in the test suite.
+ *
+ * @return void
+ */
+ function _paintLinks() {
+ $show = $query = array();
+ if (!empty($this->params['group'])) {
+ $show['show'] = 'groups';
+ } elseif (!empty($this->params['case'])) {
+ $show['show'] = 'cases';
+ }
+
+ if (!empty($this->params['app'])) {
+ $show['app'] = $query['app'] = 'true';
+ }
+ if (!empty($this->params['plugin'])) {
+ $show['plugin'] = $query['plugin'] = $this->params['plugin'];
+ }
+ if (!empty($this->params['case'])) {
+ $query['case'] = $this->params['case'];
+ } elseif (!empty($this->params['group'])) {
+ $query['group'] = $this->params['group'];
+ }
+ $show = $this->_queryString($show);
+ $query = $this->_queryString($query);
+
+ echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
+ echo " <a href='" . RUN_TEST_LINK . $query . "&amp;code_coverage=true'>Analyze Code Coverage</a></p>\n";
+ }
+/**
+ * Convert an array of parameters into a query string url
+ *
+ * @param array $url Url hash to be converted
+ * @return string Converted url query string
+ */
+ function _queryString($url) {
+ $out = '?';
+ $params = array();
+ foreach ($url as $key => $value) {
+ $params[] = "$key=$value";
+ }
+ $out .= implode('&amp;', $params);
+ return $out;
+ }
+
+/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
@@ -175,7 +236,7 @@ function paintFail($message) {
function paintPass($message) {
parent::paintPass($message);
- if ($this->_show_passes) {
+ if (isset($this->params['show_passes']) && $this->params['show_passes']) {
echo "<li class='pass'>\n";
echo "<span>Passed</span> ";
$breadcrumb = $this->getTestList();

0 comments on commit 3c57dbe

Please sign in to comment.