Skip to content

Commit

Permalink
MDL-19579 code coverage - show link to latest complete report
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 26, 2009
1 parent f401842 commit e5d06af
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions admin/report/unittest/dbtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
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();

Expand Down
4 changes: 4 additions & 0 deletions admin/report/unittest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
}
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();
Expand Down
4 changes: 3 additions & 1 deletion lang/en_utf8/simpletest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
48 changes: 45 additions & 3 deletions lib/simpletestcoveragelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -451,7 +449,7 @@ static public function get_summary_info($type) {
$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);
Expand All @@ -470,6 +468,50 @@ static public function get_summary_info($type) {
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);
}
}


Expand Down

0 comments on commit e5d06af

Please sign in to comment.