mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-66801 questions: XML import/export should include category idnumbers
This commit is contained in:
parent
9528b1ff5b
commit
e247068d72
8 changed files with 48 additions and 19 deletions
|
@ -935,6 +935,7 @@ class qformat_xml extends qformat_default {
|
|||
// The import should have the format in human readable form, so translate to machine readable format.
|
||||
$qo->infoformat = $this->trans_format($question['#']['info'][0]['@']['format']);
|
||||
}
|
||||
$qo->idnumber = $this->getpath($question, array('#', 'idnumber', 0, '#'), null);
|
||||
return $qo;
|
||||
}
|
||||
|
||||
|
@ -1205,6 +1206,7 @@ class qformat_xml extends qformat_default {
|
|||
$expout .= " <info {$infoformat}>\n";
|
||||
$expout .= " {$categoryinfo}";
|
||||
$expout .= " </info>\n";
|
||||
$expout .= " <idnumber>{$question->idnumber}</idnumber>\n";
|
||||
$expout .= " </question>\n";
|
||||
return $expout;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<info format="moodle_auto_format">
|
||||
<text>This is Alpha category for test</text>
|
||||
</info>
|
||||
<idnumber>alpha-idnumber</idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 91 -->
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<info format="moodle_auto_format">
|
||||
<text>This is Alpha category for test</text>
|
||||
</info>
|
||||
<idnumber>alpha-idnumber</idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 91 -->
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<info format="plain_text">
|
||||
<text>This is Delta category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 0 -->
|
||||
|
@ -18,6 +19,7 @@
|
|||
<info format="markdown">
|
||||
<text>This is Epsilon category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 0 -->
|
||||
|
@ -28,6 +30,7 @@
|
|||
<info format="moodle_auto_format">
|
||||
<text>This is Zeta category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 93 -->
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<info format="plain_text">
|
||||
<text>This is Iota category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 96 -->
|
||||
|
@ -47,6 +48,7 @@
|
|||
<info format="markdown">
|
||||
<text>This is Kappa category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 106 -->
|
||||
|
@ -114,6 +116,7 @@
|
|||
<info format="moodle_auto_format">
|
||||
<text>This is Lambda category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 98 -->
|
||||
|
@ -153,6 +156,7 @@
|
|||
<info format="moodle_auto_format">
|
||||
<text>This is Mu category for test</text>
|
||||
</info>
|
||||
<idnumber></idnumber>
|
||||
</question>
|
||||
|
||||
<!-- question: 99 -->
|
||||
|
|
|
@ -38,8 +38,8 @@ class qformat_xml_import_export_test extends advanced_testcase {
|
|||
/**
|
||||
* Create object qformat_xml for test.
|
||||
* @param string $filename with name for testing file.
|
||||
* @param object $course
|
||||
* @return object qformat_xml.
|
||||
* @param stdClass $course
|
||||
* @return qformat_xml XML question format object.
|
||||
*/
|
||||
public function create_qformat($filename, $course) {
|
||||
global $DB;
|
||||
|
@ -99,11 +99,12 @@ class qformat_xml_import_export_test extends advanced_testcase {
|
|||
* @param string $info imported category info field (description of category).
|
||||
* @param int $infoformat imported category info field format.
|
||||
*/
|
||||
public function assert_category_imported($name, $info, $infoformat) {
|
||||
public function assert_category_imported($name, $info, $infoformat, $idnumber = null) {
|
||||
global $DB;
|
||||
$category = $DB->get_record('question_categories', ['name' => $name], '*', MUST_EXIST);
|
||||
$this->assertEquals($info, $category->info);
|
||||
$this->assertEquals($infoformat, $category->infoformat);
|
||||
$this->assertSame($idnumber, $category->idnumber);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +147,8 @@ class qformat_xml_import_export_test extends advanced_testcase {
|
|||
$qformat = $this->create_qformat('category_with_description.xml', $course);
|
||||
$imported = $qformat->importprocess();
|
||||
$this->assertTrue($imported);
|
||||
$this->assert_category_imported('Alpha', 'This is Alpha category for test', FORMAT_MOODLE);
|
||||
$this->assert_category_imported('Alpha',
|
||||
'This is Alpha category for test', FORMAT_MOODLE, 'alpha-idnumber');
|
||||
$this->assert_category_has_parent('Alpha', 'top');
|
||||
}
|
||||
|
||||
|
@ -246,6 +248,7 @@ class qformat_xml_import_export_test extends advanced_testcase {
|
|||
'contextid' => '2',
|
||||
'info' => 'This is Alpha category for test',
|
||||
'infoformat' => '0',
|
||||
'idnumber' => 'alpha-idnumber',
|
||||
'stamp' => make_unique_id_code(),
|
||||
'parent' => '0',
|
||||
'sortorder' => '999']);
|
||||
|
|
|
@ -1721,6 +1721,7 @@ END;
|
|||
$categoryinfo = new stdClass();
|
||||
$categoryinfo->info = 'info1';
|
||||
$categoryinfo->infoformat = 'infoformat1';
|
||||
$categoryinfo->idnumber = null;
|
||||
$dummyquestion = $testobject->mock_create_dummy_question_representing_category($categoryname, $categoryinfo);
|
||||
|
||||
$this->assertEquals('category', $dummyquestion->qtype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue