Skip to content

Commit

Permalink
MDL-79367 availability: Fail grade does not mark activities as completed
Browse files Browse the repository at this point in the history
The UX team confirmed that an activity shouldn't be considered completed
when the criteria use a passing grade and the user gets a failing grade.
So the COMPLETION_COMPLETE_FAIL status won't be considered
completed from now on.
  • Loading branch information
sarjona committed Oct 16, 2023
1 parent 23b8625 commit 9ced468
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 171 deletions.
12 changes: 10 additions & 2 deletions availability/condition/completion/classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,23 @@ public function is_available($not, info $info, $grabthelot, $userid): bool {

$allow = true;
if ($this->expectedcompletion == COMPLETION_COMPLETE) {
// Complete also allows the pass, fail states.
// Complete also allows the pass state.
switch ($completiondata->completionstate) {
case COMPLETION_COMPLETE:
case COMPLETION_COMPLETE_FAIL:
case COMPLETION_COMPLETE_PASS:
break;
default:
$allow = false;
}
} else if ($this->expectedcompletion == COMPLETION_INCOMPLETE) {
// Incomplete also allows the fail state.
switch ($completiondata->completionstate) {
case COMPLETION_INCOMPLETE:
case COMPLETION_COMPLETE_FAIL:
break;
default:
$allow = false;
}
} else {
// Other values require exact match.
if ($completiondata->completionstate != $this->expectedcompletion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,48 @@ Feature: availability_completion
And I click on "forum 1" "link" in the "region-main" "region"
And I am on "Course 1" course homepage
And I should see "Page 2" in the "region-main" "region"

@javascript
Scenario Outline: Restrict access for activity completion should display correctly
Given the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
And the following "activities" exist:
| activity | name | course | idnumber | gradepass | completion | completionpassgrade | completionusegrade |
| quiz | Test quiz name | C1 | quiz1 | 5.00 | 2 | 1 | 1 |
And quiz "Test quiz name" contains the following questions:
| question | page |
| First question | 1 |
And I am on the "Page 2" "page activity editing" page logged in as "teacher1"
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I click on ".availability-item .availability-eye img" "css_element"
And I set the following fields to these values:
| Required completion status | <condition> |
| cm | quiz |
And I press "Save and return to course"
And I am on the "Course 1" "course" page logged in as "student1"
And I <shouldornot> see "Page 2" in the "region-main" "region"
# Failed grade for quiz.
When user "student1" has attempted "Test quiz name" with responses:
| slot | response |
| 1 | <answer1> |
And I reload the page
And I <shouldornotanswer1> see "Page 2" in the "region-main" "region"
# Passing grade for quiz.
But user "student1" has attempted "Test quiz name" with responses:
| slot | response |
| 1 | <answer2> |
And I reload the page
And I <shouldornotanswer2> see "Page 2" in the "region-main" "region"

Examples:
| condition | answer1 | answer2 | shouldornot | shouldornotanswer1 | shouldornotanswer2 |
| must be marked complete | False | True | should not | should not | should |
| must not be marked complete | False | True | should | should | should not |
| must be complete with pass grade | False | True | should not | should not | should |
| must be complete with fail grade | False | True | should not | should | should not |
12 changes: 6 additions & 6 deletions availability/condition/completion/tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ public function test_usage() {
$cond = new condition((object)[
'cm' => (int)$assigncm->id, 'e' => COMPLETION_INCOMPLETE
]);
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));

$cond = new condition((object)[
'cm' => (int)$assigncm->id, 'e' => COMPLETION_COMPLETE
]);
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

$cond = new condition((object)[
'cm' => (int)$assigncm->id, 'e' => COMPLETION_COMPLETE_PASS
Expand Down Expand Up @@ -531,10 +531,10 @@ public function previous_activity_data(): array {
],
// Depending on assign with grade.
'Previous complete condition with previous fail grade' => [
40, COMPLETION_COMPLETE, '', 'page3', true, false, '~Assign!.*is marked complete~'
40, COMPLETION_COMPLETE, '', 'page3', false, true, '~Assign!.*is marked complete~',
],
'Previous incomplete condition with previous fail grade' => [
40, COMPLETION_INCOMPLETE, '', 'page3', false, true, '~Assign!.*is incomplete~'
40, COMPLETION_INCOMPLETE, '', 'page3', true, false, '~Assign!.*is incomplete~',
],
'Previous complete pass condition with previous fail grade' => [
40, COMPLETION_COMPLETE_PASS, '', 'page3', false, true, '~Assign!.*is complete and passed~'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,117 +17,69 @@ Feature: Enable Block Completion in a course using activity completion
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | intro |
| page | C1 | page1 | Test page name | Test page description |
| assign | C1 | assign1 | Test assign name | Test page description |
| activity | course | idnumber | name | gradepass | completion | completionview | completionusegrade | completionpassgrade |
| page | C1 | page1 | Test page name | | 2 | 1 | 0 | 0 |
| assign | C1 | assign1 | Test assign name | 50 | 2 | 0 | 1 | 1 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| completionstatus | Course | C1 | course-view-* | side-pre |

Scenario: Add the block to a the course and add course completion items
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
And I add the "Course completion status" block
Scenario: Completion status block when student has not started any activities
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test page name | 1 |
And I press "Save changes"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "0 of 1" in the "Activity completion" "table_row"

Scenario: Add the block to a the course and add course completion items
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
And I add the "Course completion status" block
Scenario: Completion status block when student has completed a page
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test page name | 1 |
And I press "Save changes"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test page name"
When I am on the "Test page name" "page activity" page logged in as student1
And I am on "Course 1" course homepage
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "1 of 1" in the "Activity completion" "table_row"
And I follow "More details"
And I should see "Yes" in the "Activity completion" "table_row"

@javascript
Scenario: Add the block to a the course and add course completion items with passing grade
Given I am on the "Test assign name" "assign activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Add requirements | 1 |
| Receive a grade | 1 |
| Passing grade | 1 |
| gradepass | 50 |
And I press "Save and return to course"
And I am on the "Test assign name" "assign activity" page
And I follow "View all submissions"
And I click on "Grade" "link" in the "Student" "table_row"
And I set the field "Grade out of 100" to "53"
And I set the field "Notify student" to "0"
And I press "Save changes"
And I am on "Course 1" course homepage with editing mode on
And I add the "Course completion status" block
Scenario: Completion status block with items with passing grade
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test assign name | 1 |
And I press "Save changes"
And I log out
When I am on the "Test assign name" "assign activity" page logged in as student1
And I am on "Course 1" course homepage
Then I should see "Status: Pending" in the "Course completion status" "block"
And I should see "0 of 1" in the "Activity completion" "table_row"
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assign name | student1 | 53 |
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "1 of 1" in the "Activity completion" "table_row"
And I trigger cron
And I am on "Course 1" course homepage
And I follow "More details"
And I should see "Achieving grade, Achieving passing grade" in the "Activity completion" "table_row"
And I should see "Yes" in the "Activity completion" "table_row"

@javascript
Scenario: Add the block to a the course and add course completion items with failing grade.
Given I am on the "Test assign name" "assign activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Add requirements | 1 |
| Receive a grade | 1 |
| Passing grade | 1 |
| gradepass | 50 |
And I press "Save and return to course"
And I am on the "Test assign name" "assign activity" page
And I follow "View all submissions"
And I click on "Grade" "link" in the "Student" "table_row"
And I set the field "Grade out of 100" to "49"
And I set the field "Notify student" to "0"
And I press "Save changes"
And I am on "Course 1" course homepage with editing mode on
And I add the "Course completion status" block
Scenario: Completion status block with items with failing grade
Given I am on the "Course 1" course page logged in as teacher1
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assign name | student1 | 49 |
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test assign name | 1 |
And I press "Save changes"
And I log out
When I am on the "Test assign name" "assign activity" page logged in as student1
And I am on "Course 1" course homepage
Then I should see "Status: Pending" in the "Course completion status" "block"
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "0 of 1" in the "Activity completion" "table_row"
And I trigger cron
And I am on "Course 1" course homepage
Expand Down
4 changes: 2 additions & 2 deletions completion/criteria/completion_criteria_activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public function review($completion, $mark = true) {

$data = $info->get_data($cm, false, $completion->userid);

// If the activity is complete
if (in_array($data->completionstate, array(COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS, COMPLETION_COMPLETE_FAIL))) {
// If the activity is complete.
if (in_array($data->completionstate, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS])) {
if ($mark) {
$completion->mark_complete();
}
Expand Down
Loading

0 comments on commit 9ced468

Please sign in to comment.