Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behat tests and the display of completion conditions (4.3 variant) #100

Open
wants to merge 2 commits into
base: MOODLE_403_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function get_state(string $rule): int {
// Check if the referenced course is completed.
$coursecompletion = new \completion_completion(['userid' => $this->userid, 'course' => $subcourse->refcourse]);

return $coursecompletion->is_complete();
return $coursecompletion->is_complete() ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}

/**
Expand All @@ -78,6 +78,10 @@ public function get_custom_rule_descriptions(): array {
* @return array
*/
public function get_sort_order(): array {
return ['completioncourse'];
return [
'completionview',
'completionusegrade',
'completioncourse',
];
}
}
9 changes: 7 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ function subcourse_get_coursemodule_info($coursemodule) {
global $CFG, $DB;

$subcourse = $DB->get_record('subcourse', ['id' => $coursemodule->instance],
'id, name, intro, introformat, instantredirect, blankwindow, coursepageprintgrade, coursepageprintprogress');
'id, name, intro, introformat, instantredirect, blankwindow, coursepageprintgrade, coursepageprintprogress, ' .
'completioncourse');

if (!$subcourse) {
return null;
Expand All @@ -387,6 +388,10 @@ function subcourse_get_coursemodule_info($coursemodule) {
$info->content = format_module_intro('subcourse', $subcourse, $coursemodule->id, false);
}

if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$info->customdata->customcompletionrules['completioncourse'] = $subcourse->completioncourse;
}

return $info;
}

Expand Down Expand Up @@ -433,7 +438,7 @@ function subcourse_update_grades($subcourse, $userid=0, $nullifnone=true) {
// Prevent empty referenced course id coding error.
return GRADE_UPDATE_FAILED;
}

if ($refgrades && $refgrades->grades) {
if (!empty($refgrades->localremotescale)) {
// Unable to fetch remote grades - local scale is used in the remote course.
Expand Down
13 changes: 4 additions & 9 deletions tests/behat/auto_fetch_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ Feature: Grades are fetched automatically from the referenced course
And I log in as "teacher1"
And I am on "RefCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on "Edit" "link" in the "RefCourse" "table_row"
And I click on "Edit settings" "link" in the "RefCourse" "table_row"
And I set the following fields to these values:
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
| Aggregation | Mean of grades |
| Maximum grade | 1000 |
And I press "Save changes"
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
| Maximum grade | 200 |
And I press "Save changes"
And the following "grade items" exist:
| itemname | grademax | course |
| Manual item 1 | 200 | R |
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "100" to the user "Student 1" for the grade item "Manual item 1"
Expand Down
9 changes: 4 additions & 5 deletions tests/behat/completion_course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Feature: Completing the referenced course can lead to completing the subcourse a
| Subcourse name | Unit course 1 |
| Fetch grades from | RefCourse (R) |
| Redirect to the referenced course | 0 |
| Completion tracking | Show activity as complete when conditions are met |
| Require view | 0 |
| Add requirements | 1 |
| View the activity | 0 |
| Require course completed | 1 |
| id_completionexpected_enabled | 1 |
# Add the block to a the referenced course to allow students to manually complete it
Expand Down Expand Up @@ -56,9 +56,8 @@ Feature: Completing the referenced course can lead to completing the subcourse a
And I wait "1" seconds
When I run the scheduled task "core\task\completion_regular_task"
And I am on "MainCourse" course homepage
Then the "Complete the activity" completion condition of "Unit course 1" is displayed as "done"
Then the "Require course completed" completion condition of "Unit course 1" is displayed as "done"
And I log out
And I log in as "teacher1"
And I am on "MainCourse" course homepage
And I navigate to "Reports > Activity completion" in current page administration
And "//img[contains(@title, 'Unit course 1') and contains(@title, 'Completed')]" "xpath_element" should exist in the "Student 1" "table_row"
And "Student 1" user has completed "Unit course 1" activity
9 changes: 4 additions & 5 deletions tests/behat/course_page_display.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ Feature: Progress and grade in referenced course can be displayed on the course
And I turn editing mode on
And I add a "Text and media area" to section "1" and I fill the form with:
| Text | Just a simple module to activate progress tracking |
| Students must manually mark the activity as done | 1 |
And I turn editing mode off
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
| Maximum grade | 10 |
And I press "Save changes"
And the following "grade items" exist:
| itemname | grademax | course |
| Manual item 1 | 10 | R |
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "5" to the user "Student 1" for the grade item "Manual item 1"
Expand Down
70 changes: 30 additions & 40 deletions tests/behat/fetch_percentage_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,14 @@ Feature: Grades can be fetched either a real values or as percentages
And I log in as "teacher1"
And I am on "RefCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I set the following settings for grade item "RefCourse":
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
| Aggregation | Natural |
| Exclude empty grades | 1 |
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
| Maximum grade | 10 |
And I press "Save changes"
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 2 |
| Maximum grade | 10 |
And I press "Save changes"
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 3 |
| Maximum grade | 10 |
And I press "Save changes"
And the following "grade items" exist:
| itemname | grademax | course |
| Manual item 1 | 10 | R |
| Manual item 2 | 10 | R |
| Manual item 3 | 10 | R |
And I navigate to "Setup > Course grade settings" in the course gradebook
And I set the field "Grade display type" to "Real (percentage)"
#
Expand Down Expand Up @@ -107,12 +97,12 @@ Feature: Grades can be fetched either a real values or as percentages
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode off
And the following should exist in the "user-grades" table:
| Email address | -7- |
| [email protected] | 20.00 (66.67 %) |
| [email protected] | 20.00 (100.00 %) |
| [email protected] | 15.00 (75.00 %) |
| [email protected] | 0.00 (0.00 %) |
| [email protected] | - |
| -1- | -2- | -6- |
| Student 1 | [email protected] | 20.00 (66.67 %) |
| Student 2 | [email protected] | 20.00 (100.00 %) |
| Student 3 | [email protected] | 15.00 (75.00 %) |
| Student 4 | [email protected] | 0.00 (0.00 %) |
| Student 5 | [email protected] | - |

@javascript
Scenario: Grades are fetched as real values by default
Expand All @@ -125,9 +115,9 @@ Feature: Grades can be fetched either a real values or as percentages
And I turn editing mode off
And I am on "MainCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on "Edit" "link" in the "Unit course 1" "table_row"
And I click on "Edit settings" "link" in the "Unit course 1" "table_row"
And I click on "Show more..." "link"
And I click on grade item menu "Unit course 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I click on "Show more..." "link" in the "Edit grade item" "dialogue"
And I set the following fields to these values:
| Grade display type | Real (percentage) |
And I press "Save changes"
Expand All @@ -137,12 +127,12 @@ Feature: Grades can be fetched either a real values or as percentages
And I am on "MainCourse" course homepage
And I navigate to "View > Grader report" in the course gradebook
Then the following should exist in the "user-grades" table:
| Email address | -4- |
| [email protected] | 20.00 (66.67 %) |
| [email protected] | 20.00 (66.67 %) |
| [email protected] | 15.00 (50.00 %) |
| [email protected] | 0.00 (0.00 %) |
| [email protected] | - |
| -1- | -2- | -3- |
| Student 1 | [email protected] | 20.00 (66.67 %) |
| Student 2 | [email protected] | 20.00 (66.67 %) |
| Student 3 | [email protected] | 15.00 (50.00 %) |
| Student 4 | [email protected] | 0.00 (0.00 %) |
| Student 5 | [email protected] | - |

@javascript
Scenario: Grades can be fetched as percentual values
Expand All @@ -156,9 +146,9 @@ Feature: Grades can be fetched either a real values or as percentages
And I turn editing mode off
And I am on "MainCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on "Edit" "link" in the "Unit course 1" "table_row"
And I click on "Edit settings" "link" in the "Unit course 1" "table_row"
And I click on "Show more..." "link"
And I click on grade item menu "Unit course 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I click on "Show more..." "link" in the "Edit grade item" "dialogue"
And I set the following fields to these values:
| Grade display type | Real (percentage) |
And I press "Save changes"
Expand All @@ -168,9 +158,9 @@ Feature: Grades can be fetched either a real values or as percentages
And I am on the "MainCourse" course page logged in as "teacher1"
And I navigate to "View > Grader report" in the course gradebook
Then the following should exist in the "user-grades" table:
| Email address | -4- |
| [email protected] | 20.00 (66.67 %) |
| [email protected] | 30.00 (100.00 %) |
| [email protected] | 22.50 (75.00 %) |
| [email protected] | 0.00 (0.00 %) |
| [email protected] | - |
| -1- | -2- | -3- |
| Student 1 | [email protected] | 20.00 (66.67 %) |
| Student 2 | [email protected] | 30.00 (100.00 %) |
| Student 3 | [email protected] | 22.50 (75.00 %) |
| Student 4 | [email protected] | 0.00 (0.00 %) |
| Student 5 | [email protected] | - |
31 changes: 14 additions & 17 deletions tests/behat/hidden_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
And I log in as "teacher1"
And I am on "RefCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
| Maximum grade | 10 |
And I press "Save changes"
And the following "grade items" exist:
| itemname | grademax | course |
| Manual item 1 | 10 | R |
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "5" to the user "Student 1" for the grade item "Manual item 1"
And I give the grade "8" to the user "Student 2" for the grade item "Manual item 1"
And I press "Save"
And I follow "Change to aggregates only"
And I click on "Edit grade" "link" in the "Student 1" "table_row"
And I set the following fields to these values:
| Hidden | 1 |
And I press "Save changes"
And I click on grade item menu "RefCourse" of type "course" on "grader" page
And I choose "Show totals only" in the open action menu
And I click on "Course total" "core_grades > grade_actions" in the "Student 1" "table_row"
And I choose "Hide" in the open action menu
And I turn editing mode off

@javascript
Expand All @@ -60,9 +57,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
And I am on "MainCourse" course homepage
And I navigate to "View > Grader report" in the course gradebook
Then the following should exist in the "user-grades" table:
| Email address | -4- |
| [email protected] | 5.00 |
| [email protected] | 8.00 |
| -1- | -2- | -3- |
| Student 1 | [email protected] | 5.00 |
| Student 2 | [email protected] | 8.00 |
And I log out
#
# Student 1 should not see the grade in the referenced course.
Expand All @@ -88,7 +85,7 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
Scenario: If the whole course final grade item is hidden, the associated subcourse activity grade item is marked as hidden, too.
Given I am on "RefCourse" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I set the following settings for grade item "RefCourse":
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
| Hidden | 1 |
And I am on "MainCourse" course homepage
And I turn editing mode on
Expand All @@ -103,9 +100,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
And I am on "MainCourse" course homepage
And I navigate to "View > Grader report" in the course gradebook
Then the following should exist in the "user-grades" table:
| Email address | -4- |
| [email protected] | 5.00 |
| [email protected] | 8.00 |
| -1- | -2- | -3- |
| Student 1 | [email protected] | 5.00 |
| Student 2 | [email protected] | 8.00 |
And I log out
#
# Student 1 should not see the grade in the referenced course.
Expand Down