MDL-68153 qbank: question of unknown type should not cause fatal error

Regression casued by MDL-67153
This commit is contained in:
Tim Hunt 2020-03-11 20:40:51 +00:00
parent 9df2f66fb4
commit 511801eaa9
2 changed files with 32 additions and 1 deletions

View File

@ -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);

View File

@ -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);
}
}