Merge branch 'MDL-77912_401' of https://github.com/timhunt/moodle into MOODLE_401_STABLE

This commit is contained in:
Jake Dallimore 2023-07-13 10:09:45 +08:00
commit a6b769bddd
No known key found for this signature in database
2 changed files with 17 additions and 3 deletions

View File

@ -244,6 +244,13 @@ class qtype_multichoice extends question_type {
return null;
}
if (empty($questiondata->options->answers)) {
// A multi-choice question with no choices is senseless,
// but, seemingly, it can happen (presumably as a side-effect of bugs).
// Therefore, ensure it does not lead to errors here.
return null;
}
// Single choice questions - average choice fraction.
$totalfraction = 0;
foreach ($questiondata->options->answers as $answer) {

View File

@ -31,9 +31,10 @@ require_once($CFG->dirroot . '/question/type/multichoice/edit_multichoice_form.p
/**
* Unit tests for the multiple choice question definition class.
*
* @package qtype_multichoice
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_multichoice
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qtype_multichoice
*/
class question_type_test extends \advanced_testcase {
protected $qtype;
@ -72,6 +73,12 @@ class question_type_test extends \advanced_testcase {
$this->assertEquals(0.5, $this->qtype->get_random_guess_score($q));
}
public function test_get_random_guess_score_broken_question() {
$q = $this->get_test_question_data();
$q->options->answers = [];
$this->assertNull($this->qtype->get_random_guess_score($q));
}
public function test_get_random_guess_score_multi() {
$q = $this->get_test_question_data();
$q->options->single = false;