Skip to content

Commit

Permalink
MDL-66115 qtype_ddimageortext: Fixing choice deletion.
Browse files Browse the repository at this point in the history
Summarising responses fails when question choices have been removed.

AMOS BEGIN
CPY [deletedchoice,qtype_match],[deletedchoice,qtype_ddimageortext]
AMOS END

(cherry picked from commit f0265e6)
  • Loading branch information
dvdcastro committed Jul 12, 2019
1 parent f7e1084 commit 39260e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Expand Up @@ -70,3 +70,4 @@
$string['summariseplaceno'] = 'Drop zone {$a}';
$string['xleft'] = 'Left';
$string['ytop'] = 'Top';
$string['deletedchoice'] = '[Deleted choice]';
6 changes: 5 additions & 1 deletion question/type/ddimageortext/questionbase.php
Expand Up @@ -62,7 +62,11 @@ public function summarise_response(array $response) {
$response[$this->field($placeno)]) {
$selected = $this->get_selected_choice($place->group,
$response[$this->field($placeno)]);
$summarisechoice = $selected->summarise();
if (isset($selected)) {
$summarisechoice = $selected->summarise();
} else {
$summarisechoice = get_string('deletedchoice', 'qtype_ddimageortext');
}
$allblank = false;
} else {
$summarisechoice = '';
Expand Down
15 changes: 15 additions & 0 deletions question/type/ddimageortext/tests/question_test.php
Expand Up @@ -266,4 +266,19 @@ public function test_classify_response() {
4 => new question_classified_response(4, '4. dog', 1)
), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
}

public function test_summarise_response_choice_deleted() {
/** @var qtype_ddtoimage_question_base $dd */
$dd = test_question_maker::make_question('ddimageortext');
$dd->shufflechoices = false;
$dd->start_attempt(new question_attempt_step(), 1);
// Simulation of an instructor deleting 1 choice after an attempt has been made.
unset($dd->choices[1][1]);
$delquestionstr = get_string('deletedchoice', 'qtype_ddimageortext');
$this->assertEquals("Drop zone 1 -> {{$delquestionstr}} ".
"Drop zone 2 -> {{$delquestionstr}} ".
'Drop zone 3 -> {3. lazy} '.
'Drop zone 4 -> {3. lazy}',
$dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
}
}
2 changes: 1 addition & 1 deletion question/type/gapselect/questionbase.php
Expand Up @@ -127,7 +127,7 @@ public function get_question_summary() {

protected function get_selected_choice($group, $shuffledchoicenumber) {
$choiceno = $this->choiceorder[$group][$shuffledchoicenumber];
return $this->choices[$group][$choiceno];
return isset($this->choices[$group][$choiceno]) ? $this->choices[$group][$choiceno] : null;
}

public function summarise_response(array $response) {
Expand Down

0 comments on commit 39260e3

Please sign in to comment.