From 0f53569f83a8bfb321528ee74ff0e2924b0c2b42 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 25 Jun 2009 21:01:25 +0000 Subject: [PATCH] MDL-19579 code coverage - fix report paths and totals. Yay, I'm back! --- lib/simpletestcoveragelib.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/simpletestcoveragelib.php b/lib/simpletestcoveragelib.php index 7d034e0319e..a3c3f689f2d 100644 --- a/lib/simpletestcoveragelib.php +++ b/lib/simpletestcoveragelib.php @@ -332,6 +332,61 @@ class moodle_coverage_reporter extends HtmlCoverageReporter { global $CFG; parent::__construct($heading, '', $CFG->dataroot . '/codecoverage/' . $dir); } + + /** + * Writes one row in the index.html table to display filename + * and coverage recording. + * + * Overrided to transform names and links to shorter format + * + * @param $fileLink link to html details file. + * @param $realFile path to real PHP file. + * @param $fileCoverage Coverage recording for that file. + * @return string HTML code for a single row. + * @access protected + */ + protected function writeIndexFileTableRow($fileLink, $realFile, $fileCoverage) { + + global $CFG; + + $fileLink = str_replace($CFG->dirroot, '', $fileLink); + $realFile = str_replace($CFG->dirroot, '', $realFile); + + return parent::writeIndexFileTableRow($fileLink, $realFile, $fileCoverage);; + } + + /** + * Mark a source code file based on the coverage data gathered + * + * Overrided to transform names and links to shorter format + * + * @param $phpFile Name of the actual source file + * @param $fileLink Link to the html mark-up file for the $phpFile + * @param &$coverageLines Coverage recording for $phpFile + * @return boolean FALSE on failure + * @access protected + */ + protected function markFile($phpFile, $fileLink, &$coverageLines) { + global $CFG; + + $fileLink = str_replace($CFG->dirroot, '', $fileLink); + + return parent::markFile($phpFile, $fileLink, $coverageLines); + } + + + /** + * Update the grand totals + * + * Overrided to avoid the call to recordFileCoverageInfo() + * because it has been already executed by writeIndexFile() and + * cause files to be duplicated in the fileCoverage property + */ + protected function updateGrandTotals(&$coverageCounts) { + $this->grandTotalLines += $coverageCounts['total']; + $this->grandTotalCoveredLines += $coverageCounts['covered']; + $this->grandTotalUncoveredLines += $coverageCounts['uncovered']; + } }