Skip to content

Commit

Permalink
Merge branch 'MDL-71401-master-3' of git://github.com/mickhawkins/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 4, 2021
2 parents 75dcac4 + 2984de3 commit fd8544b
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 12 deletions.
20 changes: 19 additions & 1 deletion lib/completionlib.php
Expand Up @@ -599,6 +599,24 @@ public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0,
}
}

// Default to current user if one is not provided.
if ($userid == 0) {
$userid = $USER->id;
}

// Delete the cm's cached completion data for this user if automatic completion is enabled.
// This ensures any changes to the status of individual completion conditions in the activity will be fetched.
if ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) {
$completioncache = cache::make('core', 'completion');
$completionkey = $userid . '_' . $this->course->id;
$completiondata = $completioncache->get($completionkey);

if ($completiondata !== false) {
unset($completiondata[$cm->id]);
$completioncache->set($completionkey, $completiondata);
}
}

// Get current value of completion state and do nothing if it's same as
// the possible result of this change. If the change is to COMPLETE and the
// current value is one of the COMPLETE_xx subtypes, ignore that as well
Expand Down Expand Up @@ -634,7 +652,7 @@ public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0,
$newstate = $this->internal_get_state($cm, $userid, $current);
}

// If changed, update
// If the overall completion state has changed, update it in the cache.
if ($newstate != $current->completionstate) {
$current->completionstate = $newstate;
$current->timemodified = time();
Expand Down
6 changes: 1 addition & 5 deletions lib/tests/completionlib_test.php
Expand Up @@ -143,6 +143,7 @@ public function test_update_state() {
$c->update_state($cm);

// Enabled, but current state is same as possible result, do nothing.
$cm->completion = COMPLETION_TRACKING_AUTOMATIC;
$c = $mockbuilder->getMock();
$current = (object)array('completionstate' => COMPLETION_COMPLETE, 'overrideby' => null);
$c->expects($this->once())
Expand All @@ -151,7 +152,6 @@ public function test_update_state() {
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
->with($cm, false, 0)
->will($this->returnValue($current));
$c->update_state($cm, COMPLETION_COMPLETE);

Expand All @@ -165,7 +165,6 @@ public function test_update_state() {
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
->with($cm, false, 0)
->will($this->returnValue($current));
$c->update_state($cm, COMPLETION_COMPLETE);

Expand All @@ -179,7 +178,6 @@ public function test_update_state() {
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
->with($cm, false, 0)
->will($this->returnValue($current));
$c->update_state($cm, COMPLETION_COMPLETE);

Expand All @@ -191,7 +189,6 @@ public function test_update_state() {
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
->with($cm, false, 0)
->will($this->returnValue($current));
$changed = clone($current);
$changed->timemodified = time();
Expand All @@ -213,7 +210,6 @@ public function test_update_state() {
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
->with($cm, false, 0)
->will($this->returnValue($current));
$c->expects($this->once())
->method('internal_get_state')
Expand Down
3 changes: 3 additions & 0 deletions mod/assign/tests/behat/assign_activity_completion.feature
Expand Up @@ -126,6 +126,9 @@ Feature: View activity completion in the assignment activity
And I press "Save changes"
And I press "Submit assignment"
And I press "Continue"
And the "View" completion condition of "Music history" is displayed as "done"
And the "Make a submission" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
Expand Down
13 changes: 10 additions & 3 deletions mod/data/tests/behat/data_activity_completion.feature
Expand Up @@ -98,7 +98,16 @@ Feature: View activity completion in the database activity
| Instrument types | Drums |
And I press "Save and view"
# One entry is not enough to mark as complete.
And the "View" completion condition of "Music history" is displayed as "done"
And the "Make entries: 2" completion condition of "Music history" is displayed as "todo"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I am on "Course 1" course homepage
And I add an entry to "Music history" database with:
| Instrument types | Hurdygurdy |
And I press "Save and view"
Then the "View" completion condition of "Music history" is displayed as "done"
And the "Make entries: 2" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
Expand All @@ -109,9 +118,7 @@ Feature: View activity completion in the database activity
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
And I add an entry to "Music history" database with:
| Instrument types | Hurdygurdy |
And I press "Save and view"
And I follow "Music history"
Then the "View" completion condition of "Music history" is displayed as "done"
And the "Make entries: 2" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "done"
Expand Down
14 changes: 14 additions & 0 deletions mod/forum/tests/behat/forum_activity_completion.feature
Expand Up @@ -71,9 +71,23 @@ Feature: View activity completion in the forum activity
And I add a new discussion to "Music history" forum with:
| Subject | Fun instruments |
| Message | I like drums |
And I am on "Course 1" course homepage
And I follow "Music history"
And the "View" completion condition of "Music history" is displayed as "done"
And the "Start discussions: 1" completion condition of "Music history" is displayed as "done"
And the "Make forum posts: 2" completion condition of "Music history" is displayed as "todo"
And the "Post replies: 1" completion condition of "Music history" is displayed as "todo"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I reply "Fun instruments" post from "Music history" forum with:
| Subject | Reply 1 to Fun instruments |
| Message | Guitar is also Fun |
And I am on "Course 1" course homepage
And I follow "Music history"
And the "View" completion condition of "Music history" is displayed as "done"
And the "Start discussions: 1" completion condition of "Music history" is displayed as "done"
And the "Make forum posts: 2" completion condition of "Music history" is displayed as "done"
And the "Post replies: 1" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I log out
# Grade the student
And I log in as "teacher1"
Expand Down
3 changes: 3 additions & 0 deletions mod/glossary/tests/behat/glossary_activity_completion.feature
Expand Up @@ -68,6 +68,9 @@ Feature: View activity completion in the glossary activity
| Concept | Blast beats |
| Definition | Repeated fast tempo hits combining bass, snare and cymbal |
And I press "Save changes"
And the "View" completion condition of "Music history" is displayed as "done"
And the "Make entries: 1" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
Expand Down
5 changes: 5 additions & 0 deletions mod/lesson/tests/behat/lesson_activity_completion.feature
Expand Up @@ -75,6 +75,11 @@ Feature: View activity completion in the lesson activity
When I am on "Course 1" course homepage
And I follow "Music history"
And I wait "2" seconds
And I reload the page
And the "View" completion condition of "Music history" is displayed as "done"
And the "Spend at least 1 sec on this activity" completion condition of "Music history" is displayed as "done"
And the "Go through the activity to the end" completion condition of "Music history" is displayed as "todo"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And I press "The history of music part 1"
And I set the field "Your answer" to "Some drummers play with their sticks flipped around"
And I press "Submit"
Expand Down
70 changes: 70 additions & 0 deletions mod/quiz/tests/behat/quiz_activity_completion.feature
@@ -0,0 +1,70 @@
@mod @mod_quiz @core_completion
Feature: View activity completion in the quiz activity
In order to have visibility of quiz completion requirements
As a student
I need to be able to view my quiz completion progress

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following config values are set as admin:
| grade_item_advanced | hiddenuntil |
And 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 "activity" exists:
| activity | quiz |
| course | C1 |
| idnumber | quiz1 |
| name | Test quiz name |
| section | 1 |
| attempts | 2 |
| gradepass | 5.00 |
| completion | 2 |
| completionview | 1 |
| completionusegrade | 1 |
| completionpass | 1 |
| completionattemptsexhausted | 1 |
| completionminattemptsenabled | 1 |
| completionminattempts | 1 |
And quiz "Test quiz name" contains the following questions:
| question | page |
| First question | 1 |

Scenario: View automatic completion items as a student
When I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test quiz name"
And the "View" completion condition of "Test quiz name" is displayed as "done"
And the "Make attempts: 1" completion condition of "Test quiz name" is displayed as "todo"
And the "Receive a grade" completion condition of "Test quiz name" is displayed as "todo"
And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "todo"
And user "student1" has attempted "Test quiz name" with responses:
| slot | response |
| 1 | False |
And I follow "Test quiz name"
And the "View" completion condition of "Test quiz name" is displayed as "done"
And the "Make attempts: 1" completion condition of "Test quiz name" is displayed as "done"
And the "Receive a grade" completion condition of "Test quiz name" is displayed as "failed"
And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "todo"
And I press "Re-attempt quiz"
And I set the field "True" to "1"
And I press "Finish attempt ..."
And I press "Submit all and finish"
And I follow "Finish review"
And the "View" completion condition of "Test quiz name" is displayed as "done"
And the "Make attempts: 1" completion condition of "Test quiz name" is displayed as "done"
And the "Receive a grade" completion condition of "Test quiz name" is displayed as "done"
And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "done"
10 changes: 7 additions & 3 deletions mod/scorm/tests/behat/scorm_activity_completion.feature
Expand Up @@ -65,29 +65,33 @@ Feature: View activity completion in the SCORM activity
And I press "Enter"
And I switch to the main frame
And I click on "Par?" "list_item"
And I wait until the page is ready
And I click on "Keeping Score" "list_item"
And I wait until the page is ready
And I click on "Other Scoring Systems" "list_item"
And I wait until the page is ready
And I click on "The Rules of Golf" "list_item"
And I wait until the page is ready
And I click on "Playing Golf Quiz" "list_item"
And I switch to "scorm_object" iframe
And I click on "[id='question_com.scorm.golfsamples.interactions.playing_1_1']" "css_element"
And I press "Submit Answers"
And I switch to the main frame
And I click on "How to Have Fun Playing Golf" "list_item"
And I wait until the page is ready
And I click on "How to Make Friends Playing Golf" "list_item"
And I wait until the page is ready
And I click on "Having Fun Quiz" "list_item"
And I switch to "scorm_object" iframe
And I click on "[id='question_com.scorm.golfsamples.interactions.fun_1_False']" "css_element"
And I press "Submit Answers"
And I switch to the main frame
And I follow "Exit activity"
And I am on "Course 1" course homepage
And I follow "Music history"
And the "View" completion condition of "Music history" is displayed as "done"
# Conditions that are not possible to achieve (eg score below requirement but all attempts used) are marked as failed.
And the "Receive a score of 3 or more" completion condition of "Music history" is displayed as "failed"
# This condition caches as failed, which will be investigated as part of MDL-71401.
And the "Do all parts of this activity" completion condition of "Music history" is displayed as "failed"
And the "Do all parts of this activity" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "done"
And the "Complete and pass the activity" completion condition of "Music history" is displayed as "failed"

Expand Down

0 comments on commit fd8544b

Please sign in to comment.