MDL-19579 code coverage - show link to latest complete report

This commit is contained in:
stronk7 2009-06-26 17:07:33 +00:00
parent f40184265a
commit e5d06af22e
4 changed files with 57 additions and 4 deletions

View File

@ -138,6 +138,11 @@ echo '</div>';
echo '</form>';
echo $OUTPUT->box_end();
// Print link to latest code coverage for this report type
if (!data_submitted() || !$codecoverage) {
moodle_coverage_reporter::print_link_to_latest('dbtest');
}
// Footer.
admin_externalpage_print_footer();

View File

@ -142,6 +142,10 @@ if (true) {
}
echo $OUTPUT->box_end();
// Print link to latest code coverage for this report type
if (is_null($path) || !$codecoverage) {
moodle_coverage_reporter::print_link_to_latest('unittest');
}
// Footer.
admin_externalpage_print_footer();

View File

@ -5,8 +5,10 @@
$string['all'] = 'ALL';
$string['addconfigprefix'] = 'Add prefix to config file';
$string['codecoverageanalysis'] = 'Perform code coverage analysis.';
$string['codecoveragecompletereport'] = 'view code coverage complete report';
$string['codecoveragecompletereport'] = '(view code coverage complete report)';
$string['codecoveragedisabled'] = 'Cannot enable code coverage in this server (missing xdebug extension).';
$string['codecoveragelatestdetails'] = '(on $a->date, with $a->files files, $a->percentage covered)';
$string['codecoveragelatestreport'] = 'view latest code coverage complete report';
$string['confignonwritable'] = 'The file config.php is not writeable by the web server. Either change its permissions, or edit it with the appropriate user account, and add the following line before the closing php tag: <br />
\$CFG->unittestprefix = \'tst_\' // Change tst_ to a prefix of your choice, different from \$CFG->prefix';
$string['coveredlines'] = 'Covered lines';

View File

@ -28,8 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/// TODO: provide one helper function to show links from test page to coverage report
/**
* Includes
*/
@ -451,7 +449,7 @@ class moodle_coverage_reporter extends HtmlCoverageReporter {
$url = $CFG->wwwroot . '/admin/report/unittest/coveragefile.php/' . $type . '/index.html';
$result .= $OUTPUT->heading($data->title, 3, 'main codecoverageheading');
$result .= $OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');return false;"' .
' title="">(' . get_string('codecoveragecompletereport', 'simpletest') . ')</a>', 4, 'main codecoveragelink');
' title="">' . get_string('codecoveragecompletereport', 'simpletest') . '</a>', 4, 'main codecoveragelink');
$result .= print_table($table, true);
return $OUTPUT->box($result, 'generalbox boxwidthwide boxaligncenter codecoveragebox', '', true);
@ -470,6 +468,50 @@ class moodle_coverage_reporter extends HtmlCoverageReporter {
static public function print_summary_info($type) {
echo self::get_summary_info($type);
}
/**
* Return the html code needed to browse latest code coverage complete report of the
* given test type
*
* @param string $type of the test to return last execution summary (dbtest|unittest)
* @return string html contents of the summary
*/
static public function get_link_to_latest($type) {
global $CFG, $OUTPUT;
$serfilepath = $CFG->dataroot . '/codecoverage/' . $type . '/codecoverage.ser';
if (file_exists($serfilepath) && is_readable($serfilepath)) {
if ($data = unserialize(file_get_contents($serfilepath))) {
$info = new object();
$info->date = userdate($data->time);
$info->files = format_float($data->totalfiles, 0);
$info->percentage = format_float($data->totalpercentage, 2) . '%';
$strlatestreport = get_string('codecoveragelatestreport', 'simpletest');
$strlatestdetails = get_string('codecoveragelatestdetails', 'simpletest', $info);
// return one link to latest complete report
$result = '';
$url = $CFG->wwwroot . '/admin/report/unittest/coveragefile.php/' . $type . '/index.html';
$result .= $OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');return false;"' .
' title="">' . $strlatestreport . '</a>', 3, 'main codecoveragelink');
$result .= $OUTPUT->heading('<p>' . $strlatestdetails . '</p>', 4, 'main codecoveragedetails');
return $OUTPUT->box($result, 'generalbox boxwidthwide boxaligncenter codecoveragebox', '', true);
}
}
return false;
}
/**
* Print the html code needed to browse latest code coverage complete report of the
* given test type
*
* @param string $type of the test to return last execution summary (dbtest|unittest)
* @return string html contents of the summary
*/
static public function print_link_to_latest($type) {
echo self::get_link_to_latest($type);
}
}