Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
behat_core_generator Class Reference
Inheritance diagram for behat_core_generator:
behat_generator_base

Public Member Functions

 generate_items (string $generatortype, TableNode $data, bool $singular=false)
 Do the work to generate an entity. More...
 

Protected Member Functions

 get_category_id ($idnumber)
 Gets the category id from it's idnumber. More...
 
 get_cohort_id ($idnumber)
 Gets the cohort id from it's idnumber. More...
 
 get_contact_id ($username)
 Gets the contact id from it's username. More...
 
 get_context ($levelname, $contextref)
 Gets the internal context id from the context reference. More...
 
 get_course_id ($shortname)
 Gets the course id from it's shortname. More...
 
 get_creatable_entities ()
 Get a list of the entities that can be created for this component. More...
 
 get_gradecategory_id ($fullname)
 Gets the grade category id from the grade category fullname. More...
 
 get_group_id ($idnumber)
 Gets the group id from it's idnumber. More...
 
 get_grouping_id ($idnumber)
 Gets the grouping id from it's idnumber. More...
 
 get_outcome_id ($shortname)
 Gets the outcome item id from its shortname. More...
 
 get_questioncategory_id ($name)
 Get the id of a named question category (must be globally unique). More...
 
 get_role_id ($roleshortname)
 Gets the role id from it's shortname. More...
 
 get_scale_id ($name)
 Get the id of a named scale. More...
 
 get_user_id ($username)
 Gets the user id from it's username. More...
 
 name_for_errors (string $entitytype)
 Helper for formatting error messages. More...
 
 preprocess_analytics_model ($data)
 Transform indicators string into array. More...
 
 preprocess_cohort ($data)
 If contextlevel and reference are specified for cohort, transform them to the contextid. More...
 
 preprocess_course ($data)
 Remove any empty custom fields, to avoid errors when creating the course. More...
 
 preprocess_grade_item ($data)
 Preprocesses the creation of a grade item. More...
 
 preprocess_user ($data)
 If password is not set it uses the username. More...
 
 process_activity ($data)
 Adapter to modules generator. More...
 
 process_analytics_model ($data)
 Creates an analytics model. More...
 
 process_block_instance ($data)
 Add a block to a page. More...
 
 process_cohort_member ($data)
 Adds members to cohorts. More...
 
 process_customlang ($data)
 Creates language customisation. More...
 
 process_enrol_user ($data)
 Adapter to enrol_user() data generator. More...
 
 process_favourite_conversations (array $data)
 Mark a private conversation as favourite for user. More...
 
 process_group_messages (array $data)
 Send a new message from user to a group conversation. More...
 
 process_message_contacts ($data)
 Adds user to contacts. More...
 
 process_mute_group_conversations (array $data)
 Mute an existing group conversation for user. More...
 
 process_mute_private_conversations (array $data)
 Mute a private conversation for user. More...
 
 process_permission_override ($data)
 Allows/denies a capability at the specified context. More...
 
 process_private_messages (array $data)
 Send a new message from user to contact in a private conversation. More...
 
 process_question ($data)
 Create a question. More...
 
 process_question_category ($data)
 Create a question category. More...
 
 process_role ($data)
 Creates a role. More...
 
 process_role_assign ($data)
 Assigns a role to a user at the specified context. More...
 
 process_system_role_assign ($data)
 Assigns a role to a user at system context. More...
 
 process_user_preferences (array $data)
 Set a preference value for user. More...
 

Protected Attributes

string $component
 the name of the component we belong to. More...
 
testing_data_generator $componentdatagenerator
 the data generator for this component.
 
testing_data_generator $datagenerator
 the core data generator
 

Member Function Documentation

◆ generate_items()

behat_generator_base::generate_items ( string  $generatortype,
TableNode  $data,
bool  $singular = false 
)
inherited

Do the work to generate an entity.

This is called by behat_data_generators::the_following_entities_exist().

Parameters
string$generatortypeThe name of the entity to create.
TableNode$datafrom the step.
bool$singularWhether there is only one record and it is pivotted

◆ get_category_id()

behat_generator_base::get_category_id (   $idnumber)
protectedinherited

Gets the category id from it's idnumber.

Exceptions
Exception
Parameters
string$idnumber
Return values
int

