first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for qformat_xml.
*
* @package qformat_xml
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qformat_xml\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for qformat_xml implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'qformat_xml', language 'en', branch 'MOODLE_20_STABLE'
*
* @package qformat_xml
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['invalidxml'] = 'Invalid XML file - string expected (use CDATA?)';
$string['pluginname'] = 'Moodle XML format';
$string['pluginname_help'] = 'This is a Moodle-specific format for importing and exporting questions.';
$string['pluginname_link'] = 'qformat/xml';
$string['privacy:metadata'] = 'The XML question format plugin does not store any personal data.';
$string['truefalseimporterror'] = '<b>Warning</b>: The true/false question \'{$a->questiontext}\' could not be imported properly. It was not clear whether the correct answer is true or false. The question has been imported assuming that the answer is \'{$a->answer}\'. If this is not correct, you will need to edit the question.';
$string['unsupportedexport'] = 'Question type {$a} is not supported by XML export';
$string['xmlimportnoname'] = 'Missing question name in XML file';
$string['xmlimportnoquestion'] = 'Missing question text in XML file';
$string['xmltypeunsupported'] = 'Question type {$a} is not supported by XML import';
@@ -0,0 +1,78 @@
@qformat @qformat_xml
Feature: Test importing questions from Moodle XML format.
In order to reuse questions
As an teacher
I need to be able to import them in XML format.
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "users" exist:
| username | firstname |
| teacher | Teacher |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
@javascript @_file_upload
Scenario: import some true/false questions from Moodle XML format
When I am on the "Course 1" "core_question > course question import" page logged in as "teacher"
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/truefalse.xml" file to "Import" filemanager
And I press "id_submitbutton"
Then I should see "Parsing questions from import file."
And I should see "Importing 2 questions from file"
And I should see "is an acronym for Modular Object-Oriented Dynamic Learning Education"
And I should see "is an acronym for Modular Object-Oriented Dynamic Learning Environment"
When I press "Continue"
Then I should see "Moodle acronym (False)"
Then I should see "Moodle acronym (True)"
# Now export again.
When I am on the "Course 1" "core_question > course question export" page logged in as "teacher"
And I set the field "id_format_xml" to "1"
And I set the field "Export category" to "TrueFalse"
And I press "Export questions to file"
Then following "click here" should download a file that:
| Has mimetype | text/xml |
| Contains text in xml element | Moodle acronym (True) |
| Contains text in xml element | Moodle acronym (False) |
@javascript @_file_upload
Scenario: import some multiple choice questions from Moodle XML format
When I am on the "Course 1" "core_question > course question import" page logged in as "teacher"
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/multichoice.xml" file to "Import" filemanager
And I press "id_submitbutton"
Then I should see "Parsing questions from import file."
And I should see "Importing 1 questions from file"
And I should see "What language is being spoken?"
When I press "Continue"
Then I should see "Greeting"
@javascript @_file_upload
Scenario: import some multi-answer questions from Moodle XML format
When I am on the "Course 1" "core_question > course question import" page logged in as "teacher"
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/multianswer.xml" file to "Import" filemanager
And I press "id_submitbutton"
Then I should see "Parsing questions from import file."
And I should see "Importing 1 questions from file"
And I should see "Match the following cities with the correct state,"
When I press "Continue"
Then I should see "cloze with images"
@javascript @_file_upload
Scenario: import some questions with legacy-style images from Moodle XML format
When I am on the "Course 1" "core_question > course question import" page logged in as "teacher"
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/sample_questions_with_old_image_tag.xml" file to "Import" filemanager
And I press "id_submitbutton"
Then I should see "Parsing questions from import file."
And I should see "Importing 2 questions from file"
And I should see "This is a multianswer question with an image in the old"
And I should see "This is a multichoice question with an image in the old"
When I press "Continue"
Then I should see "cloze question with image"
Then I should see "mcq with image"
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 1 -->
<question type="cloze">
<name>
<text>Multianswer question without subquestions</text>
</name>
<questiontext format="html">
<text>Please select the fruits.</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
<!-- question: 2 -->
<question type="cloze">
<name>
<text>Multichoice subquestion without choices</text>
</name>
<questiontext format="html">
<text>Please select the fruits {1:MULTICHOICE}</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
<!-- question: 3 -->
<question type="cloze">
<name>
<text>Multichoice subquestion with only one choice</text>
</name>
<questiontext format="html">
<text>Please select the fruits {1:MULTICHOICE:=Apple#Correct}</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
<!-- question: 4 -->
<question type="cloze">
<name>
<text>Multichoice subquestion with no completely correct answer</text>
</name>
<questiontext format="html">
<text>Please select the fruits {1:MULTICHOICE:Pear#Incorrect~%50%Apple#Correct}</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
<!-- question: 5 -->
<question type="cloze">
<name>
<text>Numerical subquestion with buggy answer</text>
</name>
<questiontext format="html">
<text>What grade would you give it? {3:NUMERICAL:=zero}</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
</quiz>
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Sigma/Tau</text>
</category>
<info format="html">
<text>This is Tau category for test</text>
</info>
</question>
<!-- question: 106 -->
<question type="essay">
<name>
<text>Tau Question</text>
</name>
<questiontext format="moodle_auto_format">
<text>Testing Tau Question</text>
</questiontext>
<generalfeedback format="moodle_auto_format">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<responseformat>editor</responseformat>
<responserequired>1</responserequired>
<responsefieldlines>15</responsefieldlines>
<attachments>0</attachments>
<attachmentsrequired>0</attachmentsrequired>
<graderinfo format="html">
<text></text>
</graderinfo>
<responsetemplate format="html">
<text></text>
</responsetemplate>
</question>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Sigma</text>
</category>
<info format="html">
<text>This is Sigma category for test</text>
</info>
</question>
<!-- question: 105 -->
<question type="shortanswer">
<name>
<text>Sigma Question</text>
</name>
<questiontext format="moodle_auto_format">
<text>Testing Sigma Question</text>
</questiontext>
<generalfeedback format="moodle_auto_format">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<usecase>0</usecase>
<answer fraction="100" format="moodle_auto_format">
<text>yes</text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="0" format="moodle_auto_format">
<text>no</text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="0" format="moodle_auto_format">
<text>may be</text>
<feedback format="html">
<text></text>
</feedback>
</answer>
</question>
</quiz>
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Alpha</text>
</category>
<info format="moodle_auto_format">
<text>This is Alpha category for test</text>
</info>
<idnumber>alpha-idnumber</idnumber>
</question>
<!-- question: 91 -->
<question type="truefalse">
<name>
<text>Alpha Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Alpha Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></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>
</quiz>
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 1 -->
<question type="multichoice">
<name>
<text><![CDATA[Question with <strong>invalid grades</strong> : x > 1 & x < 2]]></text>
</name>
<questiontext format="html">
<text><![CDATA[Select all prime numbers :<br>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<single>false</single>
<shuffleanswers>true</shuffleanswers>
<answernumbering>abc</answernumbering>
<showstandardinstruction>0</showstandardinstruction>
<correctfeedback format="html">
<text>Your answer is correct.</text>
</correctfeedback>
<partiallycorrectfeedback format="html">
<text>Your answer is partially correct.</text>
</partiallycorrectfeedback>
<incorrectfeedback format="html">
<text>Your answer is incorrect.</text>
</incorrectfeedback>
<shownumcorrect/>
<answer fraction="-50" format="html">
<text><![CDATA[<p dir="ltr" style="text-align: left;">1<br></p>]]></text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="33" format="html"> <!-- Invalid grade. -->
<text><![CDATA[<p dir="ltr" style="text-align: left;">2<br></p>]]></text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="33.33333" format="html">
<text><![CDATA[<p dir="ltr" style="text-align: left;">3<br></p>]]></text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="-50" format="html">
<text><![CDATA[<p dir="ltr" style="text-align: left;">4<br></p>]]></text>
<feedback format="html">
<text></text>
</feedback>
</answer>
<answer fraction="33.33333" format="html">
<text><![CDATA[<p dir="ltr" style="text-align: left;">5<br></p>]]></text>
<feedback format="html">
<text></text>
</feedback>
</answer>
</question>
</quiz>
+43
View File
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Alpha</text>
</category>
<info format="moodle_auto_format">
<text>This is Alpha category for test</text>
</info>
<idnumber>alpha-idnumber</idnumber>
</question>
<!-- question: 91 -->
<question type="truefalse">
<name>
<text>Alpha Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Alpha Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
</quiz>
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Alpha</text>
</category>
<info format="moodle_auto_format">
<text>This is Alpha category for test</text>
</info>
<idnumber>The inequalities &lt; &amp; &gt;</idnumber>
</question>
<!-- question: 91 -->
<question type="truefalse">
<name>
<text>Alpha Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Alpha Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber>T &amp; F</idnumber>
<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>
</quiz>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Delta</text>
</category>
<info format="plain_text">
<text>This is Delta category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Delta/Epsilon</text>
</category>
<info format="markdown">
<text>This is Epsilon category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Delta/Epsilon/Zeta</text>
</category>
<info format="moodle_auto_format">
<text>This is Zeta category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 93 -->
<question type="truefalse">
<name>
<text>Zeta Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Zeta Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
</quiz>
@@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Iota</text>
</category>
<info format="plain_text">
<text>This is Iota category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 96 -->
<question type="truefalse">
<name>
<text>Iota Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Iota Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Iota/Kappa</text>
</category>
<info format="markdown">
<text>This is Kappa category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 106 -->
<question type="essay">
<name>
<text>Kappa Essay Question</text>
</name>
<questiontext format="moodle_auto_format">
<text>Testing Kappa Essay Question</text>
</questiontext>
<generalfeedback format="moodle_auto_format">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<responseformat>editor</responseformat>
<responserequired>1</responserequired>
<responsefieldlines>10</responsefieldlines>
<minwordlimit></minwordlimit>
<maxwordlimit></maxwordlimit>
<attachments>0</attachments>
<attachmentsrequired>0</attachmentsrequired>
<maxbytes>0</maxbytes>
<filetypeslist></filetypeslist>
<graderinfo format="html">
<text></text>
</graderinfo>
<responsetemplate format="html">
<text></text>
</responsetemplate>
</question>
<!-- question: 97 -->
<question type="truefalse">
<name>
<text>Kappa Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Kappa Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Iota/Kappa/Lambda</text>
</category>
<info format="moodle_auto_format">
<text>This is Lambda category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 98 -->
<question type="truefalse">
<name>
<text>Lambda Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Lambda Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Iota/Mu</text>
</category>
<info format="moodle_auto_format">
<text>This is Mu category for test</text>
</info>
<idnumber></idnumber>
</question>
<!-- question: 99 -->
<question type="truefalse">
<name>
<text>Mu Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Mu Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<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>
</quiz>
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Pi</text>
</category>
</question>
<!-- question: 103 -->
<question type="truefalse">
<name>
<text>Pi Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Pi Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></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>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Pi/Rho</text>
</category>
</question>
<!-- question: 104 -->
<question type="truefalse">
<name>
<text>Rho Question</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Testing Rho Question</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></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>
</quiz>
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Default for Test images in backup</text>
</category>
</question>
<!-- question: 5 -->
<question type="cloze">
<name><text>cloze question with image</text>
</name>
<questiontext>
<text><![CDATA[This is a multianswer question with an image in the old &quot;image&quot; field that was used in moodle 1.9.<br />Match the following cities with the correct state:<br />* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}<br />* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}<br />* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}<br />* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}<br />The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!<br />~%50%Marseille#No, that is the second largest city in France (after<br />Paris).~*#Wrong answer. The capital of France is Paris, of course.}.<br />]]></text>
</questiontext>
<image>moodle.png</image>
<image_base64>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAHzSURBVDhPxZFbSJNhGIDXERsVGbKawWJaoyAYGeqNYgdl6zenrhhUlB0I6iJEbUl0WF1UUK2DYhDkGghu7Z+HraisPLAsu+0ygi66kCioqwg2t6f///YhzAVBXfTc/HzP9/J8L/wG/pG8QDw+TE+Xn/O+dva07MW5vZayys3yNp/ZwPPRBPuOHqGisordDc00Ki42bqhAjQ3Jid8jAvoL9vIt4qs463G73VRtrcFiseDvuSYG+TwB7y/zfdzHpzeDWachAjeuXyWkPqZ21zZ2Nrioa/JQarOjlK8jes7Eh/s18GwHRMxkgka+3lvEi1ubcgM63Zea6W5v5ESLB4fDwRVvNam+eRBey3TAxqObNl76rXwLFvAlsIyhC2W5gZ+JJmYixQS9q8RZZzpghwEr/R2LpYGPIYWZqJnYSWNugCkPPDDx1JddTyeZqCetasMdS6WB9OQB7Xet5kmbITeQntoP/YWEfSZxFoy5SA2YCXeukAJ+vD5MMl7Cw9YF2UAkGhIXmYSbZLgI9WKxOOukx52kVAvq6eXS6HOHyAyuRz0lN5hlwg19hcTOWqXQ0FxaXZPnGC4V7s+BsToRUM8YpdA2eHswG/DO2eDV7WpGWg30dpZIA5Nddkba5nP3+Epp4F2vwqh3CXeOLZyzwV/wvwPwC58bSNEdAkhaAAAAAElFTkSuQmCC
</image_base64>
<generalfeedback>
<text></text>
</generalfeedback>
<shuffleanswers>0</shuffleanswers>
</question>
<!-- question: 4 -->
<question type="multichoice">
<name><text>mcq with image</text>
</name>
<questiontext format="html">
<text><![CDATA[This is a multichoice question with an image in the old &quot;image&quot; field that was used in Moodle 1.9]]></text>
</questiontext>
<image>moodle.png</image>
<image_base64>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAHzSURBVDhPxZFbSJNhGIDXERsVGbKawWJaoyAYGeqNYgdl6zenrhhUlB0I6iJEbUl0WF1UUK2DYhDkGghu7Z+HraisPLAsu+0ygi66kCioqwg2t6f///YhzAVBXfTc/HzP9/J8L/wG/pG8QDw+TE+Xn/O+dva07MW5vZayys3yNp/ZwPPRBPuOHqGisordDc00Ki42bqhAjQ3Jid8jAvoL9vIt4qs463G73VRtrcFiseDvuSYG+TwB7y/zfdzHpzeDWachAjeuXyWkPqZ21zZ2Nrioa/JQarOjlK8jes7Eh/s18GwHRMxkgka+3lvEi1ubcgM63Zea6W5v5ESLB4fDwRVvNam+eRBey3TAxqObNl76rXwLFvAlsIyhC2W5gZ+JJmYixQS9q8RZZzpghwEr/R2LpYGPIYWZqJnYSWNugCkPPDDx1JddTyeZqCetasMdS6WB9OQB7Xet5kmbITeQntoP/YWEfSZxFoy5SA2YCXeukAJ+vD5MMl7Cw9YF2UAkGhIXmYSbZLgI9WKxOOukx52kVAvq6eXS6HOHyAyuRz0lN5hlwg19hcTOWqXQ0FxaXZPnGC4V7s+BsToRUM8YpdA2eHswG/DO2eDV7WpGWg30dpZIA5Nddkba5nP3+Epp4F2vwqh3CXeOLZyzwV/wvwPwC58bSNEdAkhaAAAAAElFTkSuQmCC
</image_base64>
<generalfeedback>
<text></text>
</generalfeedback>
<defaultgrade>1</defaultgrade>
<penalty>0.1</penalty>
<hidden>0</hidden>
<shuffleanswers>1</shuffleanswers>
<single>true</single>
<shuffleanswers>true</shuffleanswers>
<correctfeedback> <text></text>
</correctfeedback>
<partiallycorrectfeedback> <text></text>
</partiallycorrectfeedback>
<incorrectfeedback> <text></text>
</incorrectfeedback>
<answernumbering>abc</answernumbering>
<answer fraction="0">
<text>
wrong answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
<answer fraction="0">
<text>
another wrong answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
<answer fraction="100">
<text>
right answer
</text>
<feedback>
<text>
</text>
</feedback>
</answer>
</question>
</quiz>
File diff suppressed because one or more lines are too long
@@ -0,0 +1,526 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for export/import description (info) for question category in the Moodle XML format.
*
* @package qformat_xml
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core_question\local\bank\question_edit_contexts;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format/xml/format.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
require_once($CFG->dirroot . '/question/editlib.php');
/**
* Unit tests for the XML question format import and export.
*
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_xml_import_export_test extends advanced_testcase {
/**
* Create object qformat_xml for test.
* @param string $filename with name for testing file.
* @param stdClass $course
* @return qformat_xml XML question format object.
*/
public function create_qformat($filename, $course) {
$qformat = new qformat_xml();
$qformat->setContexts((new question_edit_contexts(context_course::instance($course->id)))->all());
$qformat->setCourse($course);
$qformat->setFilename(__DIR__ . '/fixtures/' . $filename);
$qformat->setRealfilename($filename);
$qformat->setMatchgrades('error');
$qformat->setCatfromfile(1);
$qformat->setContextfromfile(1);
$qformat->setStoponerror(1);
$qformat->setCattofile(1);
$qformat->setContexttofile(1);
$qformat->set_display_progress(false);
return $qformat;
}
/**
* Check xml for compliance.
* @param string $expectedxml with correct string.
* @param string $xml you want to check.
*/
public function assert_same_xml($expectedxml, $xml) {
$this->assertEquals($this->normalise_xml($expectedxml),
$this->normalise_xml($xml));
}
/**
* Clean up some XML to remove irrelevant differences, before it is compared.
* @param string $xml some XML.
* @return string cleaned-up XML.
*/
protected function normalise_xml($xml) {
// Normalise line endings.
$xml = phpunit_util::normalise_line_endings($xml);
$xml = preg_replace("~\n$~", "", $xml); // Strip final newline in file.
// Replace all numbers in question id comments with 0.
$xml = preg_replace('~(?<=<!-- question: )([0-9]+)(?= -->)~', '0', $xml);
// Deal with how different databases output numbers. Only match when only thing in a tag.
$xml = preg_replace("~>.0000000<~", '>0<', $xml); // How Oracle outputs 0.0000000.
$xml = preg_replace("~(\.(:?[0-9]*[1-9])?)0*<~", '$1<', $xml); // Other cases of trailing 0s
$xml = preg_replace("~([0-9]).<~", '$1<', $xml); // Stray . in 1. after last step.
return $xml;
}
/**
* Check imported category.
* @param string $name imported category name.
* @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, $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);
}
/**
* Check a question category has a given parent.
* @param string $catname Name of the question category
* @param string $parentname Name of the parent category
* @throws dml_exception
*/
public function assert_category_has_parent($catname, $parentname) {
global $DB;
$sql = 'SELECT qc1.*
FROM {question_categories} qc1
JOIN {question_categories} qc2 ON qc1.parent = qc2.id
WHERE qc1.name = ?
AND qc2.name = ?';
$categories = $DB->get_records_sql($sql, [$catname, $parentname]);
$this->assertTrue(count($categories) == 1);
}
/**
* Check a question exists in a category.
* @param string $qname The name of the question
* @param string $catname The name of the category
* @throws dml_exception
*/
public function assert_question_in_category($qname, $catname) {
global $DB;
$sql = "SELECT q.*, qbe.questioncategoryid AS category
FROM {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
WHERE q.name = :name";
$question = $DB->get_record_sql($sql, ['name' => $qname], MUST_EXIST);
$category = $DB->get_record('question_categories', ['name' => $catname], '*', MUST_EXIST);
$this->assertEquals($category->id, $question->category);
}
/**
* Simple check for importing a category with a description.
*/
public function test_import_category(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$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, 'alpha-idnumber');
$this->assert_category_has_parent('Alpha', 'top');
}
/**
* Check importing nested categories.
*/
public function test_import_nested_categories(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$qformat = $this->create_qformat('nested_categories.xml', $course);
$imported = $qformat->importprocess();
$this->assertTrue($imported);
$this->assert_category_imported('Delta', 'This is Delta category for test', FORMAT_PLAIN);
$this->assert_category_imported('Epsilon', 'This is Epsilon category for test', FORMAT_MARKDOWN);
$this->assert_category_imported('Zeta', 'This is Zeta category for test', FORMAT_MOODLE);
$this->assert_category_has_parent('Delta', 'top');
$this->assert_category_has_parent('Epsilon', 'Delta');
$this->assert_category_has_parent('Zeta', 'Epsilon');
}
/**
* Check importing nested categories contain the right questions.
*/
public function test_import_nested_categories_with_questions(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$qformat = $this->create_qformat('nested_categories_with_questions.xml', $course);
$imported = $qformat->importprocess();
$this->assertTrue($imported);
$this->assert_category_imported('Iota', 'This is Iota category for test', FORMAT_PLAIN);
$this->assert_category_imported('Kappa', 'This is Kappa category for test', FORMAT_MARKDOWN);
$this->assert_category_imported('Lambda', 'This is Lambda category for test', FORMAT_MOODLE);
$this->assert_category_imported('Mu', 'This is Mu category for test', FORMAT_MOODLE);
$this->assert_question_in_category('Iota Question', 'Iota');
$this->assert_question_in_category('Kappa Question', 'Kappa');
$this->assert_question_in_category('Lambda Question', 'Lambda');
$this->assert_question_in_category('Mu Question', 'Mu');
$this->assert_category_has_parent('Iota', 'top');
$this->assert_category_has_parent('Kappa', 'Iota');
$this->assert_category_has_parent('Lambda', 'Kappa');
$this->assert_category_has_parent('Mu', 'Iota');
}
/**
* Check import of an old file (without format), for backward compatability.
*/
public function test_import_old_format(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$qformat = $this->create_qformat('old_format_file.xml', $course);
$imported = $qformat->importprocess();
$this->assertTrue($imported);
$this->assert_category_imported('Pi', '', FORMAT_MOODLE);
$this->assert_category_imported('Rho', '', FORMAT_MOODLE);
$this->assert_question_in_category('Pi Question', 'Pi');
$this->assert_question_in_category('Rho Question', 'Rho');
$this->assert_category_has_parent('Pi', 'top');
$this->assert_category_has_parent('Rho', 'Pi');
}
/**
* Check the import of an xml file where the child category exists before the parent category.
*/
public function test_import_categories_in_reverse_order(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$qformat = $this->create_qformat('categories_reverse_order.xml', $course);
$imported = $qformat->importprocess();
$this->assertTrue($imported);
$this->assert_category_imported('Sigma', 'This is Sigma category for test', FORMAT_HTML);
$this->assert_category_imported('Tau', 'This is Tau category for test', FORMAT_HTML);
$this->assert_question_in_category('Sigma Question', 'Sigma');
$this->assert_question_in_category('Tau Question', 'Tau');
$this->assert_category_has_parent('Sigma', 'top');
$this->assert_category_has_parent('Tau', 'Sigma');
}
/**
* Check exception when importing questions with invalid grades.
*
* @covers \qformat_default::importprocess
*/
public function test_import_invalid_grades(): void {
global $OUTPUT;
$this->resetAfterTest(true);
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$qformat = $this->create_qformat('error_invalid_grades.xml', $course);
ob_start();
$imported = $qformat->importprocess();
$output = ob_get_clean();
$a = ['grades' => '0.33', 'question' => 'Question with invalid grades : x > 1 & x < 2'];
$expectedoutput = $OUTPUT->notification(get_string('invalidgradequestion', 'question', $a));
$expectedoutput .= $OUTPUT->notification(get_string('importparseerror', 'question'));
$this->assertFalse($imported);
$this->assertEquals($expectedoutput, $output);
}
/**
* Simple check for exporting a category.
*/
public function test_export_category(): void {
global $SITE;
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$this->resetAfterTest();
$this->setAdminUser();
// Note while this loads $qformat with all the 'right' data from the xml file,
// the call to setCategory, followed by exportprocess will actually only export data
// from the database (created by the generator).
$qformat = $this->create_qformat('export_category.xml', $SITE);
$category = $generator->create_question_category([
'name' => 'Alpha',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Alpha category for test',
'infoformat' => '0',
'idnumber' => 'alpha-idnumber',
'stamp' => make_unique_id_code(),
'parent' => '0',
'sortorder' => '999']);
$question = $generator->create_question('truefalse', null, [
'category' => $category->id,
'name' => 'Alpha Question',
'questiontext' => ['format' => '1', 'text' => '<p>Testing Alpha Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$qformat->setCategory($category);
$expectedxml = file_get_contents(__DIR__ . '/fixtures/export_category.xml');
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
}
/**
* Check exporting nested categories.
*/
public function test_export_nested_categories(): void {
global $SITE;
$this->resetAfterTest();
$this->setAdminUser();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$qformat = $this->create_qformat('nested_categories.zml', $SITE);
$categorydelta = $generator->create_question_category([
'name' => 'Delta',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Delta category for test',
'infoformat' => '2',
'stamp' => make_unique_id_code(),
'parent' => '0',
'sortorder' => '999']);
$categoryepsilon = $generator->create_question_category([
'name' => 'Epsilon',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Epsilon category for test',
'infoformat' => '4',
'stamp' => make_unique_id_code(),
'parent' => $categorydelta->id,
'sortorder' => '999']);
$categoryzeta = $generator->create_question_category([
'name' => 'Zeta',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Zeta category for test',
'infoformat' => '0',
'stamp' => make_unique_id_code(),
'parent' => $categoryepsilon->id,
'sortorder' => '999']);
$question = $generator->create_question('truefalse', null, [
'category' => $categoryzeta->id,
'name' => 'Zeta Question',
'questiontext' => [
'format' => '1',
'text' => '<p>Testing Zeta Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$qformat->setCategory($categorydelta);
$qformat->setCategory($categoryepsilon);
$qformat->setCategory($categoryzeta);
$expectedxml = file_get_contents(__DIR__ . '/fixtures/nested_categories.xml');
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
}
/**
* Check exporting nested categories contain the right questions.
*/
public function test_export_nested_categories_with_questions(): void {
global $SITE;
$this->resetAfterTest();
$this->setAdminUser();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$qformat = $this->create_qformat('nested_categories_with_questions.xml', $SITE);
$categoryiota = $generator->create_question_category([
'name' => 'Iota',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Iota category for test',
'infoformat' => '2',
'stamp' => make_unique_id_code(),
'parent' => '0',
'sortorder' => '999']);
$iotaquestion = $generator->create_question('truefalse', null, [
'category' => $categoryiota->id,
'name' => 'Iota Question',
'questiontext' => [
'format' => '1',
'text' => '<p>Testing Iota Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$categorykappa = $generator->create_question_category([
'name' => 'Kappa',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Kappa category for test',
'infoformat' => '4',
'stamp' => make_unique_id_code(),
'parent' => $categoryiota->id,
'sortorder' => '999']);
$kappaquestion = $generator->create_question('essay', null, [
'category' => $categorykappa->id,
'name' => 'Kappa Essay Question',
'questiontext' => ['text' => 'Testing Kappa Essay Question'],
'generalfeedback' => '',
'responseformat' => 'editor',
'responserequired' => 1,
'responsefieldlines' => 10,
'attachments' => 0,
'attachmentsrequired' => 0,
'graderinfo' => ['format' => '1', 'text' => ''],
'responsetemplate' => ['format' => '1', 'text' => ''],
'idnumber' => '']);
$kappaquestion1 = $generator->create_question('truefalse', null, [
'category' => $categorykappa->id,
'name' => 'Kappa Question',
'questiontext' => [
'format' => '1',
'text' => '<p>Testing Kappa Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1',
'idnumber' => '']);
$categorylambda = $generator->create_question_category([
'name' => 'Lambda',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Lambda category for test',
'infoformat' => '0',
'stamp' => make_unique_id_code(),
'parent' => $categorykappa->id,
'sortorder' => '999']);
$lambdaquestion = $generator->create_question('truefalse', null, [
'category' => $categorylambda->id,
'name' => 'Lambda Question',
'questiontext' => [
'format' => '1',
'text' => '<p>Testing Lambda Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$categorymu = $generator->create_question_category([
'name' => 'Mu',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Mu category for test',
'infoformat' => '0',
'stamp' => make_unique_id_code(),
'parent' => $categoryiota->id,
'sortorder' => '999']);
$muquestion = $generator->create_question('truefalse', null, [
'category' => $categorymu->id,
'name' => 'Mu Question',
'questiontext' => [
'format' => '1',
'text' => '<p>Testing Mu Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$qformat->setCategory($categoryiota);
$expectedxml = file_get_contents(__DIR__ . '/fixtures/nested_categories_with_questions.xml');
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
}
/**
* Simple check for exporting a category.
*/
public function test_export_category_with_special_chars(): void {
global $SITE;
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$this->resetAfterTest();
$this->setAdminUser();
// Note while this loads $qformat with all the 'right' data from the xml file,
// the call to setCategory, followed by exportprocess will actually only export data
// from the database (created by the generator).
$qformat = $this->create_qformat('export_category.xml', $SITE);
$category = $generator->create_question_category([
'name' => 'Alpha',
'contextid' => context_course::instance($SITE->id)->id,
'info' => 'This is Alpha category for test',
'infoformat' => '0',
'idnumber' => 'The inequalities < & >',
'stamp' => make_unique_id_code(),
'parent' => '0',
'sortorder' => '999']);
$generator->create_question('truefalse', null, [
'category' => $category->id,
'name' => 'Alpha Question',
'questiontext' => ['format' => '1', 'text' => '<p>Testing Alpha Question</p>'],
'generalfeedback' => ['format' => '1', 'text' => ''],
'idnumber' => 'T & F',
'correctanswer' => '1',
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1']);
$qformat->setCategory($category);
$expectedxml = file_get_contents(__DIR__ . '/fixtures/html_chars_in_idnumbers.xml');
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
}
/**
* Test that bad multianswer questions are not imported.
*/
public function test_import_broken_multianswer_questions(): void {
$lines = file(__DIR__ . '/fixtures/broken_cloze_questions.xml');
$importer = $qformat = new qformat_xml();
// The importer echoes some errors, so we need to capture and check that.
ob_start();
$questions = $importer->readquestions($lines);
$output = ob_get_contents();
ob_end_clean();
// Check that there were some expected errors.
$this->assertStringContainsString('Error importing question', $output);
$this->assertStringContainsString('Invalid embedded answers (Cloze) question', $output);
$this->assertStringContainsString('This type of question requires at least 2 choices', $output);
$this->assertStringContainsString('The answer must be a number, for example -1.234 or 3e8, or \'*\'.', $output);
$this->assertStringContainsString('One of the answers should have a score of 100% so it is possible to get full marks for this question.',
$output);
$this->assertStringContainsString('The question text must include at least one embedded answer.', $output);
// No question have been imported.
$this->assertCount(0, $questions);
}
}
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for the calculated question type.
*
* @package qformat_xml
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qformat_xml';
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->maturity = MATURITY_STABLE;