return $DB->update_record('question', $updateobject);
}
+ /**
+ * During unit tests we need to be able to reset all caches so that each new test starts in a known state.
+ * Intended for use only for testing. This is a stop gap until we start using the MUC caching api here.
+ * You need to call this before every test that loads one or more random questions.
+ */
+ public function clear_caches_before_testing() {
+ $this->availablequestionsbycategory = array();
+ }
+
/**
* Get all the usable questions from a particular question category.
*
public function test_question_creation() {
$this->resetAfterTest();
+ question_bank::get_qtype('random')->clear_caches_before_testing();
+
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category();
$question1 = $generator->create_question('shortanswer', null, array('category' => $cat->id));
$randomquestion = $generator->create_question('random', null, array('category' => $cat->id));
+ $expectedids = array($question1->id, $question2->id);
+ $actualids = question_bank::get_qtype('random')->get_available_questions_from_category($cat->id, 0);
+ sort($expectedids);
+ sort($actualids);
+ $this->assertEquals($expectedids, $actualids);
+
$q = question_bank::load_question($randomquestion->id);
$this->assertContains($q->id, array($question1->id, $question2->id));