Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Public Member Functions | |
combine_defaults_and_record (array $defaults, $record) | |
Helper method which combines $defaults with the values specified in $record. More... | |
create_and_enrol ($course, $role='student', $userparams=null, $enrol='manual', $timestart=0, $timeend=0, $status=null) | |
Create a new user, and enrol them in the specified course as the supplied role. More... | |
create_block ($blockname, $record=null, array $options=array()) | |
Create a test block. More... | |
create_category ($record=null, array $options=null) | |
Create a test course category. More... | |
create_cohort ($record=null, array $options=null) | |
Create test cohort. More... | |
create_course ($record=null, array $options=null) | |
Create a test course. More... | |
create_course_section ($record=null, array $options=null) | |
Create course section if does not exist yet. More... | |
create_custom_field ($data) | |
Create a new custom field. More... | |
create_custom_field_category ($data) | |
Create a new course custom field category with the given name. More... | |
create_event ($data=[]) | |
Helper function used to create an event. More... | |
create_grade_category ($record=null) | |
Create a grade_category. More... | |
create_grade_item ($record=null) | |
Create a grade_item. More... | |
create_grade_outcome ($record=null) | |
Create a grade_outcome. More... | |
create_group ($record) | |
Create a test group for the specified course. More... | |
create_group_member ($record) | |
Create a test group member. More... | |
create_grouping ($record) | |
Create a test grouping for the specified course. More... | |
create_grouping_group ($record) | |
Create a test grouping group. More... | |
create_lti_tool ($data=array()) | |
Helper function used to create an LTI tool. More... | |
create_module ($modulename, $record=null, array $options=null) | |
Create a test activity module. More... | |
create_repository ($type, $record=null, array $options=null) | |
Create an instance of a repository. More... | |
create_repository_type ($type, $record=null, array $options=null) | |
Create an instance of a repository. More... | |
create_role ($record=null) | |
Creates a new role in the system. More... | |
create_scale ($record=null, array $options=null) | |
Create a test scale. More... | |
create_tag ($record=null) | |
Create a tag. More... | |
create_user ($record=null, array $options=null) | |
Create a test user. More... | |
enrol_user ($userid, $courseid, $roleidorshortname=null, $enrol='manual', $timestart=0, $timeend=0, $status=null) | |
Simplified enrolment of user to course using default options. More... | |
get_plugin_generator ($component) | |
Return generator for given plugin or component. More... | |
reset () | |
To be called from data reset code only, do not use in tests. More... | |
role_assign ($roleid, $userid, $contextid=false) | |
Assigns the specified role to a user in the context. More... | |
Public Attributes | |
array | $firstnames |
lis of common first names More... | |
array | $lastnames |
lis of common last names More... | |
$loremipsum = | |
Protected Attributes | |
$categorycount = 0 | |
$cohortcount = 0 | |
$coursecount = 0 | |
array | $generators = array() |
list of plugin generators | |
int | $gradecategorycounter = 0 |
The number of grade categories created. | |
int | $gradeitemcounter = 0 |
The number of grade items created. | |
int | $gradeoutcomecounter = 0 |
The number of grade outcomes created. | |
$groupcount = 0 | |
$groupingcount = 0 | |
$rolecount = 0 | |
$scalecount = 0 | |
$tagcount = 0 | |
$usercounter = 0 | |
testing_data_generator::combine_defaults_and_record | ( | array | $defaults, |
$record | |||
) |
Helper method which combines $defaults with the values specified in $record.
If $record is an object, it is converted to an array. Then, for each key that is in $defaults, but not in $record, the value from $defaults is copied.
array | $defaults | the default value for each field with |
array | stdClass | $record |
array | updated $record. |
testing_data_generator::create_and_enrol | ( | $course, | |
$role = 'student' , |
|||
$userparams = null , |
|||
$enrol = 'manual' , |
|||
$timestart = 0 , |
|||
$timeend = 0 , |
|||
$status = null |
|||
) |
Create a new user, and enrol them in the specified course as the supplied role.
stdClass | $course | The course to enrol in |
string | $role | The role to give within the course |
stdClass | $userparams | User parameters |
stdClass | The created user |
testing_data_generator::create_block | ( | $blockname, | |
$record = null , |
|||
array | $options = array() |
||
) |
Create a test block.
The $record passed in becomes the basis for the new row added to the block_instances table. You only need to supply the values of interest. Any missing values have sensible defaults filled in, and ->blockname will be set based on $blockname.
The $options array provides additional data, not directly related to what will be inserted in the block_instance table, which may affect the block that is created. The meanings of any data passed here depends on the particular type of block being created.
string | $blockname | the type of block to create. E.g. 'html'. |
array | stdClass | $record | forms the basis for the entry to be inserted in the block_instances table. |
array | $options | further, block-specific options to control how the block is created. |
stdClass | new block_instance record. |
testing_data_generator::create_category | ( | $record = null , |
|
array | $options = null |
||
) |
Create a test course category.
array | stdClass | $record | |
array | $options |
core_course_category | course category record |
testing_data_generator::create_cohort | ( | $record = null , |
|
array | $options = null |
||
) |
Create test cohort.
array | stdClass | $record | |
array | $options |
stdClass | cohort record |
testing_data_generator::create_course | ( | $record = null , |
|
array | $options = null |
||
) |
Create a test course.
array | stdClass | $record | |
array | $options | with keys: 'createsections'=>bool precreate all sections |
stdClass | course record |
testing_data_generator::create_course_section | ( | $record = null , |
|
array | $options = null |
||
) |
Create course section if does not exist yet.
array | stdClass | $record | must contain 'course' and 'section' attributes |
array | null | $options |
stdClass |
coding_exception |
testing_data_generator::create_custom_field | ( | $data | ) |
Create a new custom field.
array | $data | Array with 'name', 'shortname' and 'type' of the field |
core_customfield |
testing_data_generator::create_custom_field_category | ( | $data | ) |
Create a new course custom field category with the given name.
array | $data | Array with data['name'] of category |
core_customfield |
testing_data_generator::create_event | ( | $data = [] | ) |
Helper function used to create an event.
array | $data |
stdClass |
testing_data_generator::create_grade_category | ( | $record = null | ) |
Create a grade_category.
array | stdClass | $record |
stdClass | the grade category record |
testing_data_generator::create_grade_item | ( | $record = null | ) |
testing_data_generator::create_grade_outcome | ( | $record = null | ) |
Create a grade_outcome.
array | stdClass | $record |
stdClass | the grade outcome record |
testing_data_generator::create_group | ( | $record | ) |
Create a test group for the specified course.
$record should be either an array or a stdClass containing infomation about the group to create. At the very least it needs to contain courseid. Default values are added for name, description, and descriptionformat if they are not present.
This function calls groups_create_group() to create the group within the database.
array | stdClass | $record |
stdClass | group record |
testing_data_generator::create_group_member | ( | $record | ) |
Create a test group member.
array | stdClass | $record |
coding_exception |
boolean |
testing_data_generator::create_grouping | ( | $record | ) |
Create a test grouping for the specified course.
$record should be either an array or a stdClass containing infomation about the grouping to create. At the very least it needs to contain courseid. Default values are added for name, description, and descriptionformat if they are not present.
This function calls groups_create_grouping() to create the grouping within the database.
array | stdClass | $record |
stdClass | grouping record |
testing_data_generator::create_grouping_group | ( | $record | ) |
Create a test grouping group.
array | stdClass | $record |
coding_exception |
boolean |
testing_data_generator::create_lti_tool | ( | $data = array() | ) |
Helper function used to create an LTI tool.
array | $data |
stdClass | the tool |
testing_data_generator::create_module | ( | $modulename, | |
$record = null , |
|||
array | $options = null |
||
) |
Create a test activity module.
The $record should contain the same data that you would call from ->get_data() when the mod_[type]_mod_form is submitted, except that you only need to supply values of interest. The only required value is 'course'. Any missing values will have a sensible default supplied.
The $options array provides additional data, not directly related to what would come back from the module edit settings form, which may affect the activity that is created. The meanings of any data passed here depends on the particular type of activity being created.
string | $modulename | the type of activity to create. E.g. 'forum' or 'quiz'. |
array | stdClass | $record | data, as if from the module edit settings form. |
array | $options | additional data that may affect how the module is created. |
stdClass | activity record new new record that was just inserted in the table like 'forum' or 'quiz', with a ->cmid field added. |
testing_data_generator::create_repository | ( | $type, | |
$record = null , |
|||
array | $options = null |
||
) |
Create an instance of a repository.
string | type of repository to create an instance for. | |
array | stdClass | $record | data to use to up set the instance. |
array | $options | options |
stdClass | repository instance record |
testing_data_generator::create_repository_type | ( | $type, | |
$record = null , |
|||
array | $options = null |
||
) |
Create an instance of a repository.
string | type of repository to create an instance for. | |
array | stdClass | $record | data to use to up set the instance. |
array | $options | options |
repository_type | object |
testing_data_generator::create_role | ( | $record = null | ) |
Creates a new role in the system.
You can fill $record with the role 'name', 'shortname', 'description' and 'archetype'.
If an archetype is specified it's capabilities, context where the role can be assigned and all other properties are copied from the archetype; if no archetype is specified it will create an empty role.
array | stdClass | $record |
int | The new role id |
testing_data_generator::create_scale | ( | $record = null , |
|
array | $options = null |
||
) |
Create a test scale.
array | stdClass | $record | |
array | $options |
stdClass | block instance record |
testing_data_generator::create_tag | ( | $record = null | ) |
Create a tag.
array | stdClass | $record |
stdClass | the tag record |
testing_data_generator::create_user | ( | $record = null , |
|
array | $options = null |
||
) |
Create a test user.
array | stdClass | $record | |
array | $options |
stdClass | user record |
testing_data_generator::enrol_user | ( | $userid, | |
$courseid, | |||
$roleidorshortname = null , |
|||
$enrol = 'manual' , |
|||
$timestart = 0 , |
|||
$timeend = 0 , |
|||
$status = null |
|||
) |
Simplified enrolment of user to course using default options.
It is strongly recommended to use only this method for 'manual' and 'self' plugins only!!!
int | $userid | |
int | $courseid | |
int | string | $roleidorshortname | optional role id or role shortname, use only with manual plugin |
string | $enrol | name of enrol plugin, there must be exactly one instance in course, it must support enrol_user() method. |
int | $timestart | (optional) 0 means unknown |
int | $timeend | (optional) 0 means forever |
int | $status | (optional) default to ENROL_USER_ACTIVE for new enrolments |
bool | success |
testing_data_generator::get_plugin_generator | ( | $component | ) |
Return generator for given plugin or component.
string | $component | the component name, e.g. 'mod_forum' or 'core_question'. |
component_generator_base | or rather an instance of the appropriate subclass. |
testing_data_generator::reset | ( | ) |
To be called from data reset code only, do not use in tests.
void |
testing_data_generator::role_assign | ( | $roleid, | |
$userid, | |||
$contextid = false |
|||
) |
Assigns the specified role to a user in the context.
int | $roleid | |
int | $userid | |
int | $contextid | Defaults to the system context |
int | new/existing id of the assignment |
array testing_data_generator::$firstnames |
lis of common first names
array testing_data_generator::$lastnames |
lis of common last names