Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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.

return: \stdClass
param: \stdClass $course

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.

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

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

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

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.

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