From 7365000fcec340e6dff08eabfc50dc69311d4570 Mon Sep 17 00:00:00 2001 From: Ilya Tregubov Date: Fri, 14 Oct 2022 11:15:33 +0300 Subject: [PATCH] MDL-75173 core_completion: More unit tests and Behat. --- ...ourse_completion_activity_criteria.feature | 83 +++++++++++++- completion/tests/progress_test.php | 108 ++++++++++++++++++ 2 files changed, 190 insertions(+), 1 deletion(-) diff --git a/completion/tests/behat/course_completion_activity_criteria.feature b/completion/tests/behat/course_completion_activity_criteria.feature index ea0ee3ce0e3..998fd1656ef 100644 --- a/completion/tests/behat/course_completion_activity_criteria.feature +++ b/completion/tests/behat/course_completion_activity_criteria.feature @@ -45,7 +45,7 @@ Feature: Course completion state should match completion criteria And I press "Save and return to course" And I log out - Scenario: Completion status show match completion criteria. + Scenario: Completion status show match completion criteria when passgrage condition is set. Given I am on the "Course 1" course page logged in as "student1" And the "Receive a grade" completion condition of "Test assignment name" is displayed as "todo" And the "Receive a passing grade" completion condition of "Test assignment name" is displayed as "todo" @@ -64,6 +64,14 @@ Feature: Course completion state should match completion criteria And I set the following fields to these values: | Grade out of 100 | 50.0 | And I press "Save changes" + And I am on the "Course 1" course page + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + And "Student 1, Test assignment name: Completed (did not achieve pass grade)" "icon" should exist in the "Student 1" "table_row" + And I navigate to "Reports" in current page administration + And I click on "Course completion" "link" in the "region-main" "region" + And "Student 1, Test assignment name: Completed (did not achieve pass grade)" "icon" should exist in the "Student 1" "table_row" + And "Student 1, Course complete: Not completed" "icon" should exist in the "Student 1" "table_row" And I log out When I am on the "Course 1" course page logged in as "student1" And I should see "Status: Pending" in the "Course completion status" "block" @@ -78,6 +86,14 @@ Feature: Course completion state should match completion criteria And I set the following fields to these values: | Grade out of 100 | 75.0 | And I press "Save changes" + And I am on the "Course 1" course page + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + And "Student 1, Test assignment name: Completed (achieved pass grade)" "icon" should exist in the "Student 1" "table_row" + And I navigate to "Reports" in current page administration + And I click on "Course completion" "link" in the "region-main" "region" + And "Student 1, Test assignment name: Completed (achieved pass grade)" "icon" should exist in the "Student 1" "table_row" + And "Student 1, Course complete: Completed" "icon" should exist in the "Student 1" "table_row" And I log out And I am on the "Course 1" course page logged in as "student1" And I should see "Status: Complete" in the "Course completion status" "block" @@ -85,3 +101,68 @@ Feature: Course completion state should match completion criteria And the "Receive a passing grade" completion condition of "Test assignment name" is displayed as "done" And I am on the "My courses" page Then I should see "100%" in the "Course overview" "block" + + Scenario: Completion status show match completion criteria when passgrage condition is not set. + Given I am on the "Course 1" course page logged in as "teacher1" + And I am on the "Test assignment name" "assign activity" page + And I navigate to "Settings" in current page administration + And I set the following fields to these values: + | Completion tracking | Show activity as complete when conditions are met | + | completionusegrade | 1 | + | completionpassgrade | 0 | + | gradepass | 70 | + And I press "Save and return to course" + And I log out + And I am on the "Course 1" course page logged in as "student1" + And the "Receive a grade" completion condition of "Test assignment name" is displayed as "todo" + And I should see "Status: Not yet started" in the "Course completion status" "block" + And I am on the "Test assignment name" "assign activity" page + And I press "Add submission" + And I set the following fields to these values: + | Online text | I'm the student1 submission | + And I press "Save changes" + And I press "Submit assignment" + And I press "Continue" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as teacher1 + And I follow "View all submissions" + And I click on "Grade" "link" in the "Student 1" "table_row" + And I set the following fields to these values: + | Grade out of 100 | 50.0 | + And I press "Save changes" + And I am on the "Course 1" course page + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + And "Student 1, Test assignment name: Completed (did not achieve pass grade)" "icon" should exist in the "Student 1" "table_row" + And I navigate to "Reports" in current page administration + And I click on "Course completion" "link" in the "region-main" "region" + And "Student 1, Test assignment name: Completed (did not achieve pass grade)" "icon" should exist in the "Student 1" "table_row" + And "Student 1, Course complete: Completed" "icon" should exist in the "Student 1" "table_row" + And I log out + When I am on the "Course 1" course page logged in as "student1" + And I should see "Status: Complete" in the "Course completion status" "block" + # Once MDL-75582 is fixed "failed" should be changed to "done" + And the "Receive a grade" completion condition of "Test assignment name" is displayed as "failed" + And I am on the "My courses" page + And I should see "100%" in the "Course overview" "block" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as teacher1 + And I follow "View all submissions" + And I click on "Grade" "link" in the "Student 1" "table_row" + And I set the following fields to these values: + | Grade out of 100 | 75.0 | + And I press "Save changes" + And I am on the "Course 1" course page + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + And "Student 1, Test assignment name: Completed (achieved pass grade)" "icon" should exist in the "Student 1" "table_row" + And I navigate to "Reports" in current page administration + And I click on "Course completion" "link" in the "region-main" "region" + And "Student 1, Test assignment name: Completed (achieved pass grade)" "icon" should exist in the "Student 1" "table_row" + And "Student 1, Course complete: Completed" "icon" should exist in the "Student 1" "table_row" + And I log out + And I am on the "Course 1" course page logged in as "student1" + And I should see "Status: Complete" in the "Course completion status" "block" + And the "Receive a grade" completion condition of "Test assignment name" is displayed as "done" + And I am on the "My courses" page + Then I should see "100%" in the "Course overview" "block" diff --git a/completion/tests/progress_test.php b/completion/tests/progress_test.php index 08785fa3b25..16f77290acd 100644 --- a/completion/tests/progress_test.php +++ b/completion/tests/progress_test.php @@ -120,6 +120,114 @@ class progress_test extends \advanced_testcase { $this->assertEquals('100', \core_completion\progress::get_course_progress_percentage($course, $user->id)); } + /** + * Tests that the course progress percentage is returned correctly for various grade to pass settings + * + * @covers \core_completion\progress::get_course_progress_percentage. + */ + public function test_course_progress_percentage_completion_state() { + global $DB; + + // Add a course that supports completion. + $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); + + // Enrol a user in the course. + $teacher = $this->getDataGenerator()->create_user(); + $user = $this->getDataGenerator()->create_user(); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); + $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); + $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id); + $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); + + // Add three activities that use completion. + /** @var \mod_assign_generator $assigngenerator */ + $assigngenerator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); + $assign['passgragepassed'] = $assigngenerator->create_instance([ + 'course' => $course->id, + 'completion' => COMPLETION_ENABLED, + 'completionusegrade' => 1, + 'gradepass' => 50, + 'completionpassgrade' => 1 + ]); + + $assign['passgragefailed'] = $assigngenerator->create_instance([ + 'course' => $course->id, + 'completion' => COMPLETION_ENABLED, + 'completionusegrade' => 1, + 'gradepass' => 50, + 'completionpassgrade' => 1 + ]); + + $assign['passgragenotused'] = $assigngenerator->create_instance([ + 'course' => $course->id, + 'completion' => COMPLETION_ENABLED, + 'completionusegrade' => 1, + 'gradepass' => 50, + ]); + + $assign['nograde'] = $assigngenerator->create_instance([ + 'course' => $course->id, + 'completion' => COMPLETION_ENABLED, + ]); + + $c = new \completion_info($course); + + foreach ($assign as $item) { + $cmassing = get_coursemodule_from_id('assign', $item->cmid); + + // Add activity completion criteria. + $criteriadata = new \stdClass(); + $criteriadata->id = $course->id; + $criteriadata->criteria_activity = []; + // Some activities. + $criteriadata->criteria_activity[$cmassing->id] = 1; + $criterion = new \completion_criteria_activity(); + $criterion->update_config($criteriadata); + } + + $this->setUser($teacher); + + foreach ($assign as $key => $item) { + $cm = get_coursemodule_from_instance('assign', $item->id); + + // Mark user completions. + $completion = new \stdClass(); + $completion->coursemoduleid = $cm->id; + $completion->timemodified = time(); + $completion->viewed = COMPLETION_NOT_VIEWED; + $completion->overrideby = null; + + if ($key == 'passgragepassed') { + $completion->id = 0; + $completion->completionstate = COMPLETION_COMPLETE_PASS; + $completion->userid = $user->id; + $c->internal_set_data($cm, $completion, true); + } else if ($key == 'passgragefailed') { + $completion->id = 0; + $completion->completionstate = COMPLETION_COMPLETE_FAIL; + $completion->userid = $user->id; + $c->internal_set_data($cm, $completion, true); + } else if ($key == 'passgragenotused') { + $completion->id = 0; + $completion->completionstate = COMPLETION_COMPLETE; + $completion->userid = $user->id; + $c->internal_set_data($cm, $completion, true); + } else if ($key == 'nograde') { + $completion->id = 0; + $completion->completionstate = COMPLETION_COMPLETE; + $completion->userid = $user->id; + $c->internal_set_data($cm, $completion, true); + } + } + + // Run course completions cron. + \core_completion\api::mark_course_completions_activity_criteria(); + + // Check we have received valid data. + // Only assign2 is not completed. + $this->assertEquals('75', \core_completion\progress::get_course_progress_percentage($course, $user->id)); + } + /** * Tests that the course progress returns null when the course does not support it. */