Skip to content
Permalink
Browse files

Updating coverage report and tests to include hiding javascript.

  • Loading branch information...
markstory committed May 10, 2010
1 parent f084a82 commit e8e2235cfa2c48d7bd1e1daf757060bda94dfa8e
@@ -173,8 +173,8 @@ function testGenerateDiff() {
)
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/<h2>myfile\.php Code coverage\: \d+\.?\d*\%<\/h2>/', $result);
$this->assertRegExp('/<div class="code-coverage-results">/', $result);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
@@ -84,7 +84,7 @@ public function report() {
if (empty($coverageData)) {
return '<h3>No files to generate coverage for</h3>';
}
$output = '';
$output = $this->coverageScript();
foreach ($coverageData as $file => $coverageData) {
$fileData = file($file);
$output .= $this->generateDiff($file, $fileData, $coverageData);
@@ -197,6 +197,21 @@ protected function _paintLine($line, $linenumber, $class) {
);
}
/**
* generate some javascript for the coverage report.
*
* @return void
*/
public function coverageScript() {
return <<<HTML
<script type="text/javascript">
function coverage_show_hide(selector) {
var element = document.getElementById(selector);
element.style.display = (element.style.display == 'none') ? '' : 'none';
}
</script>
HTML;
}
/**
* Generate an HTML snippet for coverage headers
@@ -206,8 +221,12 @@ protected function _paintLine($line, $linenumber, $class) {
public function coverageHeader($filename, $percent) {
$filename = basename($filename);
return <<<HTML
<h2>$filename Code coverage: $percent%</h2>
<div class="code-coverage-results">
<h4>
<a href="#coverage-$filename" onclick="coverage_show_hide('coverage-$filename');">
$filename Code coverage: $percent%
</a>
</h4>
<div class="code-coverage-results" id="coverage-$filename" style="display:none;">
<pre>
HTML;
}

0 comments on commit e8e2235

Please sign in to comment.
You can’t perform that action at this time.