public function test_import_shortanswer_19() { $xml = ' <question type="shortanswer"> <name> <text>Short answer question</text> </name> <questiontext format="html"> <text>Fill in the gap in this sequence: Alpha, ________, Gamma.</text> </questiontext> <generalfeedback> <text>The answer is Beta.</text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.3333333</penalty> <hidden>0</hidden> <usecase>0</usecase> <answer fraction="100" format="plain_text"> <text>Beta</text> <feedback> <text>Well done!</text> </feedback> </answer> <answer fraction="0" format="plain_text"> <text>*</text> <feedback> <text>Doh!</text> </feedback> </answer> <hint> <text>Hint 1</text> </hint> <hint> <text>Hint 2</text> </hint> </question>'; $xmldata = xmlize($xml); $importer = new qformat_xml(); $q = $importer->import_shortanswer($xmldata['question']); $expectedq = new stdClass(); $expectedq->qtype = 'shortanswer'; $expectedq->name = 'Short answer question'; $expectedq->questiontext = 'Fill in the gap in this sequence: Alpha, ________, Gamma.'; $expectedq->questiontextformat = FORMAT_HTML; $expectedq->generalfeedback = 'The answer is Beta.'; $expectedq->usecase = false; $expectedq->defaultmark = 1; $expectedq->length = 1; $expectedq->penalty = 0.3333333; $expectedq->answer = array('Beta', '*'); $expectedq->fraction = array(1, 0); $expectedq->feedback = array( array('text' => 'Well done!', 'format' => FORMAT_HTML), array('text' => 'Doh!', 'format' => FORMAT_HTML)); $this->assert(new question_check_specified_fields_expectation($expectedq), $q); }
function wrsqz_import_from_xml($questionType, $dbType, &$data, &$question, &$format, &$extra) { if (isset($data['@']['type']) && $data['@']['type'] == $questionType . 'wiris') { $qfxml = new qformat_xml(); if ($questionType == 'essay') { $question = $qfxml->import_essay($data); }else if ($questionType == 'match') { $question = $qfxml->import_matching($data); }else if ($questionType == 'multichoice') { $question = $qfxml->import_multichoice($data); }else if ($questionType == 'truefalse') { $question = $qfxml->import_truefalse($data); }else if ($questionType == 'shortanswer') { $question = $qfxml->import_shortanswer($data); }else if ($questionType == 'multianswer') { $questiontext = $data['#']['wirisquestiontext'][0]['#']['text']; $container = new stdClass; $container->questiontext = $qfxml->import_text($questiontext); $question = wrsqz_qtype_multianswer_extract_question($container); $question->course = $qfxml->course; $question->generalfeedback = $qfxml->getpath($data, array('#','generalfeedback',0,'#','text',0,'#'), '', true ); $question->name = $qfxml->import_text( $data['#']['name'][0]['#']['text'] ); } unset($qfxml); $question->qtype = $questionType . 'wiris'; $program = wrsqz_mathmlDecode($format->getpath($data, array('#', 'wirisquestion', 0, '#'), 0)); $imported = wrsqz_importCASSession($program); if($imported===false) return false; $question->hiddenCASValue = $imported[0]; $translation = $imported[1]; if ($questionType == 'shortanswer') { mb_parse_str($format->getpath($data, array('#', 'wiriseditor', 0, '#'), 0), $eqoptionArray); $question->wirisEditor = (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') ? 'editor=true' : ''; $question->multipleAnswers = (isset($eqoptionArray['multipleAnswers']) && $eqoptionArray['multipleAnswers'] == 'true') ? 'multipleAnswers=true' : ''; $question->wirisCASForComputations = (isset($eqoptionArray['wirisCASForComputations']) && $eqoptionArray['wirisCASForComputations'] == 'true') ? 'wirisCASForComputations=true' : ''; if(isset($eqoptionArray['testFunctionName'])){ foreach ($eqoptionArray['testFunctionName'] as $index => $functionName){ if(!empty($functionName)){ $question->testFunctionName[$index]=$functionName; } } } }else if ($questionType == 'multichoice') { $question->gradeOverride = explode(';', $format->getpath($data, array('#', 'wirisoverrideanswer', 0, '#'), 0)); }else if ($questionType == 'truefalse') { $question->wirisAnswer = $format->getpath($data, array('#', 'wirisoverrideanswer', 0, '#'), 0); }else if ($questionType == 'multianswer'){ //mb_parse_str($format->getpath($data, array('#', 'wiriseditor', 0, '#'), 0), $eqoptionArray); //$question->wirisEditor = (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') ? 'editor=true' : ''; } $options = $format->getpath($data, array('#', 'wirisoptions',0,'#'), array()); $question->wirisCASForComputations = $format->getpath($options, array('wirisCASForComputations',0,'#'),0); //TODO: translate cas if needed. $question->hiddenInitialCASValue = wrsqz_mathmlDecode($format->getpath($options, array('hiddenInitialCASValue',0,'#'),0)); if(!empty($translation)){ wrsqz_replaceVarReferencesInFlatQuestion($questionType, $question, $translation); } return $question; } return false; }