Merge branch 'MDL-86099_500_STABLE' of https://github.com/marxjohnson/moodle into MOODLE_500_STABLE

This commit is contained in:
Mihail Geshoski
2025-11-17 22:28:35 +08:00
2 changed files with 31 additions and 0 deletions
@@ -627,6 +627,12 @@ class question_bank_helper {
);
}
if ($bankname === '') {
throw new \coding_exception(
'The provided bankname is empty. You must provide a name for the question bank.',
);
}
$data = new stdClass();
$data->section = 0;
$data->visible = 0;
@@ -16,6 +16,7 @@
namespace core_question;
use core\exception\coding_exception;
use core_question\local\bank\question_bank_helper;
/**
@@ -354,6 +355,30 @@ final class question_bank_helper_test extends \advanced_testcase {
$this->assertEquals($bankname, $cminfo->get_name());
}
/**
* Attempting to create a default bank with an empty name throws an exception and does not create the bank.
*/
public function test_create_default_open_instance_with_empty_name(): void {
$this->resetAfterTest();
self::setAdminUser();
$course = self::getDataGenerator()->create_course();
$bankname = '';
try {
question_bank_helper::create_default_open_instance($course, $bankname);
} catch (coding_exception $e) {
$this->assertStringEndsWith(
'The provided bankname is empty. You must provide a name for the question bank.',
$e->getMessage(),
);
}
$modinfo = get_fast_modinfo($course);
$cminfos = $modinfo->get_instances_of('qbank');
$this->assertCount(0, $cminfos);
}
/**
* Assert that viewing a question bank logs the view for that user up to a maximum of 5 unique bank views.
*