Skip to content

Commit

Permalink
Merge branch 'MDL-74613-400' of https://github.com/NoelDeMartin/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_400_STABLE
  • Loading branch information
andrewnicols committed Jun 30, 2022
2 parents 64fa293 + 582f1bc commit 787fee7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 21 deletions.
45 changes: 24 additions & 21 deletions grade/report/grader/tests/behat/switch_views.feature
Expand Up @@ -12,7 +12,7 @@ Feature: We can change what we are viewing on the grader report
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 1 | student2@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Expand All @@ -26,18 +26,15 @@ Feature: We can change what we are viewing on the grader report
| assign | user | onlinetext |
| Test assignment name 1 | student1 | This is a submission for assignment 1 |
| Test assignment name 2 | student1 | This is a submission for assignment 2 |
And I am on the "Test assignment name 1" "assign activity" page logged in as student1
Then I should see "Submitted for grading"
And I am on the "Test assignment name 2" "assign activity" page
Then I should see "Submitted for grading"
And I log out
And the following "grade items" exist:
| itemname | grademin | grademax | course |
| Manual grade | 20 | 40 | C1 |
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assignment name 1 | student1 | 80 |
| Test assignment name 2 | student1 | 90 |
| Manual grade | student1 | 30 |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment name 1"
And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment name 2"
And I press "Save changes"

@javascript
Scenario: View and minimise the grader report containing hidden activities
Expand All @@ -48,24 +45,27 @@ Feature: We can change what we are viewing on the grader report
And I navigate to "View > Grader report" in the course gradebook
And I should see "Test assignment name 1"
And I should see "Test assignment name 2"
And I should see "Manual grade"
And I should see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- | -5- | -6- |
| Student 1 | 80 | 90 | 170 |
| -1- | -4- | -5- | -6- | -7- |
| Student 1 | 80 | 90 | 30 | 170 |
And I click on "Change to aggregates only" "link"
And I should not see "Test assignment name 1"
And I should not see "Test assignment name 2"
And I should not see "Manual grade"
And I should see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- |
| Student 1 | 170 |
And I click on "Change to grades only" "link"
And I should see "Test assignment name 1"
And I should see "Test assignment name 2"
And I should see "Manual grade"
And I should not see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- | -5- |
| Student 1 | 80 | 90 |
| -1- | -4- | -5- | -6- |
| Student 1 | 80 | 90 | 30 |

@javascript @skip_chrome_zerosize
Scenario: View and minimise the grader report containing hidden activities without the 'moodle/grade:viewhidden' capability
Expand All @@ -83,21 +83,24 @@ Feature: We can change what we are viewing on the grader report
And I navigate to "View > Grader report" in the course gradebook
And I should see "Test assignment name 1"
And I should see "Test assignment name 2"
And I should see "Manual grade"
And I should see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- | -5- | -6- |
| Student 1 | 80 | - | 80 |
| -1- | -4- | -5- | -6- | -7- |
| Student 1 | 80 | - | 30 | 105.71 |
And I click on "Change to aggregates only" "link"
And I should not see "Test assignment name 1"
And I should not see "Test assignment name 2"
And I should not see "Manual grade"
And I should see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- |
| Student 1 | 80 |
| Student 1 | 105.71 |
And I click on "Change to grades only" "link"
And I should see "Test assignment name 1"
And I should see "Test assignment name 2"
And I should see "Manual grade"
And I should not see "Course total"
And the following should exist in the "user-grades" table:
| -1- | -4- | -5- |
| Student 1 | 80 | - |
| -1- | -4- | -5- | -6- |
| Student 1 | 80 | - | 30 |
22 changes: 22 additions & 0 deletions lib/behat/classes/behat_core_generator.php
Expand Up @@ -162,6 +162,12 @@ protected function get_creatable_entities(): array {
'required' => ['fullname', 'course'],
'switchids' => ['course' => 'courseid', 'gradecategory' => 'parent'],
],
'grade grades' => [
'singular' => 'grade grade',
'datagenerator' => 'grade_grade',
'required' => ['gradeitem'],
'switchids' => ['user' => 'userid', 'gradeitem' => 'itemid'],
],
'grade items' => [
'singular' => 'grade item',
'datagenerator' => 'grade_item',
Expand Down Expand Up @@ -298,6 +304,22 @@ protected function get_creatable_entities(): array {
return $entities;
}

/**
* Get the grade item id using a name.
*
* @param string $name
* @return int The grade item id
*/
protected function get_gradeitem_id(string $name): int {
global $DB;

if (!$id = $DB->get_field('grade_items', 'id', ['itemname' => $name])) {
throw new Exception('The specified grade item with name "' . $name . '" could not be found.');
}

return $id;
}

/**
* Remove any empty custom fields, to avoid errors when creating the course.
*
Expand Down
51 changes: 51 additions & 0 deletions lib/testing/generator/data_generator.php
Expand Up @@ -1010,6 +1010,57 @@ public function create_grade_category($record = null) {
return $gradecategory->get_record_data();
}

/**
* Create a grade_grade.
*
* @param array $record
* @return grade_grade the grade record
*/
public function create_grade_grade(?array $record = null): grade_grade {
global $DB, $USER;

$item = $DB->get_record('grade_items', ['id' => $record['itemid']]);
$userid = $record['userid'] ?? $USER->id;

unset($record['itemid']);
unset($record['userid']);

if ($item->itemtype === 'mod') {
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance);
$module = new $item->itemmodule(context_module::instance($cm->id), $cm, false);
$record['attemptnumber'] = $record['attemptnumber'] ?? 0;

$module->save_grade($userid, (object) $record);

$grade = grade_grade::fetch(['userid' => $userid, 'itemid' => $item->id]);
} else {
$grade = grade_grade::fetch(['userid' => $userid, 'itemid' => $item->id]);
$record['rawgrade'] = $record['rawgrade'] ?? $record['grade'] ?? null;
$record['finalgrade'] = $record['finalgrade'] ?? $record['grade'] ?? null;

unset($record['grade']);

if ($grade) {
$fields = $grade->required_fields + array_keys($grade->optional_fields);

foreach ($fields as $field) {
$grade->{$field} = $record[$field] ?? $grade->{$field};
}

$grade->update();
} else {
$record['userid'] = $userid;
$record['itemid'] = $item->id;

$grade = new grade_grade($record, false);

$grade->insert();
}
}

return $grade;
}

/**
* Create a grade_item.
*
Expand Down

0 comments on commit 787fee7

Please sign in to comment.