From 12820b3c4b213ca2dc30405db480bc39865fa01f Mon Sep 17 00:00:00 2001
From: Tomasz Muras <tm@enovation.ie>
Date: Fri, 24 Dec 2010 11:06:44 +0000
Subject: [PATCH] Fixes for generate_test method.

---
 question/type/calculated/questiontype.php       |    6 ++++--
 question/type/calculatedmulti/questiontype.php  |    7 ++++---
 question/type/calculatedsimple/questiontype.php |    4 ++--
 question/type/essay/questiontype.php            |    5 ++---
 question/type/match/questiontype.php            |    5 ++++-
 question/type/multianswer/questiontype.php      |   10 +++++-----
 question/type/multichoice/questiontype.php      |   19 ++++++++++++-------
 question/type/numerical/questiontype.php        |    9 ++++++---
 question/type/questiontype.php                  |    8 ++++++--
 question/type/shortanswer/questiontype.php      |   14 +++++++++++---
 question/type/truefalse/questiontype.php        |    6 +++---
 11 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php
index eed7933..0a2ef4b 100644
--- a/question/type/calculated/questiontype.php
+++ b/question/type/calculated/questiontype.php
@@ -2069,19 +2069,21 @@ class question_calculated_qtype extends default_questiontype {
     function generate_test($name, $courseid = null) {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
-        $form->feedback = 1;
+        $form->feedback = array(array('text' => 'feedback', 'format' => 0));
+        $form->instructions = array('text' => 'Instructions...', 'format' => 0);
         $form->multiplier = array(1, 1);
         $form->shuffleanswers = 1;
         $form->noanswers = 1;
         $form->qtype ='calculated';
         $question->qtype ='calculated';
         $form->answers = array('{a} + {b}');
+        $form->answernumbering = 'abc';
         $form->fraction = array(1);
         $form->tolerance = array(0.01);
         $form->tolerancetype = array(1);
         $form->correctanswerlength = array(2);
         $form->correctanswerformat = array(1);
-        $form->questiontext = "What is {a} + {b}?";
+        $form->questiontext = array('text' => "What is {a} + {b}?", 'format' => 0);
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id'=> $courseid));
diff --git a/question/type/calculatedmulti/questiontype.php b/question/type/calculatedmulti/questiontype.php
index ff66469..593897c 100644
--- a/question/type/calculatedmulti/questiontype.php
+++ b/question/type/calculatedmulti/questiontype.php
@@ -508,19 +508,20 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
     function generate_test($name, $courseid = null) {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
-        $form->feedback = 1;
+        $form->feedback = array('text' => 'feedback', 'format' => 0);
         $form->multiplier = array(1, 1);
         $form->shuffleanswers = 1;
         $form->noanswers = 1;
         $form->qtype ='calculatedmulti';
         $question->qtype ='calculatedmulti';
-        $form->answers = array('{a} + {b}');
+        $form->answers = array(
+                array('text' => '{a} + {b}', 'format' => 0));
         $form->fraction = array(1);
         $form->tolerance = array(0.01);
         $form->tolerancetype = array(1);
         $form->correctanswerlength = array(2);
         $form->correctanswerformat = array(1);
-        $form->questiontext = "What is {a} + {b}?";
+        $form->questiontext = array('text' => "What is {a} + {b}?", 'format' => 0);
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id'=> $courseid));
diff --git a/question/type/calculatedsimple/questiontype.php b/question/type/calculatedsimple/questiontype.php
index f205a3b..b44c642 100644
--- a/question/type/calculatedsimple/questiontype.php
+++ b/question/type/calculatedsimple/questiontype.php
@@ -303,7 +303,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
     function generate_test($name, $courseid = null) {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
-        $form->feedback = 1;
+        $form->feedback = array('text' => "feedback", 'format' => 0);
         $form->multiplier = array(1, 1);
         $form->shuffleanswers = 1;
         $form->noanswers = 1;
@@ -315,7 +315,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
         $form->tolerancetype = array(1);
         $form->correctanswerlength = array(2);
         $form->correctanswerformat = array(1);
-        $form->questiontext = "What is {a} + {b}?";
+        $form->questiontext = array('text' => "What is {a} + {b}?", 'format' => 0);
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id'=> $courseid));
diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php
index 102b26f..f3ad8ad 100644
--- a/question/type/essay/questiontype.php
+++ b/question/type/essay/questiontype.php
@@ -134,9 +134,8 @@ class question_essay_qtype extends default_questiontype {
     function generate_test($name, $courseid = null) {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
-        $form->questiontext = "What is the purpose of life?";
-        $form->feedback = "feedback";
-        $form->generalfeedback = "General feedback";
+        $form->questiontext = array('text'=>"What is the purpose of life?", 'format'=>0);
+        $form->feedback = array('text'=>"Feedback.", 'format'=>0);
         $form->fraction = 0;
         $form->penalty = 0;
 
diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php
index 0284021..f8cf24c 100644
--- a/question/type/match/questiontype.php
+++ b/question/type/match/questiontype.php
@@ -486,7 +486,10 @@ class question_match_qtype extends default_questiontype {
         list($form, $question) = parent::generate_test($name, $courseid);
         $form->shuffleanswers = 1;
         $form->noanswers = 3;
-        $form->subquestions = array('cat', 'dog', 'cow');
+        $form->subquestions = array(
+                array('text'=>'cat', 'format'=>0),
+                array('text'=>'dog', 'format'=>0),
+                array('text'=>'cow', 'format'=>0));
         $form->subanswers = array('feline', 'canine', 'bovine');
 
         if ($courseid) {
diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php
index 1c713f2..e5dd2ba 100644
--- a/question/type/multianswer/questiontype.php
+++ b/question/type/multianswer/questiontype.php
@@ -675,16 +675,16 @@ class embedded_cloze_qtype extends default_questiontype {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
         $question->category = $form->category;
-        $form->questiontext = "This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.
+        $form->questiontext = array(
+                'text' => "This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.
 
 Note that addresses like www.moodle.org and smileys :-) all work as normal:
  a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}
  b) What grade would you give it? {3:NUMERICAL:=3:2}
 
-Good luck!
-";
-        $form->feedback = "feedback";
-        $form->generalfeedback = "General feedback";
+Good luck!",
+                'format' => 0);
+        $form->feedback = array('text' => "feedback", 'format' => 0);
         $form->fraction = 0;
         $form->penalty = 0.1;
         $form->versioning = 0;
diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php
index 02f8087..5fb9631 100644
--- a/question/type/multichoice/questiontype.php
+++ b/question/type/multichoice/questiontype.php
@@ -470,19 +470,24 @@ class question_multichoice_qtype extends default_questiontype {
         global $DB;
         list($form, $question) = parent::generate_test($name, $courseid);
         $question->category = $form->category;
-        $form->questiontext = "How old is the sun?";
-        $form->generalfeedback = "General feedback";
+        $form->questiontext = array('text' => "How old is the sun?", 'format' => 0);
         $form->penalty = 0.1;
         $form->single = 1;
         $form->shuffleanswers = 1;
         $form->answernumbering = 'abc';
         $form->noanswers = 3;
-        $form->answer = array('Ancient', '5 billion years old', '4.5 billion years old');
+        $form->answer = array(
+                array('text' => 'Ancient', 'format' => 0),
+                array('text' => '5 billion years old', 'format' => 0),
+                array('text' => '4.5 billion years old', 'format' => 0));
         $form->fraction = array(0.3, 0.9, 1);
-        $form->feedback = array('True, but lacking in accuracy', 'Close, but no cigar!', 'Yep, that is it!');
-        $form->correctfeedback = 'Excellent!';
-        $form->incorrectfeedback = 'Nope!';
-        $form->partiallycorrectfeedback = 'Not bad';
+        $form->feedback = array(
+                array('text' => 'True, but lacking in accuracy', 'format' => 0),
+                array('text' => 'Close, but no cigar!', 'format' => 0),
+                array('text' => 'Yep, that is it!', 'format' => 0));
+        $form->correctfeedback = array('text' => "Excellent!", 'format' => 0);
+        $form->incorrectfeedback = array('text' => "Nope!", 'format' => 0);
+        $form->partiallycorrectfeedback = array('text' => "Not bad.", 'format' => 0);
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id' => $courseid));
diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php
index 5d83737..cae9ceb 100644
--- a/question/type/numerical/questiontype.php
+++ b/question/type/numerical/questiontype.php
@@ -1309,8 +1309,8 @@ class question_numerical_qtype extends question_shortanswer_qtype {
         list($form, $question) = default_questiontype::generate_test($name, $courseid);
         $question->category = $form->category;
 
-        $form->questiontext = "What is 674 * 36?";
-        $form->generalfeedback = "Thank you";
+        $form->questiontext = array('text' => "What is 674 * 36?", 'format' => 0);
+        $form->instructions = array('text' => "Instructions...", 'format' => 0); 
         $form->penalty = 0.1;
         $form->defaultgrade = 1;
         $form->noanswers = 3;
@@ -1320,7 +1320,10 @@ class question_numerical_qtype extends question_shortanswer_qtype {
         $form->nounits = 2;
         $form->unit = array(0 => null, 1 => null);
         $form->multiplier = array(1, 0);
-        $form->feedback = array('Very good', 'Close, but not quite there', 'Well at least you tried....');
+        $form->feedback = array(
+                array('text' => 'Very good', 'format' => 0),
+                array('text' => 'Close, but not quite there', 'format' => 0),
+                array('text' => 'Well at least you tried....', 'format' => 0));
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id' => $courseid));
diff --git a/question/type/questiontype.php b/question/type/questiontype.php
index 5aaf4d3..ff0f1ef 100644
--- a/question/type/questiontype.php
+++ b/question/type/questiontype.php
@@ -1627,10 +1627,14 @@ class default_questiontype {
         $form = new stdClass();
         $form->name = $name;
         $form->questiontextformat = 1;
-        $form->questiontext = 'test question, generated by script';
+        $form->questiontext = array(
+                'text'=>'test question, generated by script',
+                'format'=>0);
         $form->defaultgrade = 1;
         $form->penalty = 0.1;
-        $form->generalfeedback = "Well done";
+        $form->generalfeedback = array(
+                'text'=>'Well done',
+                'format'=>0);
 
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
         $newcategory = question_make_default_categories(array($context));
diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php
index 1388f5e..25dadd2 100644
--- a/question/type/shortanswer/questiontype.php
+++ b/question/type/shortanswer/questiontype.php
@@ -355,15 +355,23 @@ class question_shortanswer_qtype extends default_questiontype {
         list($form, $question) = parent::generate_test($name, $courseid);
         $question->category = $form->category;
 
-        $form->questiontext = "What is the purpose of life, the universe, and everything";
-        $form->generalfeedback = "Congratulations, you may have solved my biggest problem!";
+
+        $form->questiontext = array(
+                'text' => "What is the purpose of life, the universe, and everything", 
+                'format' => 0);
+        $form->generalfeedback = array(
+                'text' => "Congratulations, you may have solved my biggest problem!",
+                'format' => 1);
         $form->penalty = 0.1;
         $form->usecase = false;
         $form->defaultgrade = 1;
         $form->noanswers = 3;
         $form->answer = array('42', 'who cares?', 'Be happy');
         $form->fraction = array(1, 0.6, 0.8);
-        $form->feedback = array('True, but what does that mean?', 'Well you do, dont you?', 'Yes, but thats not funny...');
+        $form->feedback = array(
+                array('text' => 'True, but what does that mean?', 'format' => 0), 
+                array('text' => 'Well you do, dont you?','format' => 0),
+                array('text' => 'Yes, but thats not funny...','format' => 0));
         $form->correctfeedback = 'Excellent!';
         $form->incorrectfeedback = 'Nope!';
         $form->partiallycorrectfeedback = 'Not bad';
diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php
index 1dc2cc1..7897053 100644
--- a/question/type/truefalse/questiontype.php
+++ b/question/type/truefalse/questiontype.php
@@ -295,12 +295,12 @@ class question_truefalse_qtype extends default_questiontype {
         list($form, $question) = parent::generate_test($name, $courseid);
         $question->category = $form->category;
 
-        $form->questiontext = "This question is really stupid";
+        $form->questiontext = array('text' => "This question is really stupid", 'format' => 0);
         $form->penalty = 1;
         $form->defaultgrade = 1;
         $form->correctanswer = 0;
-        $form->feedbacktrue = 'Can you justify such a hasty judgment?';
-        $form->feedbackfalse = 'Wisdom has spoken!';
+        $form->feedbacktrue = array('text' => 'Can you justify such a hasty judgment?', 'format' => 0);
+        $form->feedbackfalse = array('text' => 'Wisdom has spoken!', 'format' => 0);
 
         if ($courseid) {
             $course = $DB->get_record('course', array('id' => $courseid));
-- 
1.5.6.5

