diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 9d4faafd91f..1385d2fd164 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -1074,53 +1074,52 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype return $status; } - /** - * Runs all the code required to set up and save an essay question for testing purposes. - * Alternate DB table prefix may be used to facilitate data deletion. - */ - function generate_test($name, $courseid = null) { - list($form, $question) = parent::generate_test($name, $courseid); - $form->feedback = 1; - $form->multiplier = array(1, 1); - $form->shuffleanswers = 1; - $form->noanswers = 1; +/** + * Runs all the code required to set up and save an essay question for testing purposes. + * Alternate DB table prefix may be used to facilitate data deletion. + */ + function generate_test($name, $courseid = null) { + list($form, $question) = parent::generate_test($name, $courseid); + $form->feedback = 1; + $form->multiplier = array(1, 1); + $form->shuffleanswers = 1; + $form->noanswers = 1; + $form->qtype ='calculated'; + $question->qtype ='calculated'; + $form->answers = array('{a} + {b}'); + $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->answers = array('{a} + {b}'); - $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}?"; + if ($courseid) { + $course = get_record('course', 'id', $courseid); + } - if ($courseid) { - $course = get_record('course', 'id', $courseid); - } + $new_question = $this->save_question($question, $form, $course); - $new_question = $this->save_question($question, $form, $course); + $dataset_form = new stdClass(); + $dataset_form->nextpageparam["forceregeneration"]= 1; + $dataset_form->calcmin = array(1 => 1.0, 2 => 1.0); + $dataset_form->calcmax = array(1 => 10.0, 2 => 10.0); + $dataset_form->calclength = array(1 => 1, 2 => 1); + $dataset_form->number = array(1 => 5.4 , 2 => 4.9); + $dataset_form->itemid = array(1 => '' , 2 => ''); + $dataset_form->calcdistribution = array(1 => 'uniform', 2 => 'uniform'); + $dataset_form->definition = array(1 => "1-0-a", + 2 => "1-0-b"); + $dataset_form->nextpageparam = array('forceregeneration' => false); + $dataset_form->addbutton = 1; + $dataset_form->selectadd = 1; + $dataset_form->courseid = $courseid; + $dataset_form->cmid = 0; + $dataset_form->id = $new_question->id; + $this->save_dataset_items($new_question, $dataset_form); - $dataset_form = new stdClass(); - $dataset_form->number = array(1 => 2.4, 2 => 7.2, 3 => 6.7, 4 => 6.3); - $dataset_form->calcmin = array(1 => 1.0, 2 => 1.0); - $dataset_form->calcmax = array(1 => 10.0, 2 => 10.0); - $dataset_form->calclength = array(1 => 1, 2 => 1); - $dataset_form->calcdistribution = array(1 => 'uniform', 2 => 'uniform'); - $dataset_form->definition = array(1 => "1-$new_question->category-b", - 2 => "1-$new_question->category-a", - 3 => "1-$new_question->category-b", - 4 => "1-$new_question->category-a"); - $dataset_form->itemid = array(1 => 2, 2 => 1, 3 => 0, 4 => 0); - $dataset_form->nextpageparam = array('forceregeneration' => false); - $dataset_form->addbutton = 1; - $dataset_form->selectadd = 1; - $dataset_form->selectdelete = 1; - $dataset_form->courseid = $courseid; - $dataset_form->cmid = 0; - - $this->save_dataset_items($new_question, $dataset_form); - - return $new_question; - } + return $new_question; + } } //// END OF CLASS ////