MDL-3782 qtype_multianswer: support 'multiple-answer' subquestions
[moodle.git] / question / type / multianswer / tests / walkthrough_test.php
index a7b7e84..e29f6a2 100644 (file)
@@ -465,4 +465,61 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
                 $this->get_contains_correct_expectation(),
                 new question_no_pattern_expectation('/class="control\b[^"]*\bpartiallycorrect"/'));
     }
+
+    public function test_deferred_feedback_multiple() {
+
+        // Create a multianswer question.
+        $q = test_question_maker::make_question('multianswer', 'multiple');
+        $this->start_attempt_at_question($q, 'deferredfeedback', 2);
+
+        // Check the initial state.
+        $this->check_current_state(question_state::$todo);
+        $this->check_current_mark(null);
+        $this->check_current_output(
+            $this->get_contains_marked_out_of_summary(),
+            $this->get_does_not_contain_feedback_expectation(),
+            $this->get_does_not_contain_validation_error_expectation());
+
+        // Save in incomplete answer.
+        $this->process_submission(array('sub1_choice0' => '1', 'sub1_choice1' => '1',
+                                        'sub1_choice2' => '', 'sub1_choice3' => '',
+                                        'sub1_choice4' => '', 'sub1_choice5' => '1',
+                                        ));
+
+        // Verify.
+        $this->check_current_state(question_state::$invalid);
+        $this->check_current_mark(null);
+        $this->check_current_output(
+            $this->get_contains_marked_out_of_summary(),
+            $this->get_does_not_contain_feedback_expectation(),
+            $this->get_contains_validation_error_expectation());
+
+        // Save a partially correct answer.
+        $this->process_submission(array('sub1_choice0' => '1', 'sub1_choice1' => '',
+                                        'sub1_choice2' => '', 'sub1_choice3' => '',
+                                        'sub1_choice4' => '1', 'sub1_choice5' => '1',
+                                        'sub2_choice0' => '', 'sub2_choice1' => '',
+                                        'sub2_choice2' => '', 'sub2_choice3' => '',
+                                        'sub2_choice4' => '1',
+                                  ));
+
+        // Verify.
+        $this->check_current_state(question_state::$complete);
+        $this->check_current_mark(null);
+        $this->check_current_output(
+            $this->get_contains_marked_out_of_summary(),
+            $this->get_does_not_contain_feedback_expectation(),
+            $this->get_does_not_contain_validation_error_expectation());
+
+        // Now submit all and finish.
+        $this->finish();
+
+        // Verify.
+        $this->check_current_state(question_state::$gradedpartial);
+        $this->check_current_mark(1.5);
+        $this->check_current_output(
+            $this->get_contains_mark_summary(1.5),
+            $this->get_contains_partcorrect_expectation(),
+            $this->get_does_not_contain_validation_error_expectation());
+    }
 }