mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 05:28:30 +01:00
MDL-76317 questions: improve error message when importing invalid grades
This commit is contained in:
parent
c895def59b
commit
1ed6318d13
@ -218,6 +218,7 @@ $string['invalidcategoryidtomove'] = 'Invalid category id to move!';
|
||||
$string['invalidconfirm'] = 'Confirmation string was incorrect';
|
||||
$string['invalidcontextinhasanyquestions'] = 'Invalid context passed to question_context_has_any_questions.';
|
||||
$string['invalidgrade'] = 'Grades ({$a}) do not match grade options - question skipped.';
|
||||
$string['invalidgradequestion'] = 'Grades ({$a->grades}) do not match grade options - question \'{$a->question}\' skipped.';
|
||||
$string['invalidpenalty'] = 'Invalid penalty';
|
||||
$string['invalidwizardpage'] = 'Incorrect or no wizard page specified!';
|
||||
$string['lastmodifiedby'] = 'Last modified by';
|
||||
|
@ -388,8 +388,8 @@ class qformat_default {
|
||||
}
|
||||
}
|
||||
if ($invalidfractions) {
|
||||
echo $OUTPUT->notification(get_string('invalidgrade', 'question',
|
||||
implode(', ', $invalidfractions)));
|
||||
$a = ['grades' => implode(', ', $invalidfractions), 'question' => $question->name];
|
||||
echo $OUTPUT->notification(get_string('invalidgradequestion', 'question', $a));
|
||||
++$gradeerrors;
|
||||
continue;
|
||||
} else {
|
||||
|
63
question/format/xml/tests/fixtures/error_invalid_grades.xml
vendored
Normal file
63
question/format/xml/tests/fixtures/error_invalid_grades.xml
vendored
Normal file
@ -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>
|
@ -235,6 +235,31 @@ class qformat_xml_import_export_test extends advanced_testcase {
|
||||
$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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user