Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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: 303 lines (12 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