Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Public Attributes | Protected Attributes | List of all members
testing_data_generator Class Reference

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
 

Member Function Documentation

◆ combine_defaults_and_record()

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.

Parameters
array$defaultsthe default value for each field with
array | stdClass$record
Return values
arrayupdated $record.

◆ create_and_enrol()

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.

Parameters
stdClass$courseThe course to enrol in
string$roleThe role to give within the course
stdClass$userparamsUser parameters
Return values
stdClassThe created user

◆ create_block()

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.

Parameters
string$blocknamethe type of block to create. E.g. 'html'.
array | stdClass$recordforms the basis for the entry to be inserted in the block_instances table.
array$optionsfurther, block-specific options to control how the block is created.
Return values
stdClassnew block_instance record.

◆ create_category()

testing_data_generator::create_category (   $record = null,
array  $options = null 
)

Create a test course category.

Parameters
array | stdClass$record
array$options
Return values
core_course_categorycourse category record

◆ create_cohort()

testing_data_generator::create_cohort (   $record = null,
array  $options = null 
)

Create test cohort.

Parameters
array | stdClass$record
array$options
Return values
stdClasscohort record

◆ create_course()

testing_data_generator::create_course (   $record = null,
array  $options = null 
)

Create a test course.

Parameters
array | stdClass$record
array$optionswith keys: 'createsections'=>bool precreate all sections
Return values
stdClasscourse record

◆ create_course_section()

testing_data_generator::create_course_section (   $record = null,
array  $options = null 
)

Create course section if does not exist yet.

Parameters
array | stdClass$recordmust contain 'course' and 'section' attributes
array | null$options
Return values
stdClass
Exceptions
coding_exception

◆ create_custom_field()

testing_data_generator::create_custom_field (   $data)

Create a new custom field.

Parameters
array$dataArray with 'name', 'shortname' and 'type' of the field
Return values
core_customfield

◆ create_custom_field_category()

testing_data_generator::create_custom_field_category (   $data)

Create a new course custom field category with the given name.

Parameters
array$dataArray with data['name'] of category
Return values
core_customfield

◆ create_event()

testing_data_generator::create_event (   $data = [])

Helper function used to create an event.

Parameters
array$data
Return values
stdClass

◆ create_grade_category()

testing_data_generator::create_grade_category (   $record = null)

Create a grade_category.

Parameters
array | stdClass$record
Return values
stdClassthe grade category record

◆ create_grade_item()

testing_data_generator::create_grade_item (   $record = null)

Create a grade_item.

Parameters
array | stdClass$record
Return values
stdClassthe grade item record

◆ create_grade_outcome()

testing_data_generator::create_grade_outcome (   $record = null)

Create a grade_outcome.

Parameters
array | stdClass$record
Return values
stdClassthe grade outcome record

◆ create_group()

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.

See also
groups_create_group
Parameters
array | stdClass$record
Return values
stdClassgroup record

◆ create_group_member()

testing_data_generator::create_group_member (   $record)

Create a test group member.

Parameters
array | stdClass$record
Exceptions
coding_exception
Return values
boolean

◆ create_grouping()

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.

See also
groups_create_grouping
Parameters
array | stdClass$record
Return values
stdClassgrouping record

◆ create_grouping_group()

testing_data_generator::create_grouping_group (   $record)

Create a test grouping group.

Parameters
array | stdClass$record
Exceptions
coding_exception
Return values
boolean

◆ create_lti_tool()

testing_data_generator::create_lti_tool (   $data = array())

Helper function used to create an LTI tool.

Parameters
array$data
Return values
stdClassthe tool

◆ create_module()

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.

Parameters
string$modulenamethe type of activity to create. E.g. 'forum' or 'quiz'.
array | stdClass$recorddata, as if from the module edit settings form.
array$optionsadditional data that may affect how the module is created.
Return values
stdClassactivity record new new record that was just inserted in the table like 'forum' or 'quiz', with a ->cmid field added.

◆ create_repository()

testing_data_generator::create_repository (   $type,
  $record = null,
array  $options = null 
)

