Skip to content
Permalink
Browse files

MDL-48452 Completion: Expected date doesn't save when form is locked

The completion fields are locked when a user has already completed the
task, to prevent you accidentally causing it to recalculate the data.

This lock doesn't apply to the expected date field, as this doesn't
affect user completion. However, changes to the field in this
situation were incorrectly not saved.
  • Loading branch information...
sammarshallou committed Dec 9, 2014
1 parent dbe2143 commit f2830925e53706e65ab23f0fcc6ddcc8b087e1a2
Showing with 68 additions and 6 deletions.
  1. +11 −6 course/modlib.php
  2. +57 −0 course/tests/behat/activities_edit_completion.feature
@@ -491,12 +491,17 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
}
$completion = new completion_info($course);
if ($completion->is_enabled() && !empty($moduleinfo->completionunlocked)) {
// Update completion settings.
$cm->completion = $moduleinfo->completion;
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
$cm->completionview = $moduleinfo->completionview;
$cm->completionexpected = $moduleinfo->completionexpected;
if ($completion->is_enabled()) {
// Completion settings that would affect users who have already completed
// the activity may be locked; if so, these should not be updated.
if (!empty($moduleinfo->completionunlocked)) {
$cm->completion = $moduleinfo->completion;
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
$cm->completionview = $moduleinfo->completionview;
}
// The expected date does not affect users who have completed the activity,
// so it is safe to update it regardless of the lock status.
$cm->completionexpected = $moduleinfo->completionexpected;
}
if (!empty($CFG->enableavailability)) {
// This code is used both when submitting the form, which uses a long
@@ -0,0 +1,57 @@
@core @core_course
Feature: Edit completion settings of an activity
In order to edit completion settings without accidentally breaking user data
As a teacher
I need to edit the activity and use the unlock button if required

Background:
Given I log in as "admin"
And I set the following administration settings values:
| Enable completion tracking | 1 |
And I log out
And the following "courses" exist:
| fullname | shortname | enablecompletion |
| Course 1 | C1 | 1 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | content | completion | completionview |
| page | C1 | x | TestPage | x | x | 2 | 1 |
And I log in as "admin"
And I follow "Course 1"

Scenario: Completion is not locked when the activity has not yet been viewed
Given I turn editing mode on
And I click on "Edit settings" "link" in the "TestPage" activity
When I expand all fieldsets
Then I should see "Completion tracking"
And I should not see "Completion options locked"

Scenario: Completion is locked after the activity has been viewed
Given I follow "TestPage"
When I follow "Edit settings"
And I expand all fieldsets
Then I should see "Completion options locked"

@javascript
Scenario: Pressing the unlock button allows the user to edit completion settings
Given I follow "TestPage"
When I follow "Edit settings"
And I expand all fieldsets
And I press "Unlock completion options"
Then I should see "Completion options unlocked"
And I set the field "Completion tracking" to "Students can manually mark the activity as completed"
And I press "Save and display"
And I follow "Edit settings"
And I expand all fieldsets
Then the field "Completion tracking" matches value "Students can manually mark the activity as completed"

@javascript
Scenario: Even when completion is locked, the user can still set the date
Given I follow "TestPage"
And I follow "Edit settings"
And I expand all fieldsets
When I click on "id_completionexpected_enabled" "checkbox"
And I set the field "id_completionexpected_year" to "2013"
And I press "Save and display"
And I follow "Edit settings"
And I expand all fieldsets
Then the field "id_completionexpected_year" matches value "2013"

0 comments on commit f283092

Please sign in to comment.
You can’t perform that action at this time.