MDL-84736 behat: add custom step to edit a criterion

This commit also improves the existing tests and add a new scenario to
verify the 'Do not mark for regrade' behavior.
This commit is contained in:
Simey Lameze
2025-12-09 17:20:43 +08:00
parent e5be425a9a
commit f2bdb3ff23
2 changed files with 97 additions and 35 deletions
@@ -97,6 +97,55 @@ class behat_gradingform_guide extends behat_base {
}
}
/**
* Edits an existing marking guide with the provided data.
*
* This method edits the marking guide of the marking guide definition
* form; the provided TableNode should contain one row for
* each field and each cell of the row should contain:
* | Field name | New value |
* | shortname | Updated Grade criterion |
*
* @When /^I edit the marking guide criterion "([^"]*)" with the following values:$/
* @param string $criterionname
* @param TableNode $fields
*/
public function i_edit_the_marking_guide_criterion_with_the_following_values(string $criterionname, TableNode $fields) {
if ($fieldvalues = $fields->getHash()) {
$criterionid = 0;
$locator = "//tr[contains(@class, 'criterion')]//div[@class='criterionname']"
. "//span[@class='textvalue'][text()='$criterionname']/ancestor::tr";
if ($criterionrow = $this->find('xpath', $locator)) {
$criterionid = str_replace('guide-criteria-', '', $criterionrow->getAttribute('id'));
}
if ($criterionid) {
$criterionroot = 'guide[criteria]' . '[' . $criterionid . ']';
foreach ($fieldvalues as $fieldvalue) {
// Make sure the fieldvalue array has 2 elements.
if (count($fieldvalue) != 2) {
throw new ExpectationException(
'The field definition should contain field name and new value. ' .
'Please follow this format: | Field name | New value |',
$this->getSession()
);
}
$fieldname = $fieldvalue['Field name'];
$newvalue = $fieldvalue['New value'];
$this->set_guide_field_value($criterionroot . "[$fieldname]", $newvalue);
}
} else {
throw new ExpectationException(
'Criterion with name "' . $criterionname . '" not found.',
$this->getSession()
);
}
}
}
/**
* Defines the marking guide with the provided data, following marking guide's definition grid cells.
*
@@ -1,5 +1,5 @@
@gradingform @gradingform_guide
Feature: Marking guide details can be updated for activity with graded submissions
Feature: Editing a marking guide already used for grading updates regrade state and student visible grades
In order to update marking guide details
As a teacher
I need to be able to grade a submission
@@ -17,13 +17,12 @@ Feature: Marking guide details can be updated for activity with graded submissio
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | name | advancedgradingmethod_submissions | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled | assignfeedback_comments_commentinline | assignfeedback_comments_enabled |
| assign | C1 | Assign 1 | guide | 1 | 0 | 1 | 1 |
| activity | course | name | advancedgradingmethod_submissions | assignsubmission_onlinetext_enabled |
| assign | C1 | Assign 1 | guide | 1 |
And the following "mod_assign > submissions" exist:
| assign | user | onlinetext |
| Assign 1 | student1 | Assign 1 submission |
And I am on the "Course 1" course page logged in as teacher1
And I change window size to "large"
And I go to "Assign 1" advanced grading definition page
And I set the following fields to these values:
| Name | Assign 1 marking guide |
@@ -32,42 +31,56 @@ Feature: Marking guide details can be updated for activity with graded submissio
| Criterion name | Description for students | Description for markers | Maximum score |
| Grade criterion A | Grade 1 description for students | Grade 1 description for markers | 70 |
| Grade criterion B | Grade 2 description for students | Grade 2 description for markers | 30 |
And I define the following frequently used comments:
| Comment 1 |
| Comment 2 |
| Comment 3 |
And I press "Save marking guide and make it ready"
@javascript
Scenario: Teacher can update marking guide details for activity with graded submissions
Given I navigate to "Assignment" in current page administration
And I navigate to "Assignment" in current page administration
And I go to "Student One" "Assign 1" activity advanced grading page
And I grade by filling the marking guide with:
| Grade criterion A | 25 | Needs improvement |
| Grade criterion B | 20 | Excellent! |
# Inserting frequently used comment.
And I click on "Insert frequently used comment" "button" in the "Grade criterion A" "table_row"
And I wait "1" seconds
And I press "Comment 1"
And I wait "1" seconds
And I click on "Insert frequently used comment" "button" in the "Grade criterion B" "table_row"
And I wait "1" seconds
And I press "Comment 2"
And I wait "1" seconds
And I press "Save changes"
When I am on "Course 1" course homepage
And I am on "Course 1" course homepage
And I go to "Assign 1" advanced grading definition page
# And I set the field "Grade criterion A" to "Criteria 1"
# And I set the field "guide[criteria][477000][shortname]" to "Criteria 1"
# And I set the following fields to these values:
# | Criterion name | Description for students | Description for markers | Maximum score |
# | Criteria 1 | Criteria 1 student | Criteria 1 marker | 40 |
# | Criteria 2 | Criteria 2 student | Criteria 2 marker | 70 |
And I click on "Move down" "button" in the "Comment 1" "table_row"
And I click on "Move up" "button" in the "Comment 3" "table_row"
And I edit the marking guide criterion "Grade criterion A" with the following values:
| Field name | New value |
| shortname | Updated Grade criterion A |
| description | Updated description for students |
| descriptionmarkers | Updated description for markers |
| maxscore | 60 |
And I press "Save"
# Remove after testing
Then the following should exist in the "guide-comments" table:
| Comment 2 |
| Comment 3 |
| Comment 1 |
@javascript
Scenario: Teacher edits a used marking guide and mark it for regrade and student sees breakdown only after teacher regrades
# Set the marking guide to be "Mark for regrade".
Given I set the field "menuguideregrade" to "Mark for regrade"
And I should see "You are about to save changes to a marking guide that has already been used for grading. Please indicate if existing grades need to be reviewed. If you set this then the marking guide will be hidden from students until their item is regraded."
And I click on "Continue" "button"
And I am on the "Assign 1" "assign activity" page logged in as student1
# Student should not see the grade breakdown as the activity is marked for regrade.
And I should not see "Grade breakdown"
When I am on the "Assign 1" "assign activity" page logged in as teacher1
And I go to "Student One" "Assign 1" activity advanced grading page
And I grade by filling the marking guide with:
| Updated Grade criterion A | 50 | I changed my mind |
| Grade criterion B | 30 | It's all good now |
And I press "Save changes"
And I am on the "Assign 1" "assign activity" page logged in as student1
# Now the student should see the updated grade breakdown.
Then I should see "Grade breakdown"
And I should see the marking guide information displayed as:
| criteria | description | remark | maxscore | criteriascore |
| Updated Grade criterion A | Updated description for students | I changed my mind | 60 | 50 / 60 |
| Grade criterion B | Grade 2 description for students | It's all good now | 30 | 30 / 30 |
@javascript
Scenario: Teacher edits a used marking guide does not mark for regrade existing student grades remain visible and unchanged
# Set the marking guide to be "Do not mark for regrade".
Given I set the field "menuguideregrade" to "Do not mark for regrade"
And I should see "You are about to save changes to a marking guide that has already been used for grading. Please indicate if existing grades need to be reviewed. If you set this then the marking guide will be hidden from students until their item is regraded."
And I click on "Continue" "button"
When I am on the "Assign 1" "assign activity" page logged in as student1
# Student should see the updated grade breakdown as the activity was not marked for regrading.
Then I should see "Grade breakdown"
And I should see the marking guide information displayed as:
| criteria | description | remark | maxscore | criteriascore |
| Updated Grade criterion A | Updated description for students | Needs improvement | 60 | 25 / 60 |
| Grade criterion B | Grade 2 description for students | Excellent! | 30 | 20 / 30 |