Merge branch 'MDL-34226' of git://github.com/timhunt/moodle

This commit is contained in:
Dan Poltawski 2012-07-23 13:53:46 +08:00
commit bdaff201bb
3 changed files with 95 additions and 39 deletions

View file

@ -38,7 +38,7 @@ require_once($CFG->dirroot . '/question/type/multianswer/question.php');
*/ */
class qtype_multianswer_test_helper extends question_test_helper { class qtype_multianswer_test_helper extends question_test_helper {
public function get_test_questions() { public function get_test_questions() {
return array('twosubq'); return array('twosubq', 'fourmc');
} }
/** /**
@ -54,6 +54,14 @@ class qtype_multianswer_test_helper extends question_test_helper {
'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".';
$q->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' . $q->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' .
'"The owl and the pussycat went to sea'; '"The owl and the pussycat went to sea';
$q->qtype = question_bank::get_qtype('multianswer');
$q->textfragments = array(
'Complete this opening line of verse: "The ',
' and the ',
' went to sea".',
);
$q->places = array('1' => '1', '2' => '2');
// Shortanswer subquestion. // Shortanswer subquestion.
question_bank::load_question_definition_classes('shortanswer'); question_bank::load_question_definition_classes('shortanswer');
@ -214,4 +222,69 @@ class qtype_multianswer_test_helper extends question_test_helper {
return $formdata; return $formdata;
} }
/**
* Makes a multianswer question about completing two blanks in some text.
* @return qtype_multianswer_question
*/
public function make_multianswer_question_fourmc() {
question_bank::load_question_definition_classes('multianswer');
$q = new qtype_multianswer_question();
test_question_maker::initialise_a_question($q);
$q->name = 'Multianswer four multi-choice';
$q->questiontext = '<p>Match the following cities with the correct state:</p>
<ul>
<li>San Francisco: {#1}</li>
<li>Tucson: {#2}</li>
<li>Los Angeles: {#3}</li>
<li>Phoenix: {#4}</li>
</ul>';
$q->questiontextformat = FORMAT_HTML;
$q->generalfeedback = '';
$q->qtype = question_bank::get_qtype('multianswer');
$q->textfragments = array('<p>Match the following cities with the correct state:</p>
<ul>
<li>San Francisco: ', '</li>
<li>Tucson: ', '</li>
<li>Los Angeles: ', '</li>
<li>Phoenix: ', '</li>
</ul>');
$q->places = array('1' => '1', '2' => '2', '3' => '3', '4' => '4');
$subqdata = array(
1 => array('qt' => '{1:MULTICHOICE:=California#OK~Arizona#Wrong}', 'California' => 'OK', 'Arizona' => 'Wrong'),
2 => array('qt' => '{1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}', 'California' => 'Wrong', 'Arizona' => 'OK'),
3 => array('qt' => '{1:MULTICHOICE:=California#OK~Arizona#Wrong}', 'California' => 'OK', 'Arizona' => 'Wrong'),
4 => array('qt' => '{1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}', 'California' => 'Wrong', 'Arizona' => 'OK'),
);
foreach ($subqdata as $i => $data) {
// Multiple-choice subquestion.
question_bank::load_question_definition_classes('multichoice');
$mc = new qtype_multichoice_single_question();
test_question_maker::initialise_a_question($mc);
$mc->name = 'Multianswer four multi-choice';
$mc->questiontext = $data['qt'];
$mc->questiontextformat = FORMAT_HTML;
$mc->generalfeedback = '';
$mc->generalfeedbackformat = FORMAT_HTML;
$mc->shuffleanswers = 0; // TODO this is a cheat to make the unit tests easier to write.
// In reality, multianswer questions always shuffle.
$mc->answernumbering = 'none';
$mc->layout = qtype_multichoice_base::LAYOUT_DROPDOWN;
$mc->answers = array(
10 * $i => new question_answer(13, 'California', $data['California'] == 'OK', $data['California'], FORMAT_HTML),
10 * $i + 1 => new question_answer(14, 'Arizona', $data['Arizona'] == 'OK', $data['Arizona'], FORMAT_HTML),
);
$mc->qtype = question_bank::get_qtype('multichoice');
$mc->maxmark = 1;
$q->subquestions[$i] = $mc;
}
return $q;
}
} }

View file

@ -37,70 +37,53 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_base { class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_base {
public function test_interactive() { public function test_deferred_feedback() {
return; // TODO
// Create a gapselect question. // Create a gapselect question.
$q = test_question_maker::make_question('calculated'); $q = test_question_maker::make_question('multianswer', 'fourmc');
$q->hints = array( $this->start_attempt_at_question($q, 'deferredfeedback', 4);
new question_hint(1, 'This is the first hint.', FORMAT_HTML),
new question_hint(2, 'This is the second hint.', FORMAT_HTML),
);
$this->start_attempt_at_question($q, 'interactive', 3);
$values = $q->vs->get_values();
// Check the initial state. // Check the initial state.
$this->check_current_state(question_state::$todo); $this->check_current_state(question_state::$todo);
$this->check_current_mark(null); $this->check_current_mark(null);
$this->check_current_output( $this->check_current_output(
$this->get_contains_marked_out_of_summary(), $this->get_contains_marked_out_of_summary(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_validation_error_expectation(), $this->get_does_not_contain_validation_error_expectation());
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_no_hint_visible_expectation());
// Submit blank. // Save in incomplete answer.
$this->process_submission(array('-submit' => 1, 'answer' => '')); $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '',
'sub3_answer' => '', 'sub4_answer' => ''));
// Verify. // Verify.
$this->check_current_state(question_state::$invalid); $this->check_current_state(question_state::$invalid);
$this->check_current_mark(null); $this->check_current_mark(null);
$this->check_current_output( $this->check_current_output(
$this->get_contains_marked_out_of_summary(), $this->get_contains_marked_out_of_summary(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_feedback_expectation(),
$this->get_contains_validation_error_expectation(), $this->get_does_not_contain_validation_error_expectation()); // TODO, really, it should. See MDL-32049.
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_no_hint_visible_expectation());
// Sumit something that does not look like a number. // Save a partially correct answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'newt')); $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1',
'sub3_answer' => '1', 'sub4_answer' => '1'));
// Verify. // Verify.
$this->check_current_state(question_state::$invalid); $this->check_current_state(question_state::$complete);
$this->check_current_mark(null); $this->check_current_mark(null);
$this->check_current_output( $this->check_current_output(
$this->get_contains_marked_out_of_summary(), $this->get_contains_marked_out_of_summary(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_feedback_expectation(),
$this->get_contains_validation_error_expectation(), $this->get_does_not_contain_validation_error_expectation());
new question_pattern_expectation('/' .
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_no_hint_visible_expectation());
// Now get it right. // Now submit all and finish.
$this->process_submission(array('-submit' => 1, 'answer' => $values['a'] + $values['b'])); $this->process_submission(array('-finish' => 1));
// Verify. // Verify.
$this->check_current_state(question_state::$gradedright); $this->check_current_state(question_state::$gradedpartial);
$this->check_current_mark(3); $this->check_current_mark(2);
$this->check_current_output( $this->check_current_output(
$this->get_contains_mark_summary(3), $this->get_contains_mark_summary(2),
$this->get_contains_submit_button_expectation(false), $this->get_contains_partcorrect_expectation(),
$this->get_contains_correct_expectation(), $this->get_does_not_contain_validation_error_expectation());
$this->get_does_not_contain_validation_error_expectation(),
$this->get_no_hint_visible_expectation());
} }
} }

View file

@ -199,7 +199,7 @@ class qtype_multichoice_single_question extends qtype_multichoice_base {
} }
public function is_complete_response(array $response) { public function is_complete_response(array $response) {
return array_key_exists('answer', $response); return array_key_exists('answer', $response) && $response['answer'] !== '';
} }
public function is_gradable_response(array $response) { public function is_gradable_response(array $response) {