Skip to content

Commit

Permalink
MDL-83615 gradebook: improve xml import error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jboulen committed Nov 13, 2024
1 parent 2b337b4 commit e5b892f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions grade/import/xml/lang/en/gradeimport_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['errbadgrade'] = 'Supplied grade (\'{$a->badgrade}\') is invalid for user with ID number {$a->useridnumber}.';
$string['errbadxmlformat'] = 'Error - bad XML format';
$string['errduplicategradeidnumber'] = 'Error - there are two grade items with idnumber \'{$a}\' in this course. This should be impossible.';
$string['errduplicateidnumber'] = 'Error - duplicate idnumber';
Expand Down
5 changes: 4 additions & 1 deletion grade/import/xml/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ function import_xml_grades($text, $course, &$error) {
$newgrade->finalgrade = $result['#']['score'][0]['#'];
} else {
$status = false;
$error = get_string('badgrade', 'grades');
$error = get_string('errbadgrade', 'gradeimport_xml', [
'badgrade' => $result['#']['score'][0]['#'],
'useridnumber' => $useridnumber,
]);
break;
}
} else {
Expand Down
24 changes: 16 additions & 8 deletions grade/tests/behat/grade_import.feature
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@core @core_grades @javascript @_file_upload
Feature: An admin can import grades into gradebook using a CSV file
In order to import grades using a CSV file
Feature: An admin can import grades into gradebook using a CSV or XML file
In order to import grades using a CSV or XML file
As a teacher
I need to be able to upload a CSV file and see uploaded grades in gradebook
I need to be able to upload a CSV or XML file and see uploaded grades in gradebook

Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | |
| student1 | Student | 1 | student1@example.com | 1000 |
| student2 | Student | 2 | student2@example.com | 2000 |
| student3 | Student | 3 | student3@example.com | 3000 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Expand All @@ -23,6 +23,7 @@ Feature: An admin can import grades into gradebook using a CSV file
And the following "grade item" exists:
| course | C1 |
| itemname | Manual item 1 |
| idnumber | item1 |
| grademin | 10 |
| grademax | 500 |
And the following "grade grades" exist:
Expand Down Expand Up @@ -66,6 +67,13 @@ Feature: An admin can import grades into gradebook using a CSV file
| Student 2 | student2@example.com | 50.00 | 50.00 |
| Student 3 | student3@example.com | 50.00 | 50.00 |

Scenario: Importing grades with an invalid grade
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And I navigate to "XML file" import page in the course gradebook
And I upload "grade/tests/fixtures/grade_import_bad_grade.xml" file to "File" filemanager
When I click on "Upload grades" "button"
Then I should see "Supplied grade ('A') is invalid for user with ID number 2000."

Scenario: Importing grades with multiple new mappings
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And I navigate to "CSV file" import page in the course gradebook
Expand Down
17 changes: 17 additions & 0 deletions grade/tests/fixtures/grade_import_bad_grade.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<results batch="xml_export_1731515757">
<result>
<assignment>item1</assignment>
<student>1000</student>
<score>50.00</score>
</result>
<result>
<assignment>item1</assignment>
<student>2000</student>
<score>A</score>
</result>
<result>
<assignment>item1</assignment>
<student>3000</student>
<score>50.00</score>
</result>
</results>

0 comments on commit e5b892f

Please sign in to comment.