From 3c57dbee04ca1774fae1ae7cf07e6d4a282cb6e8 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 5 Jan 2010 22:20:32 -0500 Subject: [PATCH] Refactoring methods from CakeTestMenu into CakeHtmlReporter. Updating CakeTestSuiteDispatcher to reflect removed methods. --- cake/tests/lib/cake_test_menu.php | 77 ------------------- cake/tests/lib/cake_test_suite_dispatcher.php | 11 +-- .../tests/lib/reporter/cake_html_reporter.php | 73 ++++++++++++++++-- 3 files changed, 71 insertions(+), 90 deletions(-) diff --git a/cake/tests/lib/cake_test_menu.php b/cake/tests/lib/cake_test_menu.php index 7099bca54..c2f920de9 100644 --- a/cake/tests/lib/cake_test_menu.php +++ b/cake/tests/lib/cake_test_menu.php @@ -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 "

Run more tests | Show Passes | \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 .= '&app=true'; - } elseif (isset($_GET['plugin'])) { - $query .= '&plugin=' . $_GET['plugin']; - } - } else { - $query = '?group='.$_GET['group']; - if (isset($_GET['app'])) { - $query .= '&app=true'; - } elseif (isset($_GET['plugin'])) { - $query .= '&plugin=' . $_GET['plugin']; - } - } - $query .= '&code_coverage=true'; - ob_start(); - echo " Analyze Code Coverage

\n"; - - break; - } - } /** * Prints a list of test cases diff --git a/cake/tests/lib/cake_test_suite_dispatcher.php b/cake/tests/lib/cake_test_suite_dispatcher.php index 29092a583..ebea5f42c 100644 --- a/cake/tests/lib/cake_test_suite_dispatcher.php +++ b/cake/tests/lib/cake_test_suite_dispatcher.php @@ -38,7 +38,8 @@ class CakeTestSuiteDispatcher { 'app' => false, 'plugin' => null, 'output' => 'html', - 'show' => 'groups' + 'show' => 'groups', + 'show_passes' => false ); /** @@ -143,9 +144,9 @@ class CakeTestSuiteDispatcher { $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 @@ class CakeTestSuiteDispatcher { CodeCoverageManager::report(); } } - CakeTestMenu::runMore(); - CakeTestMenu::analyzeCodeCoverage(); } /** @@ -211,8 +210,6 @@ class CakeTestSuiteDispatcher { if ($this->params['codeCoverage']) { CodeCoverageManager::report(); } - CakeTestMenu::runMore(); - CakeTestMenu::analyzeCodeCoverage(); } } ?> \ No newline at end of file diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php index 6f7c699f0..a24fb85aa 100644 --- a/cake/tests/lib/reporter/cake_html_reporter.php +++ b/cake/tests/lib/reporter/cake_html_reporter.php @@ -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; } /** @@ -139,9 +153,56 @@ class CakeHtmlReporter extends SimpleReporter { if (function_exists('memory_get_peak_usage')) { echo '

Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . '

'; } + echo $this->_paintLinks(); echo ''; } +/** + * 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 "

Run more tests | Show Passes | \n"; + echo " Analyze Code Coverage

\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('&', $params); + return $out; + } + /** * Paints the test failure with a breadcrumbs * trail of the nesting test suites below the @@ -175,7 +236,7 @@ class CakeHtmlReporter extends SimpleReporter { function paintPass($message) { parent::paintPass($message); - if ($this->_show_passes) { + if (isset($this->params['show_passes']) && $this->params['show_passes']) { echo "
  • \n"; echo "Passed "; $breadcrumb = $this->getTestList();