MDL-64420 qtype: gapselect unit tests unsafe
[moodle.git] / question / type / gapselect / tests / walkthrough_test.php
index 085b0b1..5e21fef 100644 (file)
@@ -52,16 +52,19 @@ class qtype_gapselect_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('p1',
-                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), null, true),
-                $this->get_contains_select_expectation('p2',
-                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), null, true),
-                $this->get_contains_select_expectation('p3',
-                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 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());
+        // Note it is possible to check the first select option as below, but it is not required.
+        // Also note the ' ' in the p2 example below is a nbsp (used when names are short).
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('p1',
+                        ['' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'], null, true),
+                $this->get_contains_select_expectation('p2',
+                        ['' => ' ', '1' => 'fox', '2' => 'dog'], null, true),
+                $this->get_contains_select_expectation('p3',
+                        ['1' => 'lazy', '2' => 'assiduous'], null, true));
 
         // Save the wrong answer.
         $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));
@@ -70,17 +73,18 @@ class qtype_gapselect_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('p1',
-                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true),
-                $this->get_contains_select_expectation('p2',
-                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true),
-                $this->get_contains_select_expectation('p3',
-                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_correctness_expectation(),
                 $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('p1',
+                        ['1' => 'quick', '2' => 'slow'], 2, true),
+                $this->get_contains_select_expectation('p2',
+                        ['1' => 'fox', '2' => 'dog'], 2, true),
+                $this->get_contains_select_expectation('p3',
+                        ['1' => 'lazy', '2' => 'assiduous'], 2, true));
 
         // Submit the wrong answer.
         $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
@@ -89,16 +93,17 @@ class qtype_gapselect_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('p1',
-                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, false),
-                $this->get_contains_select_expectation('p2',
-                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, false),
-                $this->get_contains_select_expectation('p3',
-                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, false),
-                        $this->get_does_not_contain_submit_button_expectation(),
+                $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_try_again_button_expectation(true),
                 $this->get_does_not_contain_correctness_expectation(),
                 $this->get_contains_hint_expectation('This is the first hint'));
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('p1',
+                        ['1' => 'quick', '2' => 'slow'], 2, false),
+                $this->get_contains_select_expectation('p2',
+                        ['1' => 'fox', '2' => 'dog'], 2, false),
+                $this->get_contains_select_expectation('p3',
+                        ['1' => 'lazy', '2' => 'assiduous'], 2, false));
 
         // Do try again.
         $this->process_submission(array('-tryagain' => 1));
@@ -107,17 +112,18 @@ class qtype_gapselect_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('p1',
-                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true),
-                $this->get_contains_select_expectation('p2',
-                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true),
-                $this->get_contains_select_expectation('p3',
-                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true),
                 $this->get_contains_submit_button_expectation(true),
                 $this->get_does_not_contain_correctness_expectation(),
                 $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('p1',
+                        ['1' => 'quick', '2' => 'slow'], 2, true),
+                $this->get_contains_select_expectation('p2',
+                        ['1' => 'fox', '2' => 'dog'], 2, true),
+                $this->get_contains_select_expectation('p3',
+                        ['1' => 'lazy', '2' => 'assiduous'], 2, true));
 
         // Submit the right answer.
         $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
@@ -126,15 +132,16 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
         $this->check_current_state(question_state::$gradedright);
         $this->check_current_mark(2);
         $this->check_current_output(
-                $this->get_contains_select_expectation('p1',
-                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 1, false),
-                $this->get_contains_select_expectation('p2',
-                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 1, false),
-                $this->get_contains_select_expectation('p3',
-                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 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('p1',
+                        ['1' => 'quick', '2' => 'slow'], 1, false),
+                $this->get_contains_select_expectation('p2',
+                        ['1' => 'fox', '2' => 'dog'], 1, false),
+                $this->get_contains_select_expectation('p3',
+                        ['1' => 'lazy', '2' => 'assiduous'], 1, false));
 
         // Check regrading does not mess anything up.
         $this->quba->regrade_all_questions();
@@ -160,11 +167,11 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
         // Check the initial state.
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
-        $this->check_current_output(
+        $this->check_output_contains_selectoptions(
                 $this->get_contains_select_expectation('p1',
-                        array('' => get_string('choosedots'), '1' => 'cat', '2' => 'dog'), null, true),
+                        ['1' => 'cat', '2' => 'dog'], null, true),
                 $this->get_contains_select_expectation('p2',
-                        array('' => get_string('choosedots'), '1' => 'mat', '2' => 'bat'), null, true));
+                        ['1' => 'mat', '2' => 'bat'], null, true));
     }
 
     public function test_choices_containing_dollars() {