From 8d29653fbce70b2451e70020db3b502774473505 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 9 Mar 2021 20:14:46 +0800 Subject: [PATCH] MDL-70815 completion: Test internal_get_state() with custom completion Use the custom completion implementation for mod_choice to test completion_info::get_state() to cover the case where the completion state is being determined from the custom completion condition. --- lib/tests/completionlib_test.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index eacc7a3fbf4..75de3067cac 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -427,6 +427,34 @@ class core_completionlib_testcase extends advanced_testcase { $this->assertEquals(COMPLETION_INCOMPLETE, $completioninfo->internal_get_state($cm, $teacher->id, null)); } + /** + * Test for internal_get_state() for an activity that supports custom completion. + */ + public function test_internal_get_state_with_custom_completion() { + $this->setup_data(); + + $choicerecord = [ + 'course' => $this->course, + 'completion' => COMPLETION_TRACKING_AUTOMATIC, + 'completionsubmit' => COMPLETION_ENABLED, + ]; + $choice = $this->getDataGenerator()->create_module('choice', $choicerecord); + $cminfo = cm_info::create(get_coursemodule_from_instance('choice', $choice->id)); + + $completioninfo = new completion_info($this->course); + + // Fetch completion for the user who hasn't made a choice yet. + $completion = $completioninfo->internal_get_state($cminfo, $this->user->id, COMPLETION_INCOMPLETE); + $this->assertEquals(COMPLETION_INCOMPLETE, $completion); + + // Have the user make a choice. + $choicewithoptions = choice_get_choice($choice->id); + $optionids = array_keys($choicewithoptions->option); + choice_user_submit_response($optionids[0], $choice, $this->user->id, $this->course, $cminfo); + $completion = $completioninfo->internal_get_state($cminfo, $this->user->id, COMPLETION_INCOMPLETE); + $this->assertEquals(COMPLETION_COMPLETE, $completion); + } + public function test_set_module_viewed() { $this->mock_setup(); -- 2.43.0