Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 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: 207 lines (8 kb)
Included or required: 3 times
Referenced: 16 times
Includes or requires: 0 files

Defines 8 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

add_random_questions(int $quizid, int $page, int $categoryid, int $number)   X-Ref
Add random questions to a quiz, with a filter condition based on a category ID.

param: int $quizid The quiz to add the questions to.
param: int $page The page number to add the questions to.
param: int $categoryid The category ID to use for the filter condition.
param: int $number The number of questions to add.
return: void