Skip to content

Commit

Permalink
issue #41: fix an issue when not configured condition was broken
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed Apr 3, 2024
1 parent 8e031c4 commit 61fe9f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 10 additions & 8 deletions classes/local/tool_dynamic_cohorts/condition/course_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -257,5 +263,4 @@ public function test_get_sql_data() {
public function test_get_events() {
$this->assertEquals([], $this->get_condition()->get_events());
}

}

0 comments on commit 61fe9f4

Please sign in to comment.