Create an instance of a repository.

Parameters
stringtype of repository to create an instance for.
array | stdClass$recorddata to use to up set the instance.
array$optionsoptions
Return values
stdClassrepository instance record
Since
Moodle 2.5.1

◆ create_repository_type()

testing_data_generator::create_repository_type (   $type,
  $record = null,
array  $options = null 
)

Create an instance of a repository.

Parameters
stringtype of repository to create an instance for.
array | stdClass$recorddata to use to up set the instance.
array$optionsoptions
Return values
repository_typeobject
Since
Moodle 2.5.1

◆ create_role()

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.

Parameters
array | stdClass$record
Return values
intThe new role id

◆ create_scale()

testing_data_generator::create_scale (   $record = null,
array  $options = null 
)

Create a test scale.

Parameters
array | stdClass$record
array$options
Return values
stdClassblock instance record

◆ create_tag()

testing_data_generator::create_tag (   $record = null)

Create a tag.

Parameters
array | stdClass$record
Return values
stdClassthe tag record

◆ create_user()

testing_data_generator::create_user (   $record = null,
array  $options = null 
)

Create a test user.

Parameters
array | stdClass$record
array$options
Return values
stdClassuser record

◆ enrol_user()

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!!!

Parameters
int$userid
int$courseid
int | string$roleidorshortnameoptional role id or role shortname, use only with manual plugin
string$enrolname 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
Return values
boolsuccess

◆ get_plugin_generator()

testing_data_generator::get_plugin_generator (   $component)

Return generator for given plugin or component.

Parameters
string$componentthe component name, e.g. 'mod_forum' or 'core_question'.
Return values
component_generator_baseor rather an instance of the appropriate subclass.

◆ reset()

testing_data_generator::reset ( )

To be called from data reset code only, do not use in tests.

Return values
void

◆ role_assign()

testing_data_generator::role_assign (   $roleid,
  $userid,
  $contextid = false 
)

Assigns the specified role to a user in the context.

Parameters
int$roleid
int$userid
int$contextidDefaults to the system context
Return values
intnew/existing id of the assignment

Member Data Documentation

◆ $firstnames

array testing_data_generator::$firstnames
Initial value:
= array(
'Jacob', 'Ethan', 'Michael', 'Jayden', 'William', 'Isabella', 'Sophia', 'Emma', 'Olivia', 'Ava',
'Lukas', 'Leon', 'Luca', 'Timm', 'Paul', 'Leonie', 'Leah', 'Lena', 'Hanna', 'Laura',
'Jakub', 'Jan', 'Tomáš', 'Lukáš', 'Matěj', 'Tereza', 'Eliška', 'Anna', 'Adéla', 'Karolína',
'Даниил', 'Максим', 'Артем', 'Иван', 'Александр', 'София', 'Анастасия', 'Дарья', 'Мария', 'Полина',
'伟', '伟', '芳', '伟', '秀英', '秀英', '娜', '秀英', '伟', '敏',
'翔', '大翔', '拓海', '翔太', '颯太', '陽菜', 'さくら', '美咲', '葵', '美羽',
)

lis of common first names

◆ $lastnames

array testing_data_generator::$lastnames
Initial value:
= array(
'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'García', 'Rodríguez', 'Wilson',
'Müller', 'Schmidt', 'Schneider', 'Fischer', 'Meyer', 'Weber', 'Schulz', 'Wagner', 'Becker', 'Hoffmann',
'Novák', 'Svoboda', 'Novotný', 'Dvořák', 'Černý', 'Procházková', 'Kučerová', 'Veselá', 'Horáková', 'Němcová',
'Смирнов', 'Иванов', 'Кузнецов', 'Соколов', 'Попов', 'Лебедева', 'Козлова', 'Новикова', 'Морозова', 'Петрова',
'王', '李', '张', '刘', '陈', '楊', '黃', '趙', '吳', '周',
'佐藤', '鈴木', '高橋', '田中', '渡辺', '伊藤', '山本', '中村', '小林', '斎藤',
)

lis of common last names


The documentation for this class was generated from the following file: