MDL-47990 qtype_multichoice: fix test response import/export
authorTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 30 Oct 2014 18:19:45 +0000 (18:19 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 30 Oct 2014 18:19:45 +0000 (18:19 +0000)
question/type/multichoice/question.php
question/type/multichoice/tests/question_single_test.php

index c73969c..0542f5c 100644 (file)
@@ -212,7 +212,8 @@ class qtype_multichoice_single_question extends qtype_multichoice_base {
         if (!isset($postdata['answer'])) {
             return array();
         } else {
-            return array('answer' => $this->answers[$this->order[$postdata['answer']]]->answer);
+            $answer = $this->answers[$this->order[$postdata['answer']]];
+            return array('answer' => clean_param($answer->answer, PARAM_NOTAGS));
         }
     }
 
index ca09489..7b6b6b1 100644 (file)
@@ -165,4 +165,21 @@ class qtype_multichoice_single_question_test extends advanced_testcase {
         $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p><p></p>'));
         $this->assertEquals('Frog<br />†', $mc->make_html_inline('<p>Frog</p><p>†</p>'));
     }
+
+    public function test_simulated_post_data() {
+        $mc = test_question_maker::make_a_multichoice_single_question();
+        $mc->shuffleanswers = false;
+        $mc->answers[13]->answer = '<p>A</p>';
+        $mc->answers[14]->answer = '<p>B</p>';
+        $mc->answers[15]->answer = '<p>C</p>';
+        $mc->start_attempt(new question_attempt_step(), 1);
+
+        $originalresponse = array('answer' => 1);
+
+        $simulated = $mc->get_student_response_values_for_simulation($originalresponse);
+        $this->assertEquals(array('answer' => 'B'), $simulated);
+
+        $reconstucted = $mc->prepare_simulated_post_data($simulated);
+        $this->assertEquals($originalresponse, $reconstucted);
+    }
 }