Merge branch 'MDL-77381-MOODLE_401_STABLE' of https://github.com/ScottVerbeek/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-08-16 22:40:12 +08:00
commit 0d82ce2629
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
2 changed files with 51 additions and 1 deletions

View File

@ -560,7 +560,9 @@ ORDER BY
* @return array of records. See the SQL in this function to see the fields available.
*/
public function load_questions_usages_latest_steps(qubaid_condition $qubaids, $slots = null, $fields = null) {
if ($slots !== null) {
if ($slots === []) {
return [];
} else if ($slots !== null) {
[$slottest, $params] = $this->db->get_in_or_equal($slots, SQL_PARAMS_NAMED, 'slot');
$slotwhere = " AND qa.slot {$slottest}";
} else {

View File

@ -21,6 +21,8 @@ use question_bank;
use question_engine;
use question_engine_data_mapper;
use question_state;
use quiz;
use quiz_attempt;
defined('MOODLE_INTERNAL') || die();
@ -332,4 +334,50 @@ class datalib_reporting_queries_test extends \qbehaviour_walkthrough_test_base {
'state' => (string) question_state::$gaveup,
), $state);
}
/**
* Test that a Quiz with only description questions wont break \quiz_statistics\task\recalculate.
*
* @covers \quiz_statistics\task\recalculate::execute()
* @return void
*/
public function test_quiz_with_description_questions_recalculate_statistics() {
$this->resetAfterTest();
// Create course with quiz module.
$course = $this->getDataGenerator()->create_course();
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$layout = '1';
$quiz = $quizgenerator->create_instance([
'course' => $course->id,
'grade' => 0.0, 'sumgrades' => 1,
'layout' => $layout
]);
// Add question of type description to quiz.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$question = $questiongenerator->create_question('description', null, ['category' => $cat->id]);
quiz_add_quiz_question($question->id, $quiz);
// Create attempt.
$user = $this->getDataGenerator()->create_user();
$quizobj = quiz::create($quiz->id, $user->id);
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, null, $timenow, false, $user->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
// Submit attempt.
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj->process_submitted_actions($timenow, false);
$attemptobj->process_finish($timenow, false);
// Calculate the statistics.
$this->expectOutputRegex('~.*Calculations completed.*~');
$statisticstask = new \quiz_statistics\task\recalculate();
$statisticstask->execute();
}
}