◆ get_cohort_id()

behat_generator_base::get_cohort_id (   $idnumber)
protectedinherited

Gets the cohort id from it's idnumber.

Exceptions
Exception
Parameters
string$idnumber
Return values
int

◆ get_contact_id()

behat_generator_base::get_contact_id (   $username)
protectedinherited

Gets the contact id from it's username.

Exceptions
Exception
Parameters
string$username
Return values
int

◆ get_context()

behat_generator_base::get_context (   $levelname,
  $contextref 
)
protectedinherited

Gets the internal context id from the context reference.

The context reference changes depending on the context level, it can be the system, a user, a category, a course or a module.

Exceptions
Exception
Parameters
string$levelnameThe context level string introduced by the test writer
string$contextrefThe context reference introduced by the test writer
Return values
context

◆ get_course_id()

behat_generator_base::get_course_id (   $shortname)
protectedinherited

Gets the course id from it's shortname.

Exceptions
Exception
Parameters
string$shortname
Return values
int

◆ get_creatable_entities()

behat_core_generator::get_creatable_entities ( )
protected

Get a list of the entities that can be created for this component.

This function must be overridden in subclasses. See class comment above for a description of the data structure. See behat_core_generator for an example.

Return values
arrayentity name => information about how to generate.

Reimplemented from behat_generator_base.

◆ get_gradecategory_id()

behat_generator_base::get_gradecategory_id (   $fullname)
protectedinherited

Gets the grade category id from the grade category fullname.

Parameters
string$fullnamethe grade category name.
Return values
intcorresponding id.

◆ get_group_id()

behat_generator_base::get_group_id (   $idnumber)
protectedinherited

Gets the group id from it's idnumber.

Exceptions
Exception
Parameters
string$idnumber
Return values
int

◆ get_grouping_id()

behat_generator_base::get_grouping_id (   $idnumber)
protectedinherited

Gets the grouping id from it's idnumber.

Exceptions
Exception
Parameters
string$idnumber
Return values
int

◆ get_outcome_id()

behat_generator_base::get_outcome_id (   $shortname)
protectedinherited

Gets the outcome item id from its shortname.

Exceptions
Exception
Parameters
string$shortname
Return values
int

◆ get_questioncategory_id()

behat_generator_base::get_questioncategory_id (   $name)
protectedinherited

Get the id of a named question category (must be globally unique).

Note that 'Top' is a special value, used when setting the parent of another category, meaning top-level.

Parameters
string$namethe question category name.
Return values
intthe question category id.

◆ get_role_id()

behat_generator_base::get_role_id (   $roleshortname)
protectedinherited

Gets the role id from it's shortname.

Exceptions
Exception
Parameters
string$roleshortname
Return values
int

◆ get_scale_id()

behat_generator_base::get_scale_id (   $name)
protectedinherited

Get the id of a named scale.

Parameters
string$namethe name of the scale.
Return values
intthe scale id.

◆ get_user_id()

behat_generator_base::get_user_id (   $username)
protectedinherited

Gets the user id from it's username.

Exceptions
Exception
Parameters
string$username
Return values
int

◆ name_for_errors()

behat_generator_base::name_for_errors ( string  $entitytype)
protectedinherited

Helper for formatting error messages.

Parameters
string$entitytypeentity type without prefix, e.g. 'frog'.
Return values
stringeither 'frog' for core entities, or 'mod_mymod > frog' for components.

◆ preprocess_analytics_model()

behat_core_generator::preprocess_analytics_model (   $data)
protected

Transform indicators string into array.

Parameters
array$data
Return values
array

◆ preprocess_cohort()

behat_core_generator::preprocess_cohort (   $data)
protected

If contextlevel and reference are specified for cohort, transform them to the contextid.

Parameters
array$data
Return values
array

◆ preprocess_course()

behat_core_generator::preprocess_course (   $data)
protected

Remove any empty custom fields, to avoid errors when creating the course.

Parameters
array$data
Return values
array

◆ preprocess_grade_item()

behat_core_generator::preprocess_grade_item (   $data)
protected

Preprocesses the creation of a grade item.

Converts gradetype text to a number.

Parameters
array$data
Return values
array

◆ preprocess_user()

behat_core_generator::preprocess_user (   $data)
protected

