MDL-40778 clear cache for random questions between tests
This commit is contained in:
@@ -176,6 +176,15 @@ class qtype_random extends question_type {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -65,6 +65,8 @@ class qtype_random_test extends advanced_testcase {
|
||||
|
||||
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));
|
||||
@@ -72,6 +74,12 @@ class qtype_random_test extends advanced_testcase {
|
||||
|
||||
$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));
|
||||
|
||||
Reference in New Issue
Block a user