Skip to content

Commit

Permalink
quiz-data - First export quiz unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Nov 14, 2024
1 parent fe737cb commit a5e3005
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 306 deletions.
5 changes: 4 additions & 1 deletion classes/export_quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
$this->curlrequest->set_option(CURLOPT_RETURNTRANSFER, true);
$this->curlrequest->set_option(CURLOPT_POST, 1);
$this->curlrequest->set_option(CURLOPT_POSTFIELDS, $this->postsettings);
if (!$arguments()['subcall']) {
if (!$arguments['subcall']) {
$this->listcurlrequest = $this->get_curl_request($wsurl);
$this->listpostsettings = [
'wstoken' => $token,
Expand Down Expand Up @@ -221,6 +221,7 @@ public function export_quiz_data() {
}
$quizmanifestentries = [];
$nonquizmanifestentries = [];
// Determine quiz info location based on loactions of manifest paths.
if ($this->quizmanifestpath) {
$this->filepath = cli_helper::get_quiz_structure_path($responsejson->quiz->name, dirname($this->quizmanifestpath));
$quizmanifestentries = array_column($this->quizmanifestcontents->questions, null, 'questionbankentryid');
Expand All @@ -230,6 +231,7 @@ public function export_quiz_data() {
if ($this->nonquizmanifestpath) {
$nonquizmanifestentries = array_column($this->nonquizmanifestcontents->questions, null, 'questionbankentryid');
}
// Convert the returned QBE ids into file locations using the manifest files to translate.
foreach ($responsejson->questions as $question) {
$quizmanifestentry = $quizmanifestentries["{$question->questionbankentryid}"] ?? false;
$nonquizmanifestentry = $nonquizmanifestentries["{$question->questionbankentryid}"] ?? false;
Expand All @@ -250,6 +252,7 @@ public function export_quiz_data() {
"consider consolidating them.\n";
}
}
// Save exported information (including relative file location but not QBE id so Moodle independent).
file_put_contents($this->filepath, json_encode($responsejson));
echo "Quiz data exported to:\n";
echo "{$this->filepath}\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"coursename": "",
"modulename": "",
"coursecategory": "",
"qcategoryname": "/top",
"instanceid": "",
"defaultsubdirectory": "top\/cat-2",
"defaultsubcategoryid": 5
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"context": {
"contextlevel": 10,
"coursename": "",
"modulename": "",
"coursecategory": "",
"instanceid": "",
"defaultsubdirectory": "top\/cat-2",
"defaultsubcategoryid": 5
},
"questions": [
{
"questionbankentryid": 35001,
"filepath": "\/top\/cat-1\/First-Question.xml",
"importedversion": "1",
"exportedversion": "1",
"format": "xml"
},
{
"questionbankentryid": 35002,
"filepath": "\/top\/cat-2\/subcat-2_1\/Third-Question.xml",
"importedversion": "6",
"exportedversion": "7",
"format": "xml"
},
{
"questionbankentryid": 35004,
"filepath": "\/top\/cat-2\/subcat-2_1\/Fourth-Question.xml",
"importedversion": "1",
"exportedversion": "1",
"currentcommit": "35004test",
"format": "xml"
},
{
"questionbankentryid": 35003,
"filepath": "\/top\/cat-2\/Second-Question.xml",
"importedversion": "1",
"exportedversion": "1",
"format": "xml"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"coursename": "",
"modulename": "",
"coursecategory": "",
"qcategoryname": "/top",
"instanceid": "",
"defaultsubdirectory": "top\/cat-2",
"defaultsubcategoryid": 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"context": {
"contextlevel": 70,
"coursename": "",
"modulename": "",
"coursecategory": "",
"instanceid": "",
"defaultsubdirectory": "top",
"defaultsubcategoryid": 5
},
"questions": [
{
"questionbankentryid":"36001",
"filepath": "\/top\/Quiz-Question.xml",
"importedversion": "1",
"exportedversion": "1",
"format": "xml"
}
]
}
25 changes: 25 additions & 0 deletions testrepoparent/testrepo_quiz_quiz-1/top/Quiz-Question.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<question type="shortanswer">
<name>
<text>Quiz Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p dir="ltr" style="text-align: left;">This is a test question.<br></p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<usecase>0</usecase>
<answer fraction="100" format="moodle_auto_format">
<text>This is a test answer.</text>
<feedback format="html">
<text></text>
</feedback>
</answer>
</question>
</quiz>
12 changes: 12 additions & 0 deletions testrepoparent/testrepo_quiz_quiz-1/top/gitsync_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<question type="category">
<category>
<text>top/cat 1</text>
</category>
<info format="moodle_auto_format">
<text>First imported folder</text>
</info>
<idnumber></idnumber>
</question>
</quiz>
Loading

0 comments on commit a5e3005

Please sign in to comment.