If password is not set it uses the username.

Parameters
array$data
Return values
array

◆ process_activity()

behat_core_generator::process_activity (   $data)
protected

Adapter to modules generator.

Exceptions
ExceptionCustom exception for test writers
Parameters
array$data
Return values
void

◆ process_analytics_model()

behat_core_generator::process_analytics_model (   $data)
protected

Creates an analytics model.

Parameters
target$data
Return values
void

◆ process_block_instance()

behat_core_generator::process_block_instance (   $data)
protected

Add a block to a page.

Parameters
array$datashould mostly match the fields of the block_instances table. The block type is specified by blockname. The parentcontextid is set from contextlevel and reference. Missing values are filled in by testing_block_generator::prepare_record. $data is passed to create_block as both $record and $options. Normally the keys are different, so this is a way to let people set values in either place.

◆ process_cohort_member()

behat_core_generator::process_cohort_member (   $data)
protected

Adds members to cohorts.

Parameters
array$data
Return values
void

◆ process_customlang()

behat_core_generator::process_customlang (   $data)
protected

Creates language customisation.

Exceptions
Exception
dml_exception
Parameters
array$data
Return values
void

◆ process_enrol_user()

behat_core_generator::process_enrol_user (   $data)
protected

Adapter to enrol_user() data generator.

Exceptions
Exception
Parameters
array$data
Return values
void

◆ process_favourite_conversations()

behat_core_generator::process_favourite_conversations ( array  $data)
protected

Mark a private conversation as favourite for user.

Parameters
array$data
Return values
void

◆ process_group_messages()

behat_core_generator::process_group_messages ( array  $data)
protected

Send a new message from user to a group conversation.

Parameters
array$data
Return values
void

◆ process_message_contacts()

behat_core_generator::process_message_contacts (   $data)
protected

Adds user to contacts.

Parameters
array$data
Return values
void

◆ process_mute_group_conversations()

behat_core_generator::process_mute_group_conversations ( array  $data)
protected

Mute an existing group conversation for user.

Parameters
array$data
Return values
void

◆ process_mute_private_conversations()

behat_core_generator::process_mute_private_conversations ( array  $data)
protected

Mute a private conversation for user.

Parameters
array$data
Return values
void

◆ process_permission_override()

behat_core_generator::process_permission_override (   $data)
protected

Allows/denies a capability at the specified context.

Exceptions
Exception
Parameters
array$data
Return values
void

◆ process_private_messages()

behat_core_generator::process_private_messages ( array  $data)
protected

Send a new message from user to contact in a private conversation.

Parameters
array$data
Return values
void

◆ process_question()

behat_core_generator::process_question (   $data)
protected

Create a question.

Creating questions relies on the question/type/.../tests/helper.php mechanism. We start with test_question_maker::get_question_form_data($data['qtype'], $data['template']) and then overlay the values from any other fields of $data that are set.

There is a special case that allows you to set qtype to 'missingtype'. This creates an example of broken question, such as you might get if you install a question type, create some questions of that type, and then uninstall the question type (which is prevented through the UI but can still happen). This special lets tests verify that these questions are handled OK.

Parameters
array$datathe row of data from the behat script.

◆ process_question_category()

behat_core_generator::process_question_category (   $data)
protected

Create a question category.

Parameters
array$datathe row of data from the behat script.

◆ process_role()

behat_core_generator::process_role (   $data)
protected

Creates a role.

Parameters
array$data
Return values
void

◆ process_role_assign()

behat_core_generator::process_role_assign (   $data)
protected

Assigns a role to a user at the specified context.

Exceptions
Exception
Parameters
array$data
Return values
void

◆ process_system_role_assign()

behat_core_generator::process_system_role_assign (   $data)
protected

Assigns a role to a user at system context.

Used by "system role assigns" can be deleted when system role assign will be deprecated in favour of "role assigns"

Exceptions
Exception
Parameters
array$data
Return values
void

◆ process_user_preferences()

behat_core_generator::process_user_preferences ( array  $data)
protected

Set a preference value for user.

Parameters
array$data
Return values
void

Member Data Documentation

◆ $component

string behat_generator_base::$component
protectedinherited

the name of the component we belong to.

This should probably only be used to make error messages clearer.


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