public function test_export_multianswer() { $qdata = test_question_maker::get_question_data('multianswer', 'twosubq'); $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 0 --> <question type="cloze"> <name> <text>Simple multianswer</text> </name> <questiontext format="html"> <text><![CDATA[Complete this opening line of verse: "The {1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer} and the {1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!} went to sea".]]></text> </questiontext> <generalfeedback format="html"> <text><![CDATA[General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: "The owl and the pussycat went to sea]]></text> </generalfeedback> <penalty>0.3333333</penalty> <hidden>0</hidden> <hint format="html"> <text>Hint 1</text> </hint> <hint format="html"> <text>Hint 2</text> </hint> </question> '; $this->assert_same_xml($expectedxml, $xml); }
public function test_export_truefalse() { $qdata = new stdClass(); $qdata->id = 12; $qdata->contextid = 0; $qdata->qtype = 'truefalse'; $qdata->name = 'True false question'; $qdata->questiontext = 'The answer is true.'; $qdata->questiontextformat = FORMAT_HTML; $qdata->generalfeedback = 'General feedback: You should have chosen true.'; $qdata->generalfeedbackformat = FORMAT_HTML; $qdata->defaultmark = 1; $qdata->length = 1; $qdata->penalty = 1; $qdata->hidden = 0; $qdata->options->answers = array( 1 => new question_answer(1, 'True', 1, 'Well done!', FORMAT_HTML), 2 => new question_answer(2, 'False', 0, 'Doh!', FORMAT_HTML), ); $qdata->options->trueanswer = 1; $qdata->options->falseanswer = 2; $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 12 --> <question type="truefalse"> <name> <text>True false question</text> </name> <questiontext format="html"> <text>The answer is true.</text> </questiontext> <generalfeedback format="html"> <text>General feedback: You should have chosen true.</text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>1</penalty> <hidden>0</hidden> <answer fraction="100" format="plain_text"> <text>true</text> <feedback format="html"> <text>Well done!</text> </feedback> </answer> <answer fraction="0" format="plain_text"> <text>false</text> <feedback format="html"> <text>Doh!</text> </feedback> </answer> </question> '; $this->assert_same_xml($expectedxml, $xml); }
public function test_export_multianswer_withdollars() { $qdata = test_question_maker::get_question_data('multianswer', 'dollarsigns'); $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 0 --> <question type="cloze"> <name> <text>Multianswer with $s</text> </name> <questiontext format="html"> <text>Which is the right order? {1:MULTICHOICE:=y,y,$3~$3,y,y}</text> </questiontext> <generalfeedback format="html"> <text></text> </generalfeedback> <penalty>0.3333333</penalty> <hidden>0</hidden> </question> '; $this->assert_same_xml($expectedxml, $xml); }
public function test_xml_export() { $qdata = new stdClass(); $qdata->id = 123; $qdata->contextid = 0; $qdata->qtype = 'ddwtos'; $qdata->name = 'A drag-and-drop question'; $qdata->questiontext = 'Put these in order: [[1]], [[2]], [[3]].'; $qdata->questiontextformat = FORMAT_MOODLE; $qdata->generalfeedback = 'The answer is Alpha, Beta, Gamma.'; $qdata->generalfeedbackformat = FORMAT_MOODLE; $qdata->defaultmark = 3; $qdata->length = 1; $qdata->penalty = 0.3333333; $qdata->hidden = 0; $qdata->options = new stdClass(); $qdata->options->shuffleanswers = 1; $qdata->options->correctfeedback = '<p>Your answer is correct.</p>'; $qdata->options->correctfeedbackformat = FORMAT_MOODLE; $qdata->options->partiallycorrectfeedback = '<p>Your answer is partially correct.</p>'; $qdata->options->partiallycorrectfeedbackformat = FORMAT_MOODLE; $qdata->options->shownumcorrect = 1; $qdata->options->incorrectfeedback = '<p>Your answer is incorrect.</p>'; $qdata->options->incorrectfeedbackformat = FORMAT_MOODLE; $qdata->options->answers = array(13 => new question_answer(13, 'Alpha', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}', FORMAT_MOODLE), 14 => new question_answer(14, 'Beta', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}', FORMAT_MOODLE), 15 => new question_answer(15, 'Gamma', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:1;}', FORMAT_MOODLE)); $qdata->hints = array(1 => new question_hint_with_parts(1, 'Try again.', FORMAT_MOODLE, true, false), 2 => new question_hint_with_parts(2, 'These are the first three letters of the Greek alphabet.', FORMAT_MOODLE, true, true)); $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 123 --> <question type="ddwtos"> <name> <text>A drag-and-drop question</text> </name> <questiontext format="moodle_auto_format"> <text>Put these in order: [[1]], [[2]], [[3]].</text> </questiontext> <generalfeedback format="moodle_auto_format"> <text>The answer is Alpha, Beta, Gamma.</text> </generalfeedback> <defaultgrade>3</defaultgrade> <penalty>0.3333333</penalty> <hidden>0</hidden> <shuffleanswers>1</shuffleanswers> <correctfeedback format="moodle_auto_format"> <text><![CDATA[<p>Your answer is correct.</p>]]></text> </correctfeedback> <partiallycorrectfeedback format="moodle_auto_format"> <text><![CDATA[<p>Your answer is partially correct.</p>]]></text> </partiallycorrectfeedback> <incorrectfeedback format="moodle_auto_format"> <text><![CDATA[<p>Your answer is incorrect.</p>]]></text> </incorrectfeedback> <shownumcorrect/> <dragbox> <text>Alpha</text> <group>1</group> </dragbox> <dragbox> <text>Beta</text> <group>1</group> </dragbox> <dragbox> <text>Gamma</text> <group>1</group> <infinite/> </dragbox> <hint format="moodle_auto_format"> <text>Try again.</text> <shownumcorrect/> </hint> <hint format="moodle_auto_format"> <text>These are the first three letters of the Greek alphabet.</text> <shownumcorrect/> <clearwrong/> </hint> </question> '; $this->assert_same_xml($expectedxml, $xml); }
public function test_xml_export() { $qdata = test_question_maker::get_question_data('stack', 'test0'); $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 0 --> <question type="stack"> <name> <text>test-0</text> </name> <questiontext format="html"> <text>What is $1+1$? [[input:ans1]] [[validation:ans1]]</text> </questiontext> <generalfeedback format="html"> <text></text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.3333333</penalty> <hidden>0</hidden> <questionvariables> <text></text> </questionvariables> <specificfeedback format="html"> <text>[[feedback:firsttree]]</text> </specificfeedback> <questionnote> <text></text> </questionnote> <questionsimplify>1</questionsimplify> <assumepositive>0</assumepositive> <prtcorrect format="html"> <text><![CDATA[<p>Correct answer, well done.</p>]]></text> </prtcorrect> <prtpartiallycorrect format="html"> <text><![CDATA[<p>Your answer is partially correct.</p>]]></text> </prtpartiallycorrect> <prtincorrect format="html"> <text><![CDATA[<p>Incorrect answer.</p>]]></text> </prtincorrect> <multiplicationsign>dot</multiplicationsign> <sqrtsign>1</sqrtsign> <complexno>i</complexno> <inversetrig>cos-1</inversetrig> <matrixparens>[</matrixparens> <variantsselectionseed></variantsselectionseed> <input> <name>ans1</name> <type>algebraic</type> <tans>2</tans> <boxsize>5</boxsize> <strictsyntax>1</strictsyntax> <insertstars>0</insertstars> <syntaxhint></syntaxhint> <forbidwords></forbidwords> <allowwords></allowwords> <forbidfloat>1</forbidfloat> <requirelowestterms>0</requirelowestterms> <checkanswertype>0</checkanswertype> <mustverify>1</mustverify> <showvalidation>1</showvalidation> <options></options> </input> <prt> <name>firsttree</name> <value>1</value> <autosimplify>1</autosimplify> <feedbackvariables> <text></text> </feedbackvariables> <node> <name>0</name> <answertest>EqualComAss</answertest> <sans>ans1</sans> <tans>2</tans> <testoptions></testoptions> <quiet>0</quiet> <truescoremode>=</truescoremode> <truescore>1</truescore> <truepenalty>0</truepenalty> <truenextnode>-1</truenextnode> <trueanswernote>firsttree-1-T</trueanswernote> <truefeedback format="html"> <text></text> </truefeedback> <falsescoremode>=</falsescoremode> <falsescore>0</falsescore> <falsepenalty>0</falsepenalty> <falsenextnode>-1</falsenextnode> <falseanswernote>firsttree-1-F</falseanswernote> <falsefeedback format="html"> <text></text> </falsefeedback> </node> </prt> <deployedseed>12345</deployedseed> <qtest> <testcase>1</testcase> <testinput> <name>ans1</name> <value>2</value> </testinput> <expected> <name>firsttree</name> <expectedscore>1</expectedscore> <expectedpenalty>0</expectedpenalty> <expectedanswernote>firsttree-1-T</expectedanswernote> </expected> </qtest> </question> '; $this->assert_same_xml($expectedxml, $xml); }
public function test_export() { $q = $this->make_parent_and_child(); $q->qtype = $q->qtype->name(); // TODO: Why does qformat_xml expect this field to be a string?! $exporter = new qformat_xml(); $xml = $exporter->writequestion($q); $bits = preg_split("/<!-- question: [0-9]* -->/", $xml); $xml_no_line1 = $bits[1]; $expectedxml = ' <question type="coderunner"> <name> <text>Program to test prototype</text> </name> <questiontext format="html"> <text>Answer should (somehow) produce the expected answer below</text> </questiontext> <generalfeedback format="html"> <text>No feedback available for coderunner questions.</text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.3333333</penalty> <hidden>0</hidden> <coderunnertype>sqr_user_prototype</coderunnertype> <prototypetype>0</prototypetype> <allornothing>1</allornothing> <penaltyregime></penaltyregime> <showsource></showsource> <answerboxlines></answerboxlines> <answerboxcolumns></answerboxcolumns> <useace>1</useace> <resultcolumns></resultcolumns> <answer></answer> <combinatortemplate></combinatortemplate> <testsplitterre></testsplitterre> <enablecombinator></enablecombinator> <pertesttemplate></pertesttemplate> <language></language> <acelang></acelang> <sandbox></sandbox> <grader></grader> <cputimelimitsecs></cputimelimitsecs> <memlimitmb></memlimitmb> <sandboxparams></sandboxparams> <templateparams></templateparams> <testcases> <testcase useasexample="0" hiderestiffail="0" mark="1.0000000" > <testcode> <text></text> </testcode> <stdin> <text></text> </stdin> <expected> <text>This is data Line 2</text> </expected> <extra> <text></text> </extra> <display> <text>SHOW</text> </display> </testcase> </testcases> </question> '; $this->assert_same_xml($expectedxml, $xml_no_line1); }