mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-58138 tests: unit and behat tests covering bulk and default tabs
Part of MDL-58138 epic
This commit is contained in:
parent
a64a9f9ce4
commit
8db355c58f
62
completion/tests/behat/bulk_edit_activity_completion.feature
Normal file
62
completion/tests/behat/bulk_edit_activity_completion.feature
Normal file
@ -0,0 +1,62 @@
|
||||
@core @core_completion
|
||||
Feature: Allow teachers to bulk edit activity completion rules in a course.
|
||||
In order to avoid editing single activities
|
||||
As a teacher
|
||||
I need to be able to edit the completion rules for a group of activities.
|
||||
|
||||
# Given I am a teacher in a course with completion tracking enabled and activities present.
|
||||
# When I bulk edit activity completion rules for activities of the same kind.
|
||||
# Then the completion rules should be updated for all selected activities.
|
||||
@javascript
|
||||
Scenario: Bulk edit activity completion rules
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | Frist | teacher1@example.com |
|
||||
| student1 | Student | First | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | course | idnumber | name | intro | grade |
|
||||
| assign | C1 | a1 | Test assignment one | Submit something! | 300 |
|
||||
| assign | C1 | a2 | Test assignment two | Submit something! | 100 |
|
||||
| assign | C1 | a3 | Test assignment three | Submit something! | 150 |
|
||||
| assign | C1 | a4 | Test assignment four | Submit nothing! | 150 |
|
||||
And I log in as "teacher1"
|
||||
And I am on site homepage
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I set the following fields to these values:
|
||||
| Enable completion tracking | Yes |
|
||||
And I press "Save and display"
|
||||
When I navigate to "Course completion" in current page administration
|
||||
And I follow "Bulk edit activity completion"
|
||||
And I click on "Test assignment one" "checkbox"
|
||||
And I click on "Test assignment two" "checkbox"
|
||||
And I click on "Edit" "button"
|
||||
And I should see "Completion tracking"
|
||||
And I should see "The changes will affect the following 2 Activities/Resources"
|
||||
And I should see "Student must submit to this activity to complete it"
|
||||
And I select "Show activity as complete when conditions are met" from the "completion" singleselect
|
||||
And I click on "completionview" "checkbox"
|
||||
And I click on "completionusegrade" "checkbox"
|
||||
And I click on "completionsubmit" "checkbox"
|
||||
And I click on "Save changes" "button"
|
||||
Then I should see "Updated completion for activity Test assignment one"
|
||||
And I should see "Updated completion for activity Test assignment two"
|
||||
And I should see "With conditions" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment one']]" "xpath_element"
|
||||
And I should see "Student must view this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment one']]" "xpath_element"
|
||||
And I should see "Student must receive a grade to complete this activity" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment one']]" "xpath_element"
|
||||
And I should see "Student must submit to this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment one']]" "xpath_element"
|
||||
And I should not see "Completion expected on" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment one']]" "xpath_element"
|
||||
And I should see "With conditions" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment two']]" "xpath_element"
|
||||
And I should see "Student must view this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment two']]" "xpath_element"
|
||||
And I should see "Student must receive a grade to complete this activity" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment two']]" "xpath_element"
|
||||
And I should see "Student must submit to this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment two']]" "xpath_element"
|
||||
And I should not see "Completion expected on" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Test assignment two']]" "xpath_element"
|
||||
|
53
completion/tests/behat/default_activity_completion.feature
Normal file
53
completion/tests/behat/default_activity_completion.feature
Normal file
@ -0,0 +1,53 @@
|
||||
@core @core_completion
|
||||
Feature: Allow teachers to bulk edit activity completion rules in a course.
|
||||
In order to avoid editing single activities
|
||||
As a teacher
|
||||
I need to be able to edit the completion rules for a group of activities.
|
||||
|
||||
# Given I am a teacher in a course with completion tracking enabled and activities present.
|
||||
# When I edit activity completion defaults for activity types.
|
||||
# Then the completion rule defaults should apply only to activities created from that point onwards.
|
||||
@javascript
|
||||
Scenario: Bulk edit activity completion rules
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | Frist | teacher1@example.com |
|
||||
| student1 | Student | First | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | course | idnumber | name | intro | grade |
|
||||
| assign | C1 | a1 | Test assignment one | Submit something! | 300 |
|
||||
And I log in as "teacher1"
|
||||
And I am on site homepage
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I set the following fields to these values:
|
||||
| Enable completion tracking | Yes |
|
||||
And I press "Save and display"
|
||||
When I navigate to "Course completion" in current page administration
|
||||
And I follow "Default activity completion"
|
||||
And I click on "Assignments" "checkbox"
|
||||
And I click on "Edit" "button"
|
||||
And I should see "Completion tracking"
|
||||
And I should see "The changes will affect the following 1 Activities/Resources"
|
||||
And I should see "Student must submit to this activity to complete it"
|
||||
And I select "Show activity as complete when conditions are met" from the "completion" singleselect
|
||||
And I click on "completionview" "checkbox"
|
||||
And I click on "completionusegrade" "checkbox"
|
||||
And I click on "completionsubmit" "checkbox"
|
||||
And I click on "Save changes" "button"
|
||||
#Then I should see "Updated completion for activity Test assignment one"
|
||||
#And I should see "Updated completion for activity Test assignment two"
|
||||
And I should see "With conditions" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Assignments']]" "xpath_element"
|
||||
And I should see "Student must view this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Assignments']]" "xpath_element"
|
||||
And I should see "Student must receive a grade to complete this activity" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Assignments']]" "xpath_element"
|
||||
And I should see "Student must submit to this activity to complete it" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Assignments']]" "xpath_element"
|
||||
And I should not see "Completion expected on" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' row ')][.//*[text() = 'Assignments']]" "xpath_element"
|
||||
|
@ -38,7 +38,8 @@
|
||||
<div class="mod-indent-outer"></div>
|
||||
<div>
|
||||
{{#canmanage}}
|
||||
<input type="checkbox" class="m-r-1" name="cmid[]" data-section="{{sectionnumber}}" value="{{cmid}}" aria-label="{{#str}}checkactivity, completion, {{modname}}{{/str}}">
|
||||
<label class="accesshide" for="selectactivity_{{cmid}}">Select {{modname}}</label>
|
||||
<input type="checkbox" id="selectactivity_{{cmid}}" class="m-r-1" name="cmid[]" data-section="{{sectionnumber}}" value="{{cmid}}" aria-label="{{#str}}checkactivity, completion, {{modname}}{{/str}}">
|
||||
{{/canmanage}}
|
||||
<a href="{{url}}">
|
||||
<img src="{{icon}}" class="iconlarge activityicon" alt=" " role="presentation" />
|
||||
@ -46,7 +47,7 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="activity-completionstatus col-sm-6">
|
||||
<div class="activity-completionstatus col-sm-6" id="completionstatus_{{cmid}}">
|
||||
<div class="col-sm-1">
|
||||
{{#completionstatus.icon}}
|
||||
<img src="{{completionstatus.icon}}" class="m-r-2" alt=" " role="presentation">
|
||||
|
@ -607,4 +607,31 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_assign_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$cm1 = $this->create_instance(['completion' => '2', 'completionsubmit' => '1'])->get_course_module();
|
||||
$cm2 = $this->create_instance(['completion' => '2', 'completionsubmit' => '0'])->get_course_module();
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => ['completionsubmit' => '1']];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [get_string('completionsubmit', 'assign')];
|
||||
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
private function create_action_event($courseid, $instanceid, $eventtype) {
|
||||
$event = new stdClass();
|
||||
$event->name = 'Calendar event';
|
||||
$event->modulename = 'choice';
|
||||
$event->modulename = 'choice';
|
||||
$event->courseid = $courseid;
|
||||
$event->instance = $instanceid;
|
||||
$event->type = CALENDAR_EVENT_TYPE_ACTION;
|
||||
@ -399,4 +399,42 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_choice_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
|
||||
$choice1 = $this->getDataGenerator()->create_module('choice', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 1
|
||||
]);
|
||||
$choice2 = $this->getDataGenerator()->create_module('choice', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('choice', $choice1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('choice', $choice2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => ['completionsubmit' => 1]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [get_string('completionsubmit', 'choice')];
|
||||
$this->assertEquals(mod_choice_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_choice_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_choice_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_choice_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,8 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
'anonymous_response' => FEEDBACK_ANONYMOUS_NO,
|
||||
'courseid' => $course->id,
|
||||
];
|
||||
$DB->insert_record('feedback_completed', (object) $record);
|
||||
$DB->insert_record('feedback_completedtmp', (object) $record);
|
||||
$DB->insert_record('feedback_completed', (object)$record);
|
||||
$DB->insert_record('feedback_completedtmp', (object)$record);
|
||||
|
||||
// Check now for finished and unfinished attempts.
|
||||
$updates = feedback_check_updates_since($cm, $onehourago);
|
||||
@ -240,7 +240,7 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
private function create_action_event($courseid, $instanceid, $eventtype) {
|
||||
$event = new stdClass();
|
||||
$event->name = 'Calendar event';
|
||||
$event->modulename = 'feedback';
|
||||
$event->modulename = 'feedback';
|
||||
$event->courseid = $courseid;
|
||||
$event->instance = $instanceid;
|
||||
$event->type = CALENDAR_EVENT_TYPE_ACTION;
|
||||
@ -249,4 +249,42 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_feedback_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$feedback1 = $this->getDataGenerator()->create_module('feedback', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 1
|
||||
]);
|
||||
$feedback2 = $this->getDataGenerator()->create_module('feedback', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('feedback', $feedback1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('feedback', $feedback2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => ['completionsubmit' => 1]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [get_string('completionsubmit', 'feedback')];
|
||||
$this->assertEquals(mod_feedback_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_feedback_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_feedback_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_feedback_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -8180,7 +8180,6 @@ function mod_forum_get_fontawesome_icon_map() {
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Callback function that determines whether an action event should be showing its item count
|
||||
* based on the event type and the item count.
|
||||
*
|
||||
|
@ -3519,4 +3519,54 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_forum_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$forum1 = $this->getDataGenerator()->create_module('forum', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completiondiscussions' => 3,
|
||||
'completionreplies' => 3,
|
||||
'completionposts' => 3
|
||||
]);
|
||||
$forum2 = $this->getDataGenerator()->create_module('forum', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completiondiscussions' => 0,
|
||||
'completionreplies' => 0,
|
||||
'completionposts' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('forum', $forum1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('forum', $forum2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => [
|
||||
'completiondiscussions' => 3,
|
||||
'completionreplies' => 3,
|
||||
'completionposts' => 3
|
||||
]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [
|
||||
get_string('completiondiscussionsdesc', 'forum', 3),
|
||||
get_string('completionrepliesdesc', 'forum', 3),
|
||||
get_string('completionpostsdesc', 'forum', 3)
|
||||
];
|
||||
$this->assertEquals(mod_forum_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_forum_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_forum_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_forum_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -194,4 +194,42 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_glossary_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$glossary1 = $this->getDataGenerator()->create_module('glossary', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionentries' => 3
|
||||
]);
|
||||
$glossary2 = $this->getDataGenerator()->create_module('glossary', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionentries' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('glossary', $glossary1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('glossary', $glossary2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => ['completionentries' => 3]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [get_string('completionentriesdesc', 'glossary', $glossary1->completionentries)];
|
||||
$this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_glossary_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -289,4 +289,50 @@ class mod_lesson_lib_testcase extends advanced_testcase {
|
||||
$event->timestart = time();
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_lesson_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$lesson1 = $this->getDataGenerator()->create_module('lesson', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionendreached' => 1,
|
||||
'completiontimespent' => 3600
|
||||
]);
|
||||
$lesson2 = $this->getDataGenerator()->create_module('lesson', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionendreached' => 0,
|
||||
'completiontimespent' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('lesson', $lesson1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('lesson', $lesson2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => [
|
||||
'completionendreached' => 1,
|
||||
'completiontimespent' => 3600
|
||||
]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [
|
||||
get_string('completionendreached_desc', 'lesson'),
|
||||
get_string('completiontimespentdesc', 'lesson', format_time(3600)),
|
||||
];
|
||||
$this->assertEquals(mod_lesson_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_lesson_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_lesson_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_lesson_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -691,4 +691,49 @@ class mod_quiz_lib_testcase extends advanced_testcase {
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_quiz_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$quiz1 = $this->getDataGenerator()->create_module('quiz', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionattemptsexhausted' => 1,
|
||||
'completionpass' => 1
|
||||
]);
|
||||
$quiz2 = $this->getDataGenerator()->create_module('quiz', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionattemptsexhausted' => 0,
|
||||
'completionpass' => 0
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('quiz', $quiz1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('quiz', $quiz2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => [
|
||||
'completionattemptsexhausted' => 1,
|
||||
'completionpass' => 1
|
||||
]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [
|
||||
get_string('completionattemptsexhausteddesc', 'quiz'),
|
||||
get_string('completionpassdesc', 'quiz'),
|
||||
];
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -1580,7 +1580,6 @@ function mod_scorm_get_fontawesome_icon_map() {
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* This standard function will check all instances of this module
|
||||
* and make sure there are up-to-date events created for each of them.
|
||||
* If courseid = 0, then every scorm event in the site is checked, else
|
||||
|
@ -318,7 +318,7 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
||||
private function create_action_event($courseid, $instanceid, $eventtype) {
|
||||
$event = new stdClass();
|
||||
$event->name = 'Calendar event';
|
||||
$event->modulename = 'scorm';
|
||||
$event->modulename = 'scorm';
|
||||
$event->courseid = $courseid;
|
||||
$event->instance = $instanceid;
|
||||
$event->type = CALENDAR_EVENT_TYPE_ACTION;
|
||||
@ -327,4 +327,63 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_scorm_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$scorm1 = $this->getDataGenerator()->create_module('scorm', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionstatusrequired' => 6,
|
||||
'completionscorerequired' => 5,
|
||||
'completionstatusallscos' => 1
|
||||
]);
|
||||
$scorm2 = $this->getDataGenerator()->create_module('scorm', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionstatusrequired' => null,
|
||||
'completionscorerequired' => null,
|
||||
'completionstatusallscos' => null
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('scorm', $scorm1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('scorm', $scorm2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => [
|
||||
'completionstatusrequired' => 6,
|
||||
'completionscorerequired' => 5,
|
||||
'completionstatusallscos' => 1
|
||||
]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
// Determine the selected statuses using a bitwise operation.
|
||||
$cvalues = array();
|
||||
foreach (scorm_status_options(true) as $key => $value) {
|
||||
if (($scorm1->completionstatusrequired & $key) == $key) {
|
||||
$cvalues[] = $value;
|
||||
}
|
||||
}
|
||||
$statusstring = implode(', ', $cvalues);
|
||||
|
||||
$activeruledescriptions = [
|
||||
get_string('completionstatusrequireddesc', 'scorm', $statusstring),
|
||||
get_string('completionscorerequireddesc', 'scorm', $scorm1->completionscorerequired),
|
||||
get_string('completionstatusallscos', 'scorm'),
|
||||
];
|
||||
$this->assertEquals(mod_scorm_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_scorm_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_scorm_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_scorm_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
@ -275,4 +275,42 @@ class mod_survey_lib_testcase extends advanced_testcase {
|
||||
|
||||
return calendar_event::create($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the callback responsible for returning the completion rule descriptions.
|
||||
* This function should work given either an instance of the module (cm_info), such as when checking the active rules,
|
||||
* or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
|
||||
*/
|
||||
public function test_mod_survey_completion_get_active_rule_descriptions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 2]);
|
||||
$survey1 = $this->getDataGenerator()->create_module('survey', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 1,
|
||||
]);
|
||||
$survey2 = $this->getDataGenerator()->create_module('survey', [
|
||||
'course' => $course->id,
|
||||
'completion' => 2,
|
||||
'completionsubmit' => 0,
|
||||
]);
|
||||
$cm1 = cm_info::create(get_coursemodule_from_instance('survey', $survey1->id));
|
||||
$cm2 = cm_info::create(get_coursemodule_from_instance('survey', $survey2->id));
|
||||
|
||||
// Data for the stdClass input type.
|
||||
// This type of input would occur when checking the default completion rules for an activity type, where we don't have
|
||||
// any access to cm_info, rather the input is a stdClass containing completion and customdata attributes, just like cm_info.
|
||||
$moddefaults = new stdClass();
|
||||
$moddefaults->customdata = ['customcompletionrules' => ['completionsubmit' => 1]];
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [get_string('completionsubmit', 'survey')];
|
||||
$this->assertEquals(mod_survey_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_survey_get_completion_active_rule_descriptions($cm2), []);
|
||||
$this->assertEquals(mod_survey_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||
$this->assertEquals(mod_survey_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user