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 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

Module generator base class.

Copyright: 2012 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 322 lines (13 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

testing_module_generator:: (2 methods):
  reset()
  get_modulename()

name:: (5 methods):
  precreate_course_module()
  post_add_instance()
  prepare_moduleinfo_record()
  create_instance()
  create_content()

name:: (5 methods):
  precreate_course_module()
  post_add_instance()
  prepare_moduleinfo_record()
  create_instance()
  create_content()


Class: testing_module_generator  - X-Ref

Module generator base class.

Extend in mod/xxxx/tests/generator/lib.php as class mod_xxxx_generator.

reset()   X-Ref
To be called from data reset code only,
do not use in tests.

return: void

get_modulename()   X-Ref
Returns module name

return: string name of module that this class describes

Class: name  - X-Ref

precreate_course_module($courseid, array $options)   X-Ref
Create course module and link it to course

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

param: integer $courseid
param: array $options section, visible
return: integer $cm instance id

post_add_instance($id, $cmid)   X-Ref
Called after *_add_instance()

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

param: int $id
param: int $cmid
return: stdClass module instance

prepare_moduleinfo_record($record, $options)   X-Ref
Merges together arguments $record and $options and fills default module
fields that are shared by all module types

param: object|array $record fields (different from defaults) for this module
param: null|array $options for backward-compatibility this may include fields from course_modules

create_instance($record = null, array $options = null)   X-Ref
Creates an instance of the module for testing purposes.

Module type will be taken from the class name. Each module type may overwrite
this function to add other default values used by it.

param: array|stdClass $record data for module being generated. Requires 'course' key
param: null|array $options general options for course module. Since 2.6 it is
return: stdClass record from module-defined table with additional field

create_content($instance, $record = array()   X-Ref
Generates a piece of content for the module.
User is usually taken from global $USER variable.

param: stdClass $instance object returned from create_instance() call
param: stdClass|array $record
return: stdClass generated object

Class: name  - X-Ref

precreate_course_module($courseid, array $options)   X-Ref
Create course module and link it to course

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

param: integer $courseid
param: array $options section, visible
return: integer $cm instance id

post_add_instance($id, $cmid)   X-Ref
Called after *_add_instance()

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

param: int $id
param: int $cmid
return: stdClass module instance

prepare_moduleinfo_record($record, $options)   X-Ref
Merges together arguments $record and $options and fills default module
fields that are shared by all module types

param: object|array $record fields (different from defaults) for this module
param: null|array $options for backward-compatibility this may include fields from course_modules

create_instance($record = null, array $options = null)   X-Ref
Creates an instance of the module for testing purposes.

Module type will be taken from the class name. Each module type may overwrite
this function to add other default values used by it.

param: array|stdClass $record data for module being generated. Requires 'course' key
param: null|array $options general options for course module. Since 2.6 it is
return: stdClass record from module-defined table with additional field

create_content($instance, $record = array()   X-Ref
Generates a piece of content for the module.
User is usually taken from global $USER variable.

param: stdClass $instance object returned from create_instance() call
param: stdClass|array $record
return: stdClass generated object