Refactoring methods from CakeTestMenu into CakeHtmlReporter.

Updating CakeTestSuiteDispatcher to reflect removed methods.
This commit is contained in:
Mark Story 2010-01-05 22:20:32 -05:00
parent f228990c58
commit 3c57dbee04
3 changed files with 71 additions and 90 deletions

View file

@ -18,83 +18,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
class CakeTestMenu { 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 * Prints a list of test cases

View file

@ -38,7 +38,8 @@ class CakeTestSuiteDispatcher {
'app' => false, 'app' => false,
'plugin' => null, 'plugin' => null,
'output' => 'html', 'output' => 'html',
'show' => 'groups' 'show' => 'groups',
'show_passes' => false
); );
/** /**
@ -143,9 +144,9 @@ class CakeTestSuiteDispatcher {
$appClass = $this->params['output'] . 'Reporter'; $appClass = $this->params['output'] . 'Reporter';
$appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php'; $appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php';
if (include_once $coreFile) { if (include_once $coreFile) {
$Reporter =& new $coreClass(); $Reporter =& new $coreClass(null, $this->params);
} elseif (include_once $appFile) { } elseif (include_once $appFile) {
$Reporter =& new $appClass(); $Reporter =& new $appClass(null, $this->params);
} }
} }
return $Reporter; return $Reporter;
@ -191,8 +192,6 @@ class CakeTestSuiteDispatcher {
CodeCoverageManager::report(); CodeCoverageManager::report();
} }
} }
CakeTestMenu::runMore();
CakeTestMenu::analyzeCodeCoverage();
} }
/** /**
@ -211,8 +210,6 @@ class CakeTestSuiteDispatcher {
if ($this->params['codeCoverage']) { if ($this->params['codeCoverage']) {
CodeCoverageManager::report(); CodeCoverageManager::report();
} }
CakeTestMenu::runMore();
CakeTestMenu::analyzeCodeCoverage();
} }
} }
?> ?>

View file

@ -67,19 +67,33 @@ class CakeHtmlReporter extends SimpleReporter {
*/ */
var $_timeDuration = 0; var $_timeDuration = 0;
/**
* Array of request parameters. Usually parsed GET params.
*
* @var array
*/
var $params = array();
/** /**
* Does nothing yet. The first output will * Does nothing yet. The first output will
* be sent on the first test start. For use * be sent on the first test start. For use
* by a web browser. * 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 * @access public
*/ */
function CakeHtmlReporter($character_set = 'ISO-8859-1') { function CakeHtmlReporter($character_set = 'ISO-8859-1', $params = array()) {
if (isset($_GET['show_passes']) && $_GET['show_passes']) {
$this->_show_passes = true;
}
$this->SimpleReporter(); $this->SimpleReporter();
$this->_character_set = $character_set; $this->_character_set = !empty($character_set) ? $character_set : 'ISO-8859-1';
$this->params = $params;
} }
/** /**
@ -139,9 +153,56 @@ class CakeHtmlReporter extends SimpleReporter {
if (function_exists('memory_get_peak_usage')) { if (function_exists('memory_get_peak_usage')) {
echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>'; echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
} }
echo $this->_paintLinks();
echo '</div>'; 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 * Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the * trail of the nesting test suites below the
@ -175,7 +236,7 @@ class CakeHtmlReporter extends SimpleReporter {
function paintPass($message) { function paintPass($message) {
parent::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 "<li class='pass'>\n";
echo "<span>Passed</span> "; echo "<span>Passed</span> ";
$breadcrumb = $this->getTestList(); $breadcrumb = $this->getTestList();