Merge branch 'MDL-82499-main' of https://github.com/micaherne/moodle
This commit is contained in:
+1
-1
@@ -1465,7 +1465,7 @@ function question_has_capability_on($questionorid, $cap, $notused = -1): bool {
|
||||
WHERE q.id = :id';
|
||||
|
||||
// Well, at least we tried. Seems that we really have to read from DB.
|
||||
$question = $DB->get_record_sql($sql, ['id' => $questionid]);
|
||||
$question = $DB->get_record_sql($sql, ['id' => $questionid], MUST_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2009,6 +2009,21 @@ class questionlib_test extends \advanced_testcase {
|
||||
question_has_capability_on('one', 'tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test question_has_capability_on with an invalid question ID
|
||||
*/
|
||||
public function test_question_has_capability_on_invalid_question(): void {
|
||||
try {
|
||||
question_has_capability_on(42, 'tag');
|
||||
$this->fail('Expected exception');
|
||||
} catch (\moodle_exception $exception) {
|
||||
$this->assertInstanceOf(\dml_missing_record_exception::class, $exception);
|
||||
|
||||
// We also get debugging from initial attempt to load question data.
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of question_categorylist function.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user