Skip to content

Commit

Permalink
Adding a toggle all button to the coverage report. Makes it easier to…
Browse files Browse the repository at this point in the history
… see the test subject at a glance.

Adding ability to only show files that match the extension-less basename of the test case file.  This hides much of the noise the new reports have.
  • Loading branch information
markstory committed May 10, 2010
1 parent e8e2235 commit 687eab9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
49 changes: 45 additions & 4 deletions cake/tests/lib/coverage/html_coverage_report.php
Expand Up @@ -25,16 +25,34 @@ class HtmlCoverageReport {
*/
protected $_rawCoverage;

/**
* is the test an app test
*
* @var string
*/
public $appTest = false;

/**
* is the test a plugin test
*
* @var string
*/
public $pluginTest = false;

/**
* is the test a group test?
*
* @var string
*/
public $groupTest = false;

/**
* Number of lines to provide around an uncovered code block
* Array of test case file names. Used to do basename() matching with
* files that have coverage to decide which results to show on page load.
*
* @var integer
* @var array
*/
public $numDiffContextLines = 7;
protected $_testNames = array();

/**
* Constructor
Expand Down Expand Up @@ -85,6 +103,11 @@ public function report() {
return '<h3>No files to generate coverage for</h3>';
}
$output = $this->coverageScript();
$output .= <<<HTML
<h3>Code coverage results
<a href="#" onclick="coverage_toggle_all()" class="coverage-toggle">Toggle all files</a>
</h3>
HTML;
foreach ($coverageData as $file => $coverageData) {
$fileData = file($file);
$output .= $this->generateDiff($file, $fileData, $coverageData);
Expand Down Expand Up @@ -138,6 +161,11 @@ public function filterCoverageDataByPath($path) {
$files[$filename]['executable'] += $executable;
$files[$filename]['dead'] += $dead;
}
if (isset($testRun['test'])) {
$testReflection = new ReflectionClass(get_class($testRun['test']));
list($fileBasename, $x) = explode('.', basename($testReflection->getFileName()), 2);
$this->_testNames[] = $fileBasename;
}
}
ksort($files);
return $files;
Expand Down Expand Up @@ -209,6 +237,15 @@ function coverage_show_hide(selector) {
var element = document.getElementById(selector);
element.style.display = (element.style.display == 'none') ? '' : 'none';
}
function coverage_toggle_all () {
var divs = document.querySelectorAll('div.coverage-container');
var i = divs.length;
while (i--) {
if (divs[i] && divs[i].className.indexOf('primary') == -1) {
divs[i].style.display = (divs[i].style.display == 'none') ? '' : 'none';
}
}
}
</script>
HTML;
}
Expand All @@ -220,7 +257,11 @@ function coverage_show_hide(selector) {
*/
public function coverageHeader($filename, $percent) {
$filename = basename($filename);
list($file, $ext) = explode('.', $filename);
$display = in_array($file, $this->_testNames) ? 'block' : 'none';
$primary = $display == 'block' ? 'primary' : '';
return <<<HTML
<div class="coverage-container $primary" style="display:$display;">
<h4>
<a href="#coverage-$filename" onclick="coverage_show_hide('coverage-$filename');">
$filename Code coverage: $percent%
Expand All @@ -237,6 +278,6 @@ public function coverageHeader($filename, $percent) {
* @return void
*/
public function coverageFooter() {
return "</pre></div>";
return "</pre></div></div>";
}
}
8 changes: 8 additions & 0 deletions cake/tests/lib/templates/header.php
Expand Up @@ -79,6 +79,14 @@
display:block;
margin-left:10px;
}
.coverage-toggle {
float:right;
margin-top:10px;
font-size:12px;
}
.coverage-container {
margin-top:1em;
}
div.code-coverage-results div.uncovered span.content { background:#ecc; }
div.code-coverage-results div.covered span.content { background:#cec; }
div.code-coverage-results div.ignored span.content { color:#aaa; }
Expand Down

0 comments on commit 687eab9

Please sign in to comment.