Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

Helper trait for quiz question unit tests. This trait helps to execute different tests for quiz, for example if it needs to create a quiz, add question to the question, add random quetion to the quiz, do a backup or restore.

Author: Safat Shahin <safatshahin@catalyst-au.net>
Copyright: 2021 Catalyst IT Australia Pty Ltd
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 181 lines (7 kb)
Included or required: 3 times
Referenced: 0 times
Includes or requires: 0 files

Defines 7 functions


Functions that are not part of a class:

create_test_quiz(\stdClass $course)   X-Ref
Create a test quiz for the specified course.

param: \stdClass $course
return: \stdClass

add_two_regular_questions($questiongenerator, \stdClass $quiz, $override = null)   X-Ref
Helper method to add regular questions in quiz.

param: component_generator_base $questiongenerator
param: \stdClass $quiz
param: array $override

add_one_random_question($questiongenerator, \stdClass $quiz, $override = [])   X-Ref
Helper method to add random question to quiz.

param: component_generator_base $questiongenerator
param: \stdClass $quiz
param: array $override

attempt_quiz(\stdClass $quiz, \stdClass $user, $attemptnumber = 1)   X-Ref
Attempt questions for a quiz and user.

param: \stdClass $quiz Quiz to attempt.
param: \stdClass $user A user to attempt the quiz.
param: int $attemptnumber
return: array

backup_quiz(\stdClass $quiz, \stdClass $user)   X-Ref
A helper method to backup test quiz.

param: \stdClass $quiz Quiz to attempt.
param: \stdClass $user A user to attempt the quiz.
return: string A backup ID ready to be restored.

restore_quiz(string $backupid, stdClass $course, stdClass $user)   X-Ref
A helper method to restore provided backup.

param: string $backupid Backup ID to restore.
param: stdClass $course
param: stdClass $user

duplicate_quiz($course, $quiz)   X-Ref
A helper method to emulate duplication of the quiz.

param: stdClass $course
param: stdClass $quiz
return: \cm_info|null