Merge branch 'MDL-79971-404' of https://github.com/aanabit/moodle into MOODLE_404_STABLE

This commit is contained in:
Huong Nguyen 2024-07-01 14:16:45 +07:00
commit cf92d64a57
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
2 changed files with 10 additions and 3 deletions

View File

@ -1631,11 +1631,12 @@ class completion_info {
$data->coursemoduleid = $data->cmvcoursemoduleid;
$data->userid = $data->cmvuserid;
}
// When reseting all state in the completion, we need to keep current view state.
// We cannot assume the activity has been viewed, so we should check if there is any course_modules_viewed already.
$data->viewed = is_null($data->cmvuserid) ? 0 : 1;
unset($data->cmvcoursemoduleid);
unset($data->cmvuserid);
// When reseting all state in the completion, we need to keep current view state.
$data->viewed = 1;
}
return (array)$data;

View File

@ -876,6 +876,7 @@ class completionlib_test extends advanced_testcase {
* @covers ::get_completion_data
*/
public function test_get_completion_data(): void {
$this->setAdminUser();
$this->setup_data();
$choicegenerator = $this->getDataGenerator()->get_plugin_generator('mod_choice');
$choice = $choicegenerator->create_instance([
@ -905,6 +906,11 @@ class completionlib_test extends advanced_testcase {
$this->assertEquals(0, $completiondatabeforeview['viewed']);
$this->assertEquals($cm->id, $completiondatabeforeview['coursemoduleid']);
// Mark as completed before viewing it.
$completioninfo->update_state($cm, COMPLETION_COMPLETE, $this->user->id, true);
$completiondatabeforeview = $completioninfo->get_completion_data($cm->id, $this->user->id, $defaultdata);
$this->assertEquals(0, $completiondatabeforeview['viewed']);
// Set viewed.
$completioninfo->set_module_viewed($cm, $this->user->id);