diff --git a/question/engine/bank.php b/question/engine/bank.php index 61b01a7229e..c239388d591 100644 --- a/question/engine/bank.php +++ b/question/engine/bank.php @@ -610,7 +610,7 @@ class question_finder implements cache_data_source { WHERE q.id ' . $idcondition, $params); foreach ($questionids as $id) { - if (!array_key_exists($id, $questionids)) { + if (!array_key_exists($id, $questiondata)) { throw new dml_missing_record_exception('question', '', array('id' => $id)); } get_question_options($questiondata[$id]); diff --git a/question/engine/tests/questionbank_test.php b/question/engine/tests/questionbank_test.php index 873507909bf..c0b4cb24289 100644 --- a/question/engine/tests/questionbank_test.php +++ b/question/engine/tests/questionbank_test.php @@ -110,4 +110,20 @@ class question_bank_test extends advanced_testcase { ), question_bank::get_finder()->get_questions_from_categories_with_usage_counts( array($cat->id), new qubaid_list(array($quba->get_id())))); } + + public function test_load_many_for_cache() { + $this->resetAfterTest(); + $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); + $cat = $generator->create_question_category(); + $q1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); + + $qs = question_finder::get_instance()->load_many_for_cache([$q1->id]); + $this->assertArrayHasKey($q1->id, $qs); + } + + public function test_load_many_for_cache_missing_id() { + // Try to load a non-existent question. + $this->expectException('dml_missing_record_exception'); + question_finder::get_instance()->load_many_for_cache([-1]); + } }