Skip to content

Commit 9047553

Browse files
authored
Merge pull request #100 from usqfowlerj/combo_403
Fix behat tests and the display of completion conditions (4.3 variant)
2 parents 64d2a0f + 5bdb84a commit 9047553

File tree

7 files changed

+69
-80
lines changed

7 files changed

+69
-80
lines changed

classes/completion/custom_completion.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function get_state(string $rule): int {
5454
// Check if the referenced course is completed.
5555
$coursecompletion = new \completion_completion(['userid' => $this->userid, 'course' => $subcourse->refcourse]);
5656

57-
return $coursecompletion->is_complete();
57+
return $coursecompletion->is_complete() ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
5858
}
5959

6060
/**
@@ -78,6 +78,10 @@ public function get_custom_rule_descriptions(): array {
7878
* @return array
7979
*/
8080
public function get_sort_order(): array {
81-
return ['completioncourse'];
81+
return [
82+
'completionview',
83+
'completionusegrade',
84+
'completioncourse',
85+
];
8286
}
8387
}

lib.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ function subcourse_get_coursemodule_info($coursemodule) {
364364
global $CFG, $DB;
365365

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

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

391+
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
392+
$info->customdata->customcompletionrules['completioncourse'] = $subcourse->completioncourse;
393+
}
394+
390395
return $info;
391396
}
392397

@@ -433,7 +438,7 @@ function subcourse_update_grades($subcourse, $userid=0, $nullifnone=true) {
433438
// Prevent empty referenced course id coding error.
434439
return GRADE_UPDATE_FAILED;
435440
}
436-
441+
437442
if ($refgrades && $refgrades->grades) {
438443
if (!empty($refgrades->localremotescale)) {
439444
// Unable to fetch remote grades - local scale is used in the remote course.

tests/behat/auto_fetch_grades.feature

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,12 @@ Feature: Grades are fetched automatically from the referenced course
3535
And I log in as "teacher1"
3636
And I am on "RefCourse" course homepage
3737
And I navigate to "Setup > Gradebook setup" in the course gradebook
38-
And I click on "Edit" "link" in the "RefCourse" "table_row"
39-
And I click on "Edit settings" "link" in the "RefCourse" "table_row"
40-
And I set the following fields to these values:
38+
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
4139
| Aggregation | Mean of grades |
4240
| Maximum grade | 1000 |
43-
And I press "Save changes"
44-
And I press "Add grade item"
45-
And I set the following fields to these values:
46-
| Item name | Manual item 1 |
47-
| Maximum grade | 200 |
48-
And I press "Save changes"
41+
And the following "grade items" exist:
42+
| itemname | grademax | course |
43+
| Manual item 1 | 200 | R |
4944
And I navigate to "View > Grader report" in the course gradebook
5045
And I turn editing mode on
5146
And I give the grade "100" to the user "Student 1" for the grade item "Manual item 1"

tests/behat/completion_course.feature

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Feature: Completing the referenced course can lead to completing the subcourse a
2727
| Subcourse name | Unit course 1 |
2828
| Fetch grades from | RefCourse (R) |
2929
| Redirect to the referenced course | 0 |
30-
| Completion tracking | Show activity as complete when conditions are met |
31-
| Require view | 0 |
30+
| Add requirements | 1 |
31+
| View the activity | 0 |
3232
| Require course completed | 1 |
3333
| id_completionexpected_enabled | 1 |
3434
# Add the block to a the referenced course to allow students to manually complete it
@@ -56,9 +56,8 @@ Feature: Completing the referenced course can lead to completing the subcourse a
5656
And I wait "1" seconds
5757
When I run the scheduled task "core\task\completion_regular_task"
5858
And I am on "MainCourse" course homepage
59-
Then the "Complete the activity" completion condition of "Unit course 1" is displayed as "done"
59+
Then the "Require course completed" completion condition of "Unit course 1" is displayed as "done"
6060
And I log out
6161
And I log in as "teacher1"
6262
And I am on "MainCourse" course homepage
63-
And I navigate to "Reports > Activity completion" in current page administration
64-
And "//img[contains(@title, 'Unit course 1') and contains(@title, 'Completed')]" "xpath_element" should exist in the "Student 1" "table_row"
63+
And "Student 1" user has completed "Unit course 1" activity

tests/behat/course_page_display.feature

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ Feature: Progress and grade in referenced course can be displayed on the course
3131
And I turn editing mode on
3232
And I add a "Text and media area" to section "1" and I fill the form with:
3333
| Text | Just a simple module to activate progress tracking |
34+
| Students must manually mark the activity as done | 1 |
3435
And I turn editing mode off
3536
And I navigate to "Setup > Gradebook setup" in the course gradebook
36-
And I press "Add grade item"
37-
And I set the following fields to these values:
38-
| Item name | Manual item 1 |
39-
| Maximum grade | 10 |
40-
And I press "Save changes"
37+
And the following "grade items" exist:
38+
| itemname | grademax | course |
39+
| Manual item 1 | 10 | R |
4140
And I navigate to "View > Grader report" in the course gradebook
4241
And I turn editing mode on
4342
And I give the grade "5" to the user "Student 1" for the grade item "Manual item 1"

tests/behat/fetch_percentage_grades.feature

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,14 @@ Feature: Grades can be fetched either a real values or as percentages
3737
And I log in as "teacher1"
3838
And I am on "RefCourse" course homepage
3939
And I navigate to "Setup > Gradebook setup" in the course gradebook
40-
And I set the following settings for grade item "RefCourse":
40+
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
4141
| Aggregation | Natural |
4242
| Exclude empty grades | 1 |
43-
And I press "Add grade item"
44-
And I set the following fields to these values:
45-
| Item name | Manual item 1 |
46-
| Maximum grade | 10 |
47-
And I press "Save changes"
48-
And I press "Add grade item"
49-
And I set the following fields to these values:
50-
| Item name | Manual item 2 |
51-
| Maximum grade | 10 |
52-
And I press "Save changes"
53-
And I press "Add grade item"
54-
And I set the following fields to these values:
55-
| Item name | Manual item 3 |
56-
| Maximum grade | 10 |
57-
And I press "Save changes"
43+
And the following "grade items" exist:
44+
| itemname | grademax | course |
45+
| Manual item 1 | 10 | R |
46+
| Manual item 2 | 10 | R |
47+
| Manual item 3 | 10 | R |
5848
And I navigate to "Setup > Course grade settings" in the course gradebook
5949
And I set the field "Grade display type" to "Real (percentage)"
6050
#
@@ -107,12 +97,12 @@ Feature: Grades can be fetched either a real values or as percentages
10797
And I navigate to "View > Grader report" in the course gradebook
10898
And I turn editing mode off
10999
And the following should exist in the "user-grades" table:
110-
| Email address | -7- |
111-
| student1@example.com | 20.00 (66.67 %) |
112-
| student2@example.com | 20.00 (100.00 %) |
113-
| student3@example.com | 15.00 (75.00 %) |
114-
| student4@example.com | 0.00 (0.00 %) |
115-
| student5@example.com | - |
100+
| -1- | -2- | -6- |
101+
| Student 1 | student1@example.com | 20.00 (66.67 %) |
102+
| Student 2 | student2@example.com | 20.00 (100.00 %) |
103+
| Student 3 | student3@example.com | 15.00 (75.00 %) |
104+
| Student 4 | student4@example.com | 0.00 (0.00 %) |
105+
| Student 5 | student5@example.com | - |
116106

117107
@javascript
118108
Scenario: Grades are fetched as real values by default
@@ -125,9 +115,9 @@ Feature: Grades can be fetched either a real values or as percentages
125115
And I turn editing mode off
126116
And I am on "MainCourse" course homepage
127117
And I navigate to "Setup > Gradebook setup" in the course gradebook
128-
And I click on "Edit" "link" in the "Unit course 1" "table_row"
129-
And I click on "Edit settings" "link" in the "Unit course 1" "table_row"
130-
And I click on "Show more..." "link"
118+
And I click on grade item menu "Unit course 1" of type "gradeitem" on "setup" page
119+
And I choose "Edit grade item" in the open action menu
120+
And I click on "Show more..." "link" in the "Edit grade item" "dialogue"
131121
And I set the following fields to these values:
132122
| Grade display type | Real (percentage) |
133123
And I press "Save changes"
@@ -137,12 +127,12 @@ Feature: Grades can be fetched either a real values or as percentages
137127
And I am on "MainCourse" course homepage
138128
And I navigate to "View > Grader report" in the course gradebook
139129
Then the following should exist in the "user-grades" table:
140-
| Email address | -4- |
141-
| student1@example.com | 20.00 (66.67 %) |
142-
| student2@example.com | 20.00 (66.67 %) |
143-
| student3@example.com | 15.00 (50.00 %) |
144-
| student4@example.com | 0.00 (0.00 %) |
145-
| student5@example.com | - |
130+
| -1- | -2- | -3- |
131+
| Student 1 | student1@example.com | 20.00 (66.67 %) |
132+
| Student 2 | student2@example.com | 20.00 (66.67 %) |
133+
| Student 3 | student3@example.com | 15.00 (50.00 %) |
134+
| Student 4 | student4@example.com | 0.00 (0.00 %) |
135+
| Student 5 | student5@example.com | - |
146136

147137
@javascript
148138
Scenario: Grades can be fetched as percentual values
@@ -156,9 +146,9 @@ Feature: Grades can be fetched either a real values or as percentages
156146
And I turn editing mode off
157147
And I am on "MainCourse" course homepage
158148
And I navigate to "Setup > Gradebook setup" in the course gradebook
159-
And I click on "Edit" "link" in the "Unit course 1" "table_row"
160-
And I click on "Edit settings" "link" in the "Unit course 1" "table_row"
161-
And I click on "Show more..." "link"
149+
And I click on grade item menu "Unit course 1" of type "gradeitem" on "setup" page
150+
And I choose "Edit grade item" in the open action menu
151+
And I click on "Show more..." "link" in the "Edit grade item" "dialogue"
162152
And I set the following fields to these values:
163153
| Grade display type | Real (percentage) |
164154
And I press "Save changes"
@@ -168,9 +158,9 @@ Feature: Grades can be fetched either a real values or as percentages
168158
And I am on the "MainCourse" course page logged in as "teacher1"
169159
And I navigate to "View > Grader report" in the course gradebook
170160
Then the following should exist in the "user-grades" table:
171-
| Email address | -4- |
172-
| student1@example.com | 20.00 (66.67 %) |
173-
| student2@example.com | 30.00 (100.00 %) |
174-
| student3@example.com | 22.50 (75.00 %) |
175-
| student4@example.com | 0.00 (0.00 %) |
176-
| student5@example.com | - |
161+
| -1- | -2- | -3- |
162+
| Student 1 | student1@example.com | 20.00 (66.67 %) |
163+
| Student 2 | student2@example.com | 30.00 (100.00 %) |
164+
| Student 3 | student3@example.com | 22.50 (75.00 %) |
165+
| Student 4 | student4@example.com | 0.00 (0.00 %) |
166+
| Student 5 | student5@example.com | - |

tests/behat/hidden_grades.feature

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
2828
And I log in as "teacher1"
2929
And I am on "RefCourse" course homepage
3030
And I navigate to "Setup > Gradebook setup" in the course gradebook
31-
And I press "Add grade item"
32-
And I set the following fields to these values:
33-
| Item name | Manual item 1 |
34-
| Maximum grade | 10 |
35-
And I press "Save changes"
31+
And the following "grade items" exist:
32+
| itemname | grademax | course |
33+
| Manual item 1 | 10 | R |
3634
And I navigate to "View > Grader report" in the course gradebook
3735
And I turn editing mode on
3836
And I give the grade "5" to the user "Student 1" for the grade item "Manual item 1"
3937
And I give the grade "8" to the user "Student 2" for the grade item "Manual item 1"
4038
And I press "Save"
41-
And I follow "Change to aggregates only"
42-
And I click on "Edit grade" "link" in the "Student 1" "table_row"
43-
And I set the following fields to these values:
44-
| Hidden | 1 |
45-
And I press "Save changes"
39+
And I click on grade item menu "RefCourse" of type "course" on "grader" page
40+
And I choose "Show totals only" in the open action menu
41+
And I click on "Course total" "core_grades > grade_actions" in the "Student 1" "table_row"
42+
And I choose "Hide" in the open action menu
4643
And I turn editing mode off
4744

4845
@javascript
@@ -60,9 +57,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
6057
And I am on "MainCourse" course homepage
6158
And I navigate to "View > Grader report" in the course gradebook
6259
Then the following should exist in the "user-grades" table:
63-
| Email address | -4- |
64-
| student1@example.com | 5.00 |
65-
| student2@example.com | 8.00 |
60+
| -1- | -2- | -3- |
61+
| Student 1 | student1@example.com | 5.00 |
62+
| Student 2 | student2@example.com | 8.00 |
6663
And I log out
6764
#
6865
# Student 1 should not see the grade in the referenced course.
@@ -88,7 +85,7 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
8885
Scenario: If the whole course final grade item is hidden, the associated subcourse activity grade item is marked as hidden, too.
8986
Given I am on "RefCourse" course homepage
9087
And I navigate to "Setup > Gradebook setup" in the course gradebook
91-
And I set the following settings for grade item "RefCourse":
88+
And I set the following settings for grade item "RefCourse" of type "course" on "setup" page:
9289
| Hidden | 1 |
9390
And I am on "MainCourse" course homepage
9491
And I turn editing mode on
@@ -103,9 +100,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t
103100
And I am on "MainCourse" course homepage
104101
And I navigate to "View > Grader report" in the course gradebook
105102
Then the following should exist in the "user-grades" table:
106-
| Email address | -4- |
107-
| student1@example.com | 5.00 |
108-
| student2@example.com | 8.00 |
103+
| -1- | -2- | -3- |
104+
| Student 1 | student1@example.com | 5.00 |
105+
| Student 2 | student2@example.com | 8.00 |
109106
And I log out
110107
#
111108
# Student 1 should not see the grade in the referenced course.

0 commit comments

Comments
 (0)