MDL-49041 qtype_multianswer: don't reveal marks on partial responses

This commit also fixes MDL-32049 about the lack or valdiation message
when an incomplete respnses is submitted.

AMOS BEGIN
 CPY [pleaseananswerallparts,qtype_match],[pleaseananswerallparts,qtype_multianswer]
AMOS END
This commit is contained in:
Tim Hunt
2015-02-05 20:00:53 +00:00
parent 96dc38c46a
commit c3ab0b8bbf
5 changed files with 73 additions and 8 deletions
@@ -71,6 +71,10 @@ class qbehaviour_interactive extends question_behaviour_with_multiple_tries {
// We only need different behaviour in try again states.
if (!$this->is_try_again_state()) {
parent::adjust_display_options($options);
if ($this->qa->get_state() == question_state::$invalid &&
$options->marks == question_display_options::MARK_AND_MAX) {
$options->marks = question_display_options::MAX_ONLY;
}
return;
}
@@ -35,6 +35,7 @@ $string['layoutundefined'] = 'Undefined layout';
$string['layoutvertical'] = 'Vertical column of radio buttons';
$string['nooptionsforsubquestion'] = 'Unable to get options for question part # {$a->sub} (question->id={$a->id})';
$string['noquestions'] = 'The Cloze(multianswer) question "<strong>{$a}</strong>" does not contain any question';
$string['pleaseananswerallparts'] = 'Please answer all parts of the question.';
$string['pluginname'] = 'Embedded answers (Cloze)';
$string['pluginname_help'] = 'Embedded answers (Cloze) questions consist of a passage of text with questions such as multiple-choice and short answer embedded within it.';
$string['pluginname_link'] = 'question/type/multianswer';
+3 -5
View File
@@ -207,12 +207,10 @@ class qtype_multianswer_question extends question_graded_automatically_with_coun
}
public function get_validation_error(array $response) {
$errors = array();
foreach ($this->subquestions as $i => $subq) {
$substep = $this->get_substep(null, $i);
$errors[] = $subq->get_validation_error($substep->filter_array($response));
if ($this->is_complete_response($response)) {
return '';
}
return implode('<br />', $errors);
return get_string('pleaseananswerallparts', 'qtype_multianswer');
}
/**
+6
View File
@@ -55,6 +55,12 @@ class qtype_multianswer_renderer extends qtype_renderer {
$qa, 'question', 'questiontext', $question->id);
}
if ($qa->get_state() == question_state::$invalid) {
$output .= html_writer::nonempty_tag('div',
$question->get_validation_error($qa->get_last_qt_data()),
array('class' => 'validationerror'));
}
$this->page->requires->js_init_call('M.qtype_multianswer.init',
array('#q' . $qa->get_slot()), false, array(
'name' => 'qtype_multianswer',
@@ -67,7 +67,7 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
$this->check_current_output(
$this->get_contains_marked_out_of_summary(),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_validation_error_expectation()); // TODO, really, it should. See MDL-32049.
$this->get_contains_validation_error_expectation());
// Save a partially correct answer.
$this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1',
@@ -207,7 +207,7 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, true),
new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true),
);
$choices = array('' => '', '0' => 'Califormia', '1' => 'Arizona');
$choices = array('' => '', '0' => 'California', '1' => 'Arizona');
$this->start_attempt_at_question($q, 'interactive', 4);
@@ -322,6 +322,62 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
$this->get_no_hint_visible_expectation());
}
public function test_interactive_partial_response_does_not_reveal_answer() {
// Create a multianswer question.
$q = test_question_maker::make_question('multianswer', 'fourmc');
$q->hints = array(
new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, true),
new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true),
);
$choices = array('' => '', '0' => 'California', '1' => 'Arizona');
$this->start_attempt_at_question($q, 'interactive', 4);
// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->assertEquals('interactivecountback',
$this->quba->get_question_attempt($this->slot)->get_behaviour_name());
$this->check_current_output(
$this->get_contains_marked_out_of_summary(),
$this->get_contains_select_expectation('sub1_answer', $choices, null, true),
$this->get_contains_select_expectation('sub2_answer', $choices, null, true),
$this->get_contains_select_expectation('sub3_answer', $choices, null, true),
$this->get_contains_select_expectation('sub4_answer', $choices, null, true),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_validation_error_expectation(),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation());
// Submit an incomplete response response.
$this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1', '-submit' => 1));
// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_select_expectation('sub1_answer', $choices, 1, true),
$this->get_contains_select_expectation('sub2_answer', $choices, 1, true),
$this->get_contains_select_expectation('sub3_answer', $choices, null, true),
$this->get_contains_select_expectation('sub4_answer', $choices, null, true),
$this->get_does_not_contain_num_parts_correct(),
$this->get_contains_validation_error_expectation(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_does_not_contain_correctness_expectation(),
$this->get_no_hint_visible_expectation());
$this->render();
$a = array('mark' => '0.00', 'max' => '1.00');
$this->assertNotRegExp('~' . preg_quote(get_string('markoutofmax', 'question', $a), '~') . '~',
$this->currentoutput);
$a['mark'] = '1.00';
$this->assertNotRegExp('~' . preg_quote(get_string('markoutofmax', 'question', $a), '~') . '~',
$this->currentoutput);
}
public function test_interactivecountback_feedback() {
// Create a multianswer question.
@@ -330,7 +386,7 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, true, true),
new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true),
);
$choices = array('' => '', '0' => 'Califormia', '1' => 'Arizona');
$choices = array('' => '', '0' => 'California', '1' => 'Arizona');
$this->start_attempt_at_question($q, 'interactive', 12);