diff --git a/classes/local/tool_dynamic_cohorts/condition/course_completed.php b/classes/local/tool_dynamic_cohorts/condition/course_completed.php index 333eb0d..a9f6243 100644 --- a/classes/local/tool_dynamic_cohorts/condition/course_completed.php +++ b/classes/local/tool_dynamic_cohorts/condition/course_completed.php @@ -228,15 +228,17 @@ public function get_sql(): condition_sql { public function is_broken(): bool { global $DB; - // Check course exists. - if (!$course = $DB->get_record('course', ['id' => $this->get_courseid_value()])) { - return true; - } + if ($this->get_config_data()) { + // Check course exists. + if (!$course = $DB->get_record('course', ['id' => $this->get_courseid_value()])) { + return true; + } - // Check completion is enabled for a course. - $completion = new completion_info($course); - if (!$completion->is_enabled()) { - return true; + // Check completion is enabled for a course. + $completion = new completion_info($course); + if (!$completion->is_enabled()) { + return true; + } } return false; diff --git a/tests/local/tool_dynamic_cohorts/condition/course_completed_test.php b/tests/local/tool_dynamic_cohorts/condition/course_completed_test.php index fd7279d..3c5bbf5 100644 --- a/tests/local/tool_dynamic_cohorts/condition/course_completed_test.php +++ b/tests/local/tool_dynamic_cohorts/condition/course_completed_test.php @@ -157,6 +157,12 @@ public function test_is_broken_and_broken_description() { $course = $this->getDataGenerator()->create_course(); + $condition = condition_base::get_instance(0, (object)[ + 'classname' => '\tool_dynamic_cohorts\local\tool_dynamic_cohorts\condition\course_completed', + ]); + + $this->assertFalse($condition->is_broken()); + // Invalid course. $condition = $this->get_condition([ 'courseid' => 7777, @@ -257,5 +263,4 @@ public function test_get_sql_data() { public function test_get_events() { $this->assertEquals([], $this->get_condition()->get_events()); } - }