Skip to content
Snippets Groups Projects
Commit 386a651d authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Create a fresh question each time a test is done. Issue #552.

parent a8ad6272
No related branches found
No related tags found
No related merge requests found
......@@ -181,16 +181,16 @@ if (empty($question->deployedseeds)) {
new pix_icon('t/delete', stack_string('undeploy')));
}
$qn = question_bank::load_question($questionid);
$bulktestresults = array(false, '');
if (optional_param('testall', null, PARAM_INT)) {
// Bulk test all variants.
$bulktester = new stack_bulk_tester();
$bulktestresults = $bulktester->qtype_stack_test_question($qn, $testscases, 'web', $deployedseed, true);
$bulktestresults = $bulktester->qtype_stack_test_question($context, $questionid,
$testscases, 'web', $deployedseed, true);
}
// Print out question notes of all deployed variants.
$qn = question_bank::load_question($questionid);
$qn->seed = (int) $deployedseed;
$cn = $qn->get_context();
$qunote = question_engine::make_questions_usage_by_activity('qtype_stack', $cn);
......@@ -297,16 +297,7 @@ echo $OUTPUT->heading(stack_string('questiontestsfor', $seed), 2);
$testresults = array();
$allpassed = true;
foreach ($testscases as $key => $testcase) {
// Create a completely clean version of the question usage we will use.
// Evaluated state is stored in question variables etc.
$question = question_bank::load_question($questionid);
$question->seed = $seed;
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot);
$testresults[$key] = $testcase->test_question($quba, $question, $seed);
$testresults[$key] = $testcase->test_question($questionid, $seed, $context);
if (!$testresults[$key]->passed()) {
$allpassed = false;
}
......
......@@ -180,7 +180,7 @@ class stack_bulk_tester {
}
// Make sure the bulk tester is able to continue.
try {
list($ok, $message) = $this->qtype_stack_test_question($question, $tests, $outputmode);
list($ok, $message) = $this->qtype_stack_test_question($context, $questionid, $tests, $outputmode);
} catch (stack_exception $e) {
$ok = false;
$message = stack_string('errors') . ' : ' . $e;
......@@ -214,7 +214,8 @@ class stack_bulk_tester {
}
// Make sure the bulk tester is able to continue.
try {
list($ok, $message) = $this->qtype_stack_test_question($question, $tests, $outputmode, $seed);
list($ok, $message) = $this->qtype_stack_test_question($context, $questionid, $tests,
$outputmode, $seed);
} catch (stack_exception $e) {
$ok = false;
$message = stack_string('errors') . ' : ' . $e;
......@@ -246,17 +247,17 @@ class stack_bulk_tester {
* bool true if the tests passed, else false.
* sring message summarising the number of passes and fails.
*/
public function qtype_stack_test_question($question, $tests, $outputmode, $seed = null, $quiet = false) {
public function qtype_stack_test_question($context, $qid, $tests, $outputmode, $seed = null, $quiet = false) {
flush(); // Force output to prevent timeouts and to make progress clear.
core_php_time_limit::raise(60); // Prevent PHP timeouts.
gc_collect_cycles(); // Because PHP's default memory management is rubbish.
// Prepare the question and a usage.
$question = clone($question);
$question = question_bank::load_question($qid);
if (!is_null($seed)) {
$question->seed = (int) $seed;
}
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', context_system::instance());
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
// Execute the tests.
......@@ -264,7 +265,7 @@ class stack_bulk_tester {
$fails = 0;
foreach ($tests as $key => $testcase) {
$testresults[$key] = $testcase->test_question($quba, $question, $seed);
$testresults[$key] = $testcase->test_question($qid, $seed, $context);
if ($testresults[$key]->passed()) {
$passes += 1;
} else {
......@@ -306,7 +307,7 @@ class stack_bulk_tester {
}
/**
* Instantial the question to seed the cache.
* Instantiate the question to seed the cache.
*
* @param qtype_stack_question $question the question to test.
* @param int|null $seed if we want to force a particular version.
......
......@@ -62,13 +62,21 @@ class stack_question_test {
/**
* Run this test against a particular question.
* @param question_usage_by_activity $quba the useage to use when running the test.
* @param qtype_stack_question $question the question to test.
* @param int $questionid The database id of the question to test.
* @param int $seed the random seed to use.
* @param context_course $context The course in which this question takes place.
* @return stack_question_test_result the test results.
*/
public function test_question(question_usage_by_activity $quba, qtype_stack_question $question, $seed) {
public function test_question($questionid, $seed, $context) {
// Create a completely clean version of the question usage we will use.
// Evaluated state is stored in question variables etc.
$question = question_bank::load_question($questionid);
if (!is_null($seed)) {
$question->seed = (int) $seed;
}
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot, $seed);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment