Beispiel #1
0
    public function test_import_truefalse_wih_files()
    {
        $this->resetAfterTest();
        $this->setAdminUser();
        $xml = '<question type="truefalse">
    <name>
      <text>truefalse</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p><a href="@@PLUGINFILE@@/myfolder/moodle.txt">This text file</a> contains the word Moodle.</p>]]></text>
<file name="moodle.txt" path="/myfolder/" encoding="base64">TW9vZGxl</file>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[<p>For further information, see the documentation about Moodle.</p>]]></text>
</generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>1.0000000</penalty>
    <hidden>0</hidden>
    <answer fraction="100" format="moodle_auto_format">
      <text>true</text>
      <feedback format="html">
        <text></text>
      </feedback>
    </answer>
    <answer fraction="0" format="moodle_auto_format">
      <text>false</text>
      <feedback format="html">
        <text></text>
      </feedback>
    </answer>
  </question>';
        $xmldata = xmlize($xml);
        $importer = new qformat_xml();
        $q = $importer->import_truefalse($xmldata['question']);
        $draftitemid = $q->questiontextitemid;
        $files = file_get_drafarea_files($draftitemid, '/myfolder/');
        $this->assertEquals(1, count($files->list));
        $file = $files->list[0];
        $this->assertEquals('moodle.txt', $file->filename);
        $this->assertEquals('/myfolder/', $file->filepath);
        $this->assertEquals(6, $file->size);
    }
Beispiel #2
0
    public function test_import_truefalse_19() {
        $xml = '  <question type="truefalse">
    <name>
      <text>True false question</text>
    </name>
    <questiontext format="html">
      <text>The answer is true.</text>
    </questiontext>
    <generalfeedback>
      <text>General feedback: You should have chosen true.</text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>1</penalty>
    <hidden>0</hidden>
    <answer fraction="100">
      <text>true</text>
      <feedback>
        <text>Well done!</text>
      </feedback>
    </answer>
    <answer fraction="0">
      <text>false</text>
      <feedback>
        <text>Doh!</text>
      </feedback>
    </answer>
  </question>';
        $xmldata = xmlize($xml);

        $importer = new qformat_xml();
        $q = $importer->import_truefalse($xmldata['question']);

        $expectedq = new stdClass();
        $expectedq->qtype = 'truefalse';
        $expectedq->name = 'True false question';
        $expectedq->questiontext = 'The answer is true.';
        $expectedq->questiontextformat = FORMAT_HTML;
        $expectedq->generalfeedback = 'General feedback: You should have chosen true.';
        $expectedq->defaultmark = 1;
        $expectedq->length = 1;
        $expectedq->penalty = 1;

        $expectedq->feedbacktrue = array('text' => 'Well done!',
                'format' => FORMAT_HTML);
        $expectedq->feedbackfalse = array('text' => 'Doh!',
                'format' => FORMAT_HTML);
        $expectedq->correctanswer = true;

        $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;
}