MDL-64420 qtype: gapselect unit tests unsafe
[moodle.git] / question / type / multianswer / tests / walkthrough_test.php
index a7f21fd..d3f6e45 100644 (file)
@@ -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' => 'California', '1' => 'Arizona');
+        $choices = array('0' => 'California', '1' => 'Arizona');
 
         $this->start_attempt_at_question($q, 'interactive', 4);
 
@@ -218,16 +218,17 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                 $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());
+        $this->check_output_contains_selectoptions(
+                $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));
 
         // Submit a completely wrong response.
         $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '0',
@@ -237,10 +238,6 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub2_answer', $choices, 0, false),
-                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub4_answer', $choices, 0, false),
                 $this->get_does_not_contain_num_parts_correct(),
                 $this->get_contains_hidden_expectation(
                         $this->quba->get_field_prefix($this->slot) . 'sub1_answer', ''),
@@ -254,6 +251,11 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                 $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('sub1_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub2_answer', $choices, 0, false),
+                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub4_answer', $choices, 0, false));
 
         // Check that, if we review in this state, the try again button is disabled.
         $displayoptions = new question_display_options();
@@ -270,14 +272,15 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $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_feedback_expectation(),
                 $this->get_tries_remaining_expectation(2),
                 $this->get_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $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));
 
         // Submit a partially wrong response.
         $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1',
@@ -287,10 +290,6 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub2_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub4_answer', $choices, 1, false),
                 $this->get_contains_num_parts_correct(2),
                 $this->get_contains_hidden_expectation(
                         $this->quba->get_field_prefix($this->slot) . 'sub1_answer', ''),
@@ -302,6 +301,11 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                         $this->quba->get_field_prefix($this->slot) . 'sub4_answer', '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('sub1_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub2_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub4_answer', $choices, 1, false));
 
         // Try again.
         $this->process_submission(array('sub1_answer' => '',
@@ -312,14 +316,15 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, '', true),
-                $this->get_contains_select_expectation('sub2_answer', $choices, '1', true),
-                $this->get_contains_select_expectation('sub3_answer', $choices, '', true),
-                $this->get_contains_select_expectation('sub4_answer', $choices, '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('sub1_answer', $choices, '', true),
+                $this->get_contains_select_expectation('sub2_answer', $choices, '1', true),
+                $this->get_contains_select_expectation('sub3_answer', $choices, '', true),
+                $this->get_contains_select_expectation('sub4_answer', $choices, '1', true));
     }
 
     public function test_interactive_partial_response_does_not_reveal_answer() {
@@ -330,7 +335,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' => 'California', '1' => 'Arizona');
+        $choices = array('0' => 'California', '1' => 'Arizona');
 
         $this->start_attempt_at_question($q, 'interactive', 4);
 
@@ -341,16 +346,17 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                 $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());
+        $this->check_output_contains_selectoptions(
+                $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));
 
         // Submit an incomplete response response.
         $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1', '-submit' => 1));
@@ -359,16 +365,17 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $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->check_output_contains_selectoptions(
+                $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->render();
         $a = array('mark' => '0.00', 'max' => '1.00');
         $this->assertNotRegExp('~' . preg_quote(get_string('markoutofmax', 'question', $a), '~') . '~',
@@ -386,7 +393,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' => 'California', '1' => 'Arizona');
+        $choices = array('0' => 'California', '1' => 'Arizona');
 
         $this->start_attempt_at_question($q, 'interactive', 12);
 
@@ -397,15 +404,16 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                 $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_no_hint_visible_expectation());
+        $this->check_output_contains_selectoptions(
+                $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));
 
         // Submit an answer with two right, and two wrong.
         $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1',
@@ -415,15 +423,16 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub2_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
-                $this->get_contains_select_expectation('sub4_answer', $choices, 1, false),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_contains_try_again_button_expectation(true),
                 $this->get_does_not_contain_correctness_expectation(),
                 new question_pattern_expectation('/Tries remaining: 2/'),
                 $this->get_contains_hint_expectation('This is the first hint.'));
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub1_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub2_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub3_answer', $choices, 1, false),
+                $this->get_contains_select_expectation('sub4_answer', $choices, 1, false));
 
         // Check that extract responses will return the reset data.
         $prefix = $this->quba->get_field_prefix($this->slot);
@@ -439,14 +448,15 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$todo);
         $this->check_current_mark(null);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, '', true),
-                $this->get_contains_select_expectation('sub2_answer', $choices, '1', true),
-                $this->get_contains_select_expectation('sub3_answer', $choices, '', true),
-                $this->get_contains_select_expectation('sub4_answer', $choices, '1', 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('sub1_answer', $choices, '', true),
+                $this->get_contains_select_expectation('sub2_answer', $choices, '1', true),
+                $this->get_contains_select_expectation('sub3_answer', $choices, '', true),
+                $this->get_contains_select_expectation('sub4_answer', $choices, '1', true));
 
         // Submit the right answer.
         $this->process_submission(array('sub1_answer' => '0', 'sub2_answer' => '1',
@@ -456,14 +466,15 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
         $this->check_current_state(question_state::$gradedright);
         $this->check_current_mark(10);
         $this->check_current_output(
-                $this->get_contains_select_expectation('sub1_answer', $choices, '0', false),
-                $this->get_contains_select_expectation('sub2_answer', $choices, '1', false),
-                $this->get_contains_select_expectation('sub3_answer', $choices, '0', false),
-                $this->get_contains_select_expectation('sub4_answer', $choices, '1', false),
                 $this->get_does_not_contain_submit_button_expectation(),
                 $this->get_does_not_contain_try_again_button_expectation(),
                 $this->get_contains_correct_expectation(),
                 new question_no_pattern_expectation('/class="control\b[^"]*\bpartiallycorrect"/'));
+        $this->check_output_contains_selectoptions(
+                $this->get_contains_select_expectation('sub1_answer', $choices, '0', false),
+                $this->get_contains_select_expectation('sub2_answer', $choices, '1', false),
+                $this->get_contains_select_expectation('sub3_answer', $choices, '0', false),
+                $this->get_contains_select_expectation('sub4_answer', $choices, '1', false));
     }
 
     public function test_deferred_feedback_multiple() {