MDL-82554 question: Allow null createdby in question_has_capability_on.

This commit is contained in:
Michael Aherne
2024-07-23 10:47:07 +01:00
parent d7cb2a66cd
commit da95f8d083
2 changed files with 30 additions and 1 deletions
+29
View File
@@ -2008,6 +2008,35 @@ class questionlib_test extends \advanced_testcase {
question_has_capability_on('one', 'tag');
}
/**
* Test that question_has_capability_on does not fail when passed an object with a null
* createdby property.
*/
public function test_question_has_capability_on_object_with_null_createdby(): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$category = $generator->create_category();
$context = \context_coursecat::instance($category->id);
$role = $generator->create_role();
role_assign($role, $user->id, $context->id);
assign_capability('moodle/question:editmine', CAP_ALLOW, $role, $context->id);
$this->setUser($user);
$fakequestion = (object) [
'contextid' => $context->id,
'createdby' => null,
];
$this->assertFalse(question_has_capability_on($fakequestion, 'edit'));
$fakequestion->createdby = $user->id;
$this->assertTrue(question_has_capability_on($fakequestion, 'edit'));
}
/**
* Test of question_categorylist function.
*