Skip to content

Commit

Permalink
Refactoring methods from CakeTestMenu into CakeHtmlReporter.
Browse files Browse the repository at this point in the history
Updating CakeTestSuiteDispatcher to reflect removed methods.
  • Loading branch information
markstory committed Jan 6, 2010
1 parent f228990 commit 3c57dbe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 90 deletions.
77 changes: 0 additions & 77 deletions cake/tests/lib/cake_test_menu.php
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions cake/tests/lib/cake_test_suite_dispatcher.php
Expand Up @@ -38,7 +38,8 @@ class CakeTestSuiteDispatcher {
'app' => false,
'plugin' => null,
'output' => 'html',
'show' => 'groups'
'show' => 'groups',
'show_passes' => false
);

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -191,8 +192,6 @@ function _runGroupTest() {
CodeCoverageManager::report();
}
}
CakeTestMenu::runMore();
CakeTestMenu::analyzeCodeCoverage();
}

/**
Expand All @@ -211,8 +210,6 @@ function _runTestCase() {
if ($this->params['codeCoverage']) {
CodeCoverageManager::report();
}
CakeTestMenu::runMore();
CakeTestMenu::analyzeCodeCoverage();
}
}
?>
73 changes: 67 additions & 6 deletions cake/tests/lib/reporter/cake_html_reporter.php
Expand Up @@ -67,19 +67,33 @@ 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;
}

/**
Expand Down Expand Up @@ -139,9 +153,56 @@ 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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3c57dbe

Please sign in to comment.