MDL-62880 qtype_ddwtos: drop support for legacy import format
It was more than 8 years since we wrote in that format.
This commit is contained in:
@@ -71,32 +71,17 @@ class qtype_ddwtos extends qtype_gapselect_base {
|
||||
$question->shuffleanswers = $format->trans_single(
|
||||
$format->getpath($data, array('#', 'shuffleanswers', 0, '#'), 1));
|
||||
|
||||
if (!empty($data['#']['dragbox'])) {
|
||||
// Modern XML format.
|
||||
$dragboxes = $data['#']['dragbox'];
|
||||
$question->answer = array();
|
||||
$question->draggroup = array();
|
||||
$question->infinite = array();
|
||||
// Import the choices.
|
||||
$question->answer = array();
|
||||
$question->draggroup = array();
|
||||
$question->infinite = array();
|
||||
|
||||
foreach ($data['#']['dragbox'] as $dragboxxml) {
|
||||
$question->choices[] = array(
|
||||
'answer' => $format->getpath($dragboxxml, array('#', 'text', 0, '#'), '', true),
|
||||
'choicegroup' => $format->getpath($dragboxxml, array('#', 'group', 0, '#'), 1),
|
||||
'infinite' => array_key_exists('infinite', $dragboxxml['#']),
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Legacy format containing PHP serialisation.
|
||||
foreach ($data['#']['answer'] as $answerxml) {
|
||||
$ans = $format->import_answer($answerxml);
|
||||
$options = unserialize(stripslashes($ans->feedback['text']));
|
||||
$question->choices[] = array(
|
||||
'answer' => $ans->answer,
|
||||
'choicegroup' => $options->draggroup,
|
||||
'infinite' => $options->infinite,
|
||||
);
|
||||
}
|
||||
foreach ($data['#']['dragbox'] as $dragboxxml) {
|
||||
$question->choices[] = array(
|
||||
'answer' => $format->getpath($dragboxxml, array('#', 'text', 0, '#'), '', true),
|
||||
'choicegroup' => $format->getpath($dragboxxml, array('#', 'group', 0, '#'), 1),
|
||||
'infinite' => array_key_exists('infinite', $dragboxxml['#']),
|
||||
);
|
||||
}
|
||||
|
||||
$format->import_combined_feedback($question, $data, true);
|
||||
|
||||
@@ -243,199 +243,6 @@ class qtype_ddwtos_test extends question_testcase {
|
||||
$this->assertEquals($expectedq->hint, $q->hint);
|
||||
}
|
||||
|
||||
public function test_xml_import_legacy() {
|
||||
$xml = ' <question type="ddwtos">
|
||||
<name>
|
||||
<text>QDandD1 Base definition</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text><p>Drag and drop the words from the list below to fill the blank spaces ' .
|
||||
'and correctly complete the sentence.</p> <p>At 25°C all aqueous basic ' .
|
||||
'solutions have [[1]] ion concentrations less than [[8]]<br />mol ' .
|
||||
'litre<sup>-1</sup> and pH values [[9]] than [[6]].</p> ' .
|
||||
'<!--DONOTCLEAN--></text>
|
||||
</questiontext>
|
||||
<image></image>
|
||||
<generalfeedback>
|
||||
<text><p>At 25 &#xB0;C all aqueous basic solutions have hydrogen ion ' .
|
||||
'concentrations less than 10<sup>&#x2212;7</sup> mol ' .
|
||||
'litre<sup>&#x2212;1</sup> and pH values greater than 7.</p> ' .
|
||||
'<p>See Section 9 of S103 <em class="italic">Discovering ' .
|
||||
'Science</em> Block 8.</p></text>
|
||||
</generalfeedback>
|
||||
<defaultgrade>1</defaultgrade>
|
||||
<penalty>0.33</penalty>
|
||||
<hidden>0</hidden>
|
||||
<shuffleanswers>0</shuffleanswers>
|
||||
<shuffleanswers>false</shuffleanswers>
|
||||
<answer>
|
||||
<correctanswer>1</correctanswer>
|
||||
<text>hydrogen</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>positive</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>hydroxide</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>negative</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>10<sup>7</sup></text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>1</correctanswer>
|
||||
<text>7</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>1</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>1</correctanswer>
|
||||
<text>10<sup>-7</sup></text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>1</correctanswer>
|
||||
<text>greater</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer>
|
||||
<correctanswer>0</correctanswer>
|
||||
<text>less</text>
|
||||
<feedback>
|
||||
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}</text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<correctfeedback>
|
||||
<text>Your answer is correct.</text>
|
||||
</correctfeedback>
|
||||
<correctresponsesfeedback>1</correctresponsesfeedback>
|
||||
<partiallycorrectfeedback>
|
||||
<text>Your answer is partially correct.</text>
|
||||
</partiallycorrectfeedback>
|
||||
<incorrectfeedback>
|
||||
<text>Your answer is incorrect.</text>
|
||||
</incorrectfeedback>
|
||||
<unlimited>0</unlimited>
|
||||
<penalty>0.33</penalty>
|
||||
<hint>
|
||||
<statenumberofcorrectresponses>1</statenumberofcorrectresponses>
|
||||
<clearincorrectresponses>0</clearincorrectresponses>
|
||||
<hintcontent>
|
||||
<text>You may wish to read Section 9 of <em ' .
|
||||
'class="italic">Discovering Science</em> Block 8.</text>
|
||||
</hintcontent>
|
||||
</hint>
|
||||
<hint>
|
||||
<statenumberofcorrectresponses>1</statenumberofcorrectresponses>
|
||||
<clearincorrectresponses>1</clearincorrectresponses>
|
||||
<hintcontent>
|
||||
<text>Any incorrect choices will be removed before your final try.</text>
|
||||
</hintcontent>
|
||||
</hint>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$q = $importer->try_importing_using_qtypes(
|
||||
$xmldata['question'], null, null, 'ddwtos');
|
||||
|
||||
$expectedq = new stdClass();
|
||||
$expectedq->qtype = 'ddwtos';
|
||||
$expectedq->name = 'QDandD1 Base definition';
|
||||
$expectedq->questiontext = '<p>Drag and drop the words from the list below ' .
|
||||
'to fill the blank spaces and correctly complete the sentence.</p>' .
|
||||
'<p>At 25°C all aqueous basic solutions have [[1]] ion concentrations ' .
|
||||
'less than [[8]]<br />mol litre<sup>-1</sup> and pH values [[9]] than [[6]].</p>' .
|
||||
'<!--DONOTCLEAN-->';
|
||||
$expectedq->questiontextformat = FORMAT_HTML;
|
||||
$expectedq->generalfeedback = '<p>At 25 °C all aqueous basic solutions ' .
|
||||
'have hydrogen ion concentrations less than 10<sup>−7</sup> ' .
|
||||
'mol litre<sup>−1</sup> and pH values greater than 7.</p><p>See ' .
|
||||
'Section 9 of S103 <em class="italic">Discovering Science</em> Block 8.</p>';
|
||||
$expectedq->defaultmark = 1;
|
||||
$expectedq->length = 1;
|
||||
$expectedq->penalty = 0.3333333;
|
||||
|
||||
$expectedq->shuffleanswers = 0;
|
||||
$expectedq->correctfeedback = array('text' => 'Your answer is correct.',
|
||||
'format' => FORMAT_HTML);
|
||||
$expectedq->partiallycorrectfeedback = array(
|
||||
'text' => 'Your answer is partially correct.',
|
||||
'format' => FORMAT_HTML);
|
||||
$expectedq->shownumcorrect = true;
|
||||
$expectedq->incorrectfeedback = array('text' => 'Your answer is incorrect.',
|
||||
'format' => FORMAT_HTML);
|
||||
|
||||
$expectedq->choices = array(
|
||||
array('answer' => array('text' => 'hydrogen', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 1, 'infinite' => false),
|
||||
array('answer' => array('text' => 'positive', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 1, 'infinite' => false),
|
||||
array('answer' => array('text' => 'hydroxide', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 1, 'infinite' => false),
|
||||
array('answer' => array('text' => 'negative', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 1, 'infinite' => false),
|
||||
array('answer' => array('text' => '10<sup>7</sup>', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 2, 'infinite' => false),
|
||||
array('answer' => array('text' => '7', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 2, 'infinite' => false),
|
||||
array('answer' => array('text' => '1', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 2, 'infinite' => false),
|
||||
array('answer' => array('text' => '10<sup>-7</sup>', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 2, 'infinite' => false),
|
||||
array('answer' => array('text' => 'greater', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 3, 'infinite' => false),
|
||||
array('answer' => array('text' => 'less', 'format' => FORMAT_PLAIN),
|
||||
'choicegroup' => 3, 'infinite' => false),
|
||||
);
|
||||
|
||||
$expectedq->hint = array(array('text' => 'You may wish to read Section 9 of ' .
|
||||
'<em class="italic">Discovering Science</em> Block 8.',
|
||||
'format' => FORMAT_HTML),
|
||||
array('text' => 'Any incorrect choices will be removed before your final try.',
|
||||
'format' => FORMAT_HTML),
|
||||
);
|
||||
$expectedq->hintshownumcorrect = array(true, true);
|
||||
$expectedq->hintclearwrong = array(false, true);
|
||||
|
||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||
$this->assertEquals($expectedq->choices, $q->choices);
|
||||
$this->assertEquals($expectedq->hint, $q->hint);
|
||||
}
|
||||
|
||||
public function test_xml_export() {
|
||||
$qdata = new stdClass();
|
||||
$qdata->id = 123;
|
||||
|
||||
Reference in New Issue
Block a user