MDL-64420 qtype: gapselect unit tests unsafe
[moodle.git] / question / type / match / tests / walkthrough_test.php
index 403d8d3..f5bd7af 100644 (file)
@@ -56,12 +56,13 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
+                $this->get_contains_question_text_expectation($m),
+                $this->get_does_not_contain_feedback_expectation());
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, null, true),
                 $this->get_contains_select_expectation('sub1', $choices, null, true),
                 $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
-                $this->get_contains_question_text_expectation($m),
-                $this->get_does_not_contain_feedback_expectation());
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
         $this->check_step_count(1);
 
         // Save a blank response.
@@ -72,12 +73,13 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
+                $this->get_contains_question_text_expectation($m),
+                $this->get_does_not_contain_feedback_expectation());
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, null, true),
                 $this->get_contains_select_expectation('sub1', $choices, null, true),
                 $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
-                $this->get_contains_question_text_expectation($m),
-                $this->get_does_not_contain_feedback_expectation());
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
         $this->check_step_count(1);
 
         // Finish the attempt.
@@ -86,7 +88,7 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         // Verify.
         $this->check_current_state(question_state::$gaveup);
         $this->check_current_mark(null);
-        $this->check_current_output(
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, null, false),
                 $this->get_contains_select_expectation('sub1', $choices, null, false),
                 $this->get_contains_select_expectation('sub2', $choices, null, false),
@@ -111,12 +113,13 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
+                $this->get_contains_question_text_expectation($m),
+                $this->get_does_not_contain_feedback_expectation());
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, null, true),
                 $this->get_contains_select_expectation('sub1', $choices, null, true),
                 $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
-                $this->get_contains_question_text_expectation($m),
-                $this->get_does_not_contain_feedback_expectation());
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Save a partial response.
         $this->process_submission(array('sub0' => $orderforchoice[1],
@@ -126,12 +129,13 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$invalid);
         $this->check_current_mark(null);
         $this->check_current_output(
+                $this->get_contains_question_text_expectation($m),
+                $this->get_does_not_contain_feedback_expectation());
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], true),
                 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], true),
                 $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
-                $this->get_contains_question_text_expectation($m),
-                $this->get_does_not_contain_feedback_expectation());
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Finish the attempt.
         $this->quba->finish_all_questions();
@@ -140,11 +144,12 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$gradedpartial);
         $this->check_current_mark(2);
         $this->check_current_output(
+                $this->get_contains_partcorrect_expectation());
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
                 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
                 $this->get_contains_select_expectation('sub2', $choices, null, false),
-                $this->get_contains_select_expectation('sub3', $choices, null, false),
-                $this->get_contains_partcorrect_expectation());
+                $this->get_contains_select_expectation('sub3', $choices, null, false));
     }
 
     public function test_interactive_correct_no_submit() {
@@ -169,14 +174,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(3),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Save the right answer.
         $this->process_submission(array('sub0' => $orderforchoice[1],
@@ -190,13 +196,14 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$gradedright);
         $this->check_current_mark(4);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
-                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_correct_expectation(),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
+                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false));
     }
 
     public function test_interactive_partial_no_submit() {
@@ -221,14 +228,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(3),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Save the right answer.
         $this->process_submission(array('sub0' => $orderforchoice[1],
@@ -242,13 +250,14 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$gradedpartial);
         $this->check_current_mark(2);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
-                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[1], false),
-                $this->get_contains_select_expectation('sub3', $choices, null, false),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_partcorrect_expectation(),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
+                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[1], false),
+                $this->get_contains_select_expectation('sub3', $choices, null, false));
     }
 
     public function test_interactive_with_invalid() {
@@ -273,14 +282,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(3),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Try to submit an invalid answer.
         $this->process_submission(array('sub0' => '0',
@@ -291,14 +301,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$invalid);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_invalid_answer_expectation(),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Now submit the right answer.
         $this->process_submission(array('sub0' => $orderforchoice[1],
@@ -309,13 +320,14 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$gradedright);
         $this->check_current_mark(4);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
-                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_correct_expectation(),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
+                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false));
     }
 
     public function test_match_with_tricky_html_choices() {
@@ -346,6 +358,8 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         // Check the initial state.
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
+        // Do not use check_output_contains_selectoptions as there are multibyte characters ('1 ≤ x ≤ 2') that
+        // seem to be read as ascii ('1 â\89¤ x â\89¤ 2') in this test.
         $this->check_current_output(
                 $this->get_contains_select_expectation('sub0', $choices, null, true),
                 $this->get_contains_select_expectation('sub1', $choices, null, true),
@@ -392,14 +406,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(3),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Submit a completely wrong response.
         $this->process_submission(array('sub0' => $orderforchoice[3],
@@ -410,10 +425,6 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false),
-                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[3], false),
-                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[3], false),
                 $this->get_contains_hidden_expectation(
                         $this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
                 $this->get_contains_hidden_expectation(
@@ -424,6 +435,11 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
                         $this->quba->get_field_prefix($this->slot) . 'sub3', '0'),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_hint_expectation('This is the first hint.'));
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false),
+                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[3], false),
+                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[3], false));
 
         // Try again.
         $this->process_submission(array('sub0' => 0,
@@ -434,14 +450,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, null, true),
-                $this->get_contains_select_expectation('sub3', $choices, null, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(2),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, null, true),
+                $this->get_contains_select_expectation('sub3', $choices, null, true));
 
         // Submit a partially wrong response.
         $this->process_submission(array('sub0' => $orderforchoice[3],
@@ -452,10 +469,6 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false),
-                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
-                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false),
                 $this->get_contains_hidden_expectation(
                         $this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
                 $this->get_contains_hidden_expectation(
@@ -466,6 +479,11 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
                         $this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1]),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_hint_expectation('This is the second hint.'));
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false),
+                $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
+                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false));
 
         // Try again.
         $this->process_submission(array('sub0' => 0,
@@ -476,13 +494,15 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub0', $choices, null, true),
-                $this->get_contains_select_expectation('sub1', $choices, null, true),
-                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], true),
-                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_feedback_expectation(),
                 $this->get_tries_remaining_expectation(1),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub0', $choices, null, true),
+                $this->get_contains_select_expectation('sub1', $choices, null, true),
+                $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], true),
+                $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], true));
+
     }
 }