mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-68153 qbank: question of unknown type should not cause fatal error
Regression casued by MDL-67153
This commit is contained in:
parent
9df2f66fb4
commit
511801eaa9
@ -86,7 +86,7 @@ class edit_menu_column extends column_base {
|
||||
}
|
||||
}
|
||||
|
||||
$qtypeactions = \question_bank::get_qtype($question->qtype)
|
||||
$qtypeactions = \question_bank::get_qtype($question->qtype, false)
|
||||
->get_extra_question_bank_actions($question);
|
||||
foreach ($qtypeactions as $action) {
|
||||
$menu->add($action);
|
||||
|
@ -70,4 +70,35 @@ class core_question_bank_view_testcase extends advanced_testcase {
|
||||
// Verify the question has not been loaded into the cache.
|
||||
$this->assertFalse($cache->has($questiondata->id));
|
||||
}
|
||||
|
||||
public function test_unknown_qtype_does_not_break_view() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$generator = $this->getDataGenerator();
|
||||
/** @var core_question_generator $questiongenerator */
|
||||
$questiongenerator = $generator->get_plugin_generator('core_question');
|
||||
|
||||
// Create a course.
|
||||
$course = $generator->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
// Create a question in the default category.
|
||||
$contexts = new question_edit_contexts($context);
|
||||
$cat = question_make_default_categories($contexts->all());
|
||||
$questiondata = $questiongenerator->create_question('numerical', null,
|
||||
['name' => 'Example question', 'category' => $cat->id]);
|
||||
$DB->set_field('question', 'qtype', 'unknownqtype', ['id' => $questiondata->id]);
|
||||
|
||||
// Generate the view.
|
||||
$view = new core_question\bank\view($contexts, new moodle_url('/'), $course);
|
||||
ob_start();
|
||||
$view->display('editq', 0, 20, $cat->id . ',' . $context->id, false, false, false);
|
||||
$html = ob_get_clean();
|
||||
|
||||
// Mainly we are verifying that there was no fatal error.
|
||||
|
||||
// Verify the output includes the expected question.
|
||||
$this->assertContains('Example question', $html);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user