diff --git a/question/behaviour/interactivecountback/tests/walkthrough_test.php b/question/behaviour/interactivecountback/tests/walkthrough_test.php index 583a41bce33..255cbe71eff 100644 --- a/question/behaviour/interactivecountback/tests/walkthrough_test.php +++ b/question/behaviour/interactivecountback/tests/walkthrough_test.php @@ -42,7 +42,7 @@ class qbehaviour_interactivecountback_walkthrough_test extends qbehaviour_walkth public function test_interactive_feedback_match_reset() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->shufflestems = false; $m->hints = array( new question_hint_with_parts(0, 'This is the first hint.', FORMAT_HTML, true, true), diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index d602098b828..32cd480597a 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -375,29 +375,7 @@ class test_question_maker { * @return qtype_match_question */ public static function make_a_matching_question() { - question_bank::load_question_definition_classes('match'); - $match = new qtype_match_question(); - self::initialise_a_question($match); - $match->name = 'Matching question'; - $match->questiontext = 'Classify the animals.'; - $match->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.'; - $match->qtype = question_bank::get_qtype('match'); - - $match->shufflestems = 1; - - self::set_standard_combined_feedback_fields($match); - - // Using unset to get 1-based arrays. - $match->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat'); - $match->stemformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML, FORMAT_HTML); - $match->choices = array('', 'Mammal', 'Amphibian', 'Insect'); - $match->right = array('', 1, 2, 2, 1); - unset($match->stems[0]); - unset($match->stemformat[0]); - unset($match->choices[0]); - unset($match->right[0]); - - return $match; + return self::make_question('match'); } /** diff --git a/question/type/match/question.php b/question/type/match/question.php index 41130100daf..6aba21d82fa 100644 --- a/question/type/match/question.php +++ b/question/type/match/question.php @@ -46,6 +46,8 @@ class qtype_match_question extends question_graded_automatically_with_countback /** @var array of question stems. */ public $stems; + /** @var int[] FORMAT_... type for each stem. */ + public $stemformat; /** @var array of choices that can be matched to each stem. */ public $choices; /** @var array index of the right choice for each stem. */ diff --git a/question/type/match/tests/helper.php b/question/type/match/tests/helper.php index 1e0aabbddd4..ee5ab4dd909 100644 --- a/question/type/match/tests/helper.php +++ b/question/type/match/tests/helper.php @@ -40,7 +40,6 @@ class qtype_match_test_helper extends question_test_helper { return array('foursubq'); } - /** * Makes a match question about completing two blanks in some text. * @return object the question definition data, as it might be returned from @@ -128,4 +127,36 @@ class qtype_match_test_helper extends question_test_helper { return $q; } + /** + * Makes a matching question to classify 'Dog', 'Frog', 'Toad' and 'Cat' as + * 'Mammal', 'Amphibian' or 'Insect'. + * defaultmark 1. Stems are shuffled by default. + * @return qtype_match_question + */ + public static function make_match_question_foursubq() { + question_bank::load_question_definition_classes('match'); + $match = new qtype_match_question(); + test_question_maker::initialise_a_question($match); + $match->name = 'Matching question'; + $match->questiontext = 'Classify the animals.'; + $match->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.'; + $match->qtype = question_bank::get_qtype('match'); + + $match->shufflestems = 1; + + test_question_maker::set_standard_combined_feedback_fields($match); + + // Using unset to get 1-based arrays. + $match->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat'); + $match->stemformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML, FORMAT_HTML); + $match->choices = array('', 'Mammal', 'Amphibian', 'Insect'); + $match->right = array('', 1, 2, 2, 1); + unset($match->stems[0]); + unset($match->stemformat[0]); + unset($match->choices[0]); + unset($match->right[0]); + + return $match; + } + } diff --git a/question/type/match/tests/question_test.php b/question/type/match/tests/question_test.php index 4e83431d2c3..67ab4012aa3 100644 --- a/question/type/match/tests/question_test.php +++ b/question/type/match/tests/question_test.php @@ -38,7 +38,7 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); class qtype_match_question_test extends advanced_testcase { public function test_get_expected_data() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array('sub0' => PARAM_INT, 'sub1' => PARAM_INT, @@ -46,7 +46,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_is_complete_response() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $this->assertFalse($question->is_complete_response(array())); @@ -58,7 +58,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_is_gradable_response() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $this->assertFalse($question->is_gradable_response(array())); @@ -72,7 +72,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_is_same_response() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $this->assertTrue($question->is_same_response( @@ -97,7 +97,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_grading() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $correctresponse = $question->prepare_simulated_post_data( @@ -126,7 +126,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_get_correct_response() { - $question = test_question_maker::make_a_matching_question(); + $question = test_question_maker::make_question('match'); $question->start_attempt(new question_attempt_step(), 1); $correct = $question->prepare_simulated_post_data(array('Dog' => 'Mammal', @@ -137,7 +137,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_get_question_summary() { - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $match->start_attempt(new question_attempt_step(), 1); $qsummary = $match->get_question_summary(); $this->assertRegExp('/' . preg_quote($match->questiontext, '/') . '/', $qsummary); @@ -150,7 +150,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_summarise_response() { - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $match->start_attempt(new question_attempt_step(), 1); $summary = $match->summarise_response($match->prepare_simulated_post_data(array('Dog' => 'Amphibian', 'Frog' => 'Mammal'))); @@ -160,7 +160,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_classify_response() { - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $match->start_attempt(new question_attempt_step(), 1); $response = $match->prepare_simulated_post_data(array('Dog' => 'Amphibian', 'Frog' => 'Insect', 'Toad' => '', 'Cat' => '')); @@ -182,14 +182,14 @@ class qtype_match_question_test extends advanced_testcase { } public function test_classify_response_choice_deleted_after_attempt() { - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $firststep = new question_attempt_step(); $match->start_attempt($firststep, 1); $response = $match->prepare_simulated_post_data(array( 'Dog' => 'Amphibian', 'Frog' => 'Insect', 'Toad' => '', 'Cat' => 'Mammal')); - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); unset($match->stems[4]); unset($match->stemsformat[4]); unset($match->right[4]); @@ -203,14 +203,14 @@ class qtype_match_question_test extends advanced_testcase { } public function test_classify_response_choice_added_after_attempt() { - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $firststep = new question_attempt_step(); $match->start_attempt($firststep, 1); $response = $match->prepare_simulated_post_data(array( 'Dog' => 'Amphibian', 'Frog' => 'Insect', 'Toad' => '', 'Cat' => 'Mammal')); - $match = test_question_maker::make_a_matching_question(); + $match = test_question_maker::make_question('match'); $match->stems[5] = "Snake"; $match->stemsformat[5] = FORMAT_HTML; $match->choices[5] = "Reptile"; @@ -226,7 +226,7 @@ class qtype_match_question_test extends advanced_testcase { } public function test_prepare_simulated_post_data() { - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->start_attempt(new question_attempt_step(), 1); $postdata = $m->prepare_simulated_post_data(array('Dog' => 'Mammal', 'Frog' => 'Amphibian', 'Toad' => 'Amphibian', 'Cat' => 'Mammal')); diff --git a/question/type/match/tests/walkthrough_test.php b/question/type/match/tests/walkthrough_test.php index f5bd7af8b7f..b7930406041 100644 --- a/question/type/match/tests/walkthrough_test.php +++ b/question/type/match/tests/walkthrough_test.php @@ -41,7 +41,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_deferred_feedback_unanswered() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->shufflestems = false; $this->start_attempt_at_question($m, 'deferredfeedback', 4); @@ -98,7 +98,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_deferred_feedback_partial_answer() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->shufflestems = false; $this->start_attempt_at_question($m, 'deferredfeedback', 4); @@ -155,7 +155,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_interactive_correct_no_submit() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->hints = array( new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), @@ -209,7 +209,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_interactive_partial_no_submit() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->hints = array( new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), @@ -263,7 +263,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_interactive_with_invalid() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->hints = array( new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), @@ -333,7 +333,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_match_with_tricky_html_choices() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->stems = array( 1 => '(1, 2]', 2 => '[1, 2]', @@ -387,7 +387,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base { public function test_match_clear_wrong() { // Create a matching question. - $m = test_question_maker::make_a_matching_question(); + $m = test_question_maker::make_question('match'); $m->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),