diff --git a/question/type/match/lang/en/qtype_match.php b/question/type/match/lang/en/qtype_match.php index 72c857cfaab..83fc1142892 100644 --- a/question/type/match/lang/en/qtype_match.php +++ b/question/type/match/lang/en/qtype_match.php @@ -33,8 +33,6 @@ $string['nomatchinganswer'] = 'You must specify an answer matching the question $string['nomatchinganswerforq'] = 'You must specify an answer for this question.'; $string['notenoughqsandas'] = 'You must supply at least {$a->q} questions and {$a->a} answers.'; $string['notenoughquestions'] = 'You must supply at least {$a} question and answer pairs.'; -$string['shuffle'] = 'Shuffle'; -$string['shuffle_help'] = 'If enabled, the order of the questions is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled. In a matching question, only the questions are affected by this parameter. The answer choices will always be shuffled.'; $string['pleaseananswerallparts'] = 'Please answer all parts of the question.'; $string['pluginname'] = 'Matching'; $string['pluginname_help'] = 'Matching questions require the respondent to correctly match a list of names or statements (questions) to another list of names or statements (answers).'; @@ -46,3 +44,7 @@ $string['privacy:metadata'] = 'Matching question type plugin allows question aut $string['privacy:preference:defaultmark'] = 'The default mark set for a given question.'; $string['privacy:preference:penalty'] = 'The penalty for each incorrect try when questions are run using the \'Interactive with multiple tries\' or \'Adaptive mode\' behaviour.'; $string['privacy:preference:shuffleanswers'] = 'Whether the answers should be automatically shuffled.'; +$string['regradeissuenumchoiceschanged'] = 'The number of choices has changed.'; +$string['regradeissuenumstemschanged'] = 'The number of sub-questions has changed.'; +$string['shuffle'] = 'Shuffle'; +$string['shuffle_help'] = 'If enabled, the order of the questions is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled. In a matching question, only the questions are affected by this parameter. The answer choices will always be shuffled.'; diff --git a/question/type/match/question.php b/question/type/match/question.php index 15996ceca59..84c99d4f30b 100644 --- a/question/type/match/question.php +++ b/question/type/match/question.php @@ -107,6 +107,23 @@ class qtype_match_question extends question_graded_automatically_with_countback } } + public function validate_can_regrade_with_other_version(question_definition $otherversion): ?string { + $basemessage = parent::validate_can_regrade_with_other_version($otherversion); + if ($basemessage) { + return $basemessage; + } + + if (count($this->stems) != count($otherversion->stems)) { + return get_string('regradeissuenumstemschanged', 'qtype_match'); + } + + if (count($this->choices) != count($otherversion->choices)) { + return get_string('regradeissuenumchoiceschanged', 'qtype_match'); + } + + return null; + } + public function get_question_summary() { $question = $this->html_to_text($this->questiontext, $this->questiontextformat); $stems = array(); diff --git a/question/type/match/tests/question_test.php b/question/type/match/tests/question_test.php index 1419bac9d1f..e5532c4212b 100644 --- a/question/type/match/tests/question_test.php +++ b/question/type/match/tests/question_test.php @@ -33,6 +33,7 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); * @package qtype_match * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \qtype_match_question */ class question_test extends \advanced_testcase { @@ -244,4 +245,32 @@ class question_test extends \advanced_testcase { $options = $question->get_question_definition_for_external_rendering($qa, $displayoptions); $this->assertEquals(1, $options['shufflestems']); } + + public function test_validate_can_regrade_with_other_version_ok() { + $m = \test_question_maker::make_question('match'); + + $newm = clone($m); + + $this->assertNull($newm->validate_can_regrade_with_other_version($m)); + } + + public function test_validate_can_regrade_with_other_version_bad_stems() { + $m = \test_question_maker::make_question('match'); + + $newm = clone($m); + unset($newm->stems[4]); + + $this->assertEquals(get_string('regradeissuenumstemschanged', 'qtype_match'), + $newm->validate_can_regrade_with_other_version($m)); + } + + public function test_validate_can_regrade_with_other_version_bad_choices() { + $m = \test_question_maker::make_question('match'); + + $newm = clone($m); + unset($newm->choices[3]); + + $this->assertEquals(get_string('regradeissuenumchoiceschanged', 'qtype_match'), + $newm->validate_can_regrade_with_other_version($m)); + } }