Skip to content

Commit

Permalink
Merge branch 'MDL-68153' of https://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Mar 25, 2020
2 parents f6cf23f + 511801e commit 1cc2470
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion question/classes/bank/edit_menu_column.php
Expand Up @@ -86,7 +86,7 @@ protected function display_content($question, $rowclasses) {
}
}

$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);
Expand Down
31 changes: 31 additions & 0 deletions question/tests/bank_view_test.php
Expand Up @@ -70,4 +70,35 @@ public function test_viewing_question_bank_should_not_load_individual_questions(
// 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);
}
}

0 comments on commit 1cc2470

Please sign in to comment.