Skip to content

Commit de99be4

Browse files
committed
Updates to get bultestall script working with enhanced bulk_tester class.
1 parent a350c35 commit de99be4

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

bulktestall.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
$title = get_string('bulktesttitle', 'qtype_coderunner', $context->get_context_name());
4646
$PAGE->set_title($title);
4747

48-
// Create the helper class.
49-
$bulktester = new qtype_coderunner_bulk_tester($context);
48+
5049
$numpasses = 0;
5150
$allfailingtests = [];
5251
$allmissinganswers = [];
@@ -60,14 +59,16 @@
6059
echo $OUTPUT->heading($title, 1);
6160

6261
// Run the tests.
63-
foreach ($bulktester->get_num_coderunner_questions_by_context() as $contextid => $numcoderunnerquestions) {
62+
$contextdata = qtype_coderunner_bulk_tester::get_num_coderunner_questions_by_context();
63+
foreach ($contextdata as $contextid => $numcoderunnerquestions) {
6464
if ($skipping && $contextid != $startfromcontextid) {
6565
continue;
6666
}
6767
$skipping = false;
68-
6968
$testcontext = context::instance_by_id($contextid);
7069
if (has_capability('moodle/question:editall', $context)) {
70+
$PAGE->set_context($testcontext); // Helps grading cache pickup right course id.
71+
$bulktester = new qtype_coderunner_bulk_tester($testcontext);
7172
echo $OUTPUT->heading(get_string('bulktesttitle', 'qtype_coderunner', $testcontext->get_context_name()));
7273
echo html_writer::tag('p', html_writer::link(
7374
new moodle_url(
@@ -77,13 +78,13 @@
7778
get_string('bulktestcontinuefromhere', 'qtype_coderunner')
7879
));
7980

80-
[$passes, $failingtests, $missinganswers] = $bulktester->run_all_tests_for_context($testcontext);
81+
[$passes, $failingtests, $missinganswers] = $bulktester->run_all_tests_for_context();
8182
$numpasses += $passes;
8283
$allfailingtests = array_merge($allfailingtests, $failingtests);
8384
$allmissinganswers = array_merge($allmissinganswers, $missinganswers);
8485
}
8586
}
8687

8788
// Display the final summary.
88-
$bulktester->print_overall_result($numpasses, $allfailingtests, $allmissinganswers);
89+
qtype_coderunner_bulk_tester::print_summary_after_bulktestall($numpasses, $allfailingtests, $allmissinganswers);
8990
echo $OUTPUT->footer();

classes/bulk_tester.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function run_all_tests_for_context($questionidstoinclude = []) {
313313
} else {
314314
$qparams['courseid'] = SITEID;
315315
}
316-
$questiontestsurl = new moodle_url('/question/type/coderunner/questiontestrun.php');
316+
$questiontestsurl = new moodle_url('/question/type/coderunner/questiontestrun.php');
317317
$questiontestsurl->params($qparams);
318318

319319
$this->numpasses = 0;
@@ -404,7 +404,7 @@ public function run_all_tests_for_context($questionidstoinclude = []) {
404404
}
405405
echo "</ul>\n";
406406
}
407-
return;
407+
return [$this->numpasses, $this->failedtestdetails, $this->missinganswerdetails];
408408
}
409409

410410

@@ -497,8 +497,6 @@ public function print_overall_result() {
497497
}
498498
echo html_writer::end_tag('ul');
499499
}
500-
501-
502500
if (count($this->failedtestdetails) > 0) {
503501
echo $OUTPUT->heading(get_string('coderunner_install_testsuite_failures', 'qtype_coderunner'), 5);
504502
echo html_writer::start_tag('ul');
@@ -532,6 +530,36 @@ public function print_overall_result() {
532530
echo html_writer::tag('p', $link);
533531
}
534532

533+
/**
534+
* Print an overall summary of the failed tests.
535+
*/
536+
public static function print_summary_after_bulktestall($numpasses, $allfailingtests, $allmissinganswers) {
537+
global $OUTPUT;
538+
echo $OUTPUT->heading(get_string('bulktestoverallresults', 'qtype_coderunner'), 5);
539+
$spacer = '&nbsp;&nbsp;|&nbsp;&nbsp;';
540+
$passstr = $numpasses . ' ' . get_string('passes', 'qtype_coderunner') . $spacer;
541+
$failstr = count($allfailingtests) . ' ' . get_string('fails', 'qtype_coderunner') . $spacer;
542+
$missingstr = count($allmissinganswers) . ' ' . get_string('missinganswers', 'qtype_coderunner');
543+
echo html_writer::tag('p', $passstr . $failstr . $missingstr);
544+
545+
if (count($allmissinganswers) > 0) {
546+
echo $OUTPUT->heading(get_string('coderunner_install_testsuite_noanswer', 'qtype_coderunner'), 5);
547+
echo html_writer::start_tag('ul');
548+
foreach ($allmissinganswers as $message) {
549+
echo html_writer::tag('li', $message);
550+
}
551+
echo html_writer::end_tag('ul');
552+
}
553+
if (count($allfailingtests) > 0) {
554+
echo $OUTPUT->heading(get_string('coderunner_install_testsuite_failures', 'qtype_coderunner'), 5);
555+
echo html_writer::start_tag('ul');
556+
foreach ($allfailingtests as $message) {
557+
echo html_writer::tag('li', $message);
558+
}
559+
echo html_writer::end_tag('ul');
560+
}
561+
}
562+
535563

536564
/**
537565
* Display the results of scanning all the CodeRunner questions to

0 commit comments

Comments
 (0)