Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
behat_data_generators Class Reference

Class to set up quickly a Given environment. More...

Inheritance diagram for behat_data_generators:
behat_base behat_session_interface

Public Member Functions

 get_all_entities ()
 Get all entities that can be created in all components using the_following_entities_exist()
 
 get_entity (string $entitytype)
 Get the required fields for a specific creatable entity.
 
 getSession ($name=null)
 Returns the Mink session.
 
 the_following_entities_exist ($entitytype, TableNode $data)
 Creates the specified elements.
 
 the_following_entity_exists ($entitytype, TableNode $data)
 Creates the specified (singular) element.
 
 the_following_repeated_entities_exist (string $entitytype, int $count, TableNode $data)
 Create multiple entities of one entity type.
 

Public Attributes

const PAGE_READY_JS
 The JS code to check that the page is ready.
 

Protected Member Functions

 get_instance_for_component (string $component)
 Get an instance of the appropriate subclass of this class for a given component.
 
 parse_entity_type (string $entitytype)
 Parse a full entity type like 'users' or 'mod_forum > subscription'.
 

Protected Attributes

array $movedentitytypes
 Convert legacy entity names to the new component-specific form.
 

Detailed Description

Class to set up quickly a Given environment.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

The entry point is the Behat steps: the following "entity types" exist: | test | data |

Entity type will either look like "users" or "activities" for core entities, or "mod_forum > subscription" or "core_message > message" for entities belonging to components.

Generally, you only need to specify properties relevant to your test, and everything else gets set to sensible defaults.

The actual generation of entities is done by behat_generator_base. There is one subclass for each component, e.g. behat_core_generator or behat_mod_quiz_generator. To see the types of entity that can be created for each component, look at the arrays returned by the get_creatable_entities() method in each class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ get_all_entities()

behat_data_generators::get_all_entities ( )

Get all entities that can be created in all components using the_following_entities_exist()

Return values
array
Exceptions
coding_exception

◆ get_entity()

behat_data_generators::get_entity ( string $entitytype)

Get the required fields for a specific creatable entity.

Parameters
string$entitytype
Return values
mixed
Exceptions
coding_exception

◆ get_instance_for_component()

behat_data_generators::get_instance_for_component ( string $component)
protected

Get an instance of the appropriate subclass of this class for a given component.

Parameters
string$componentThe name of the component to generate entities for.
Return values
behat_generator_basethe subclass of this class for the requested component.

◆ getSession()

behat_session_interface::getSession ( $name = null)
inherited

Returns the Mink session.

Parameters
string | null$namename of the session OR active session will be used
Return values
Behat\Mink\Session

Implemented in behat_form_field.

◆ parse_entity_type()

behat_data_generators::parse_entity_type ( string $entitytype)
protected

Parse a full entity type like 'users' or 'mod_forum > subscription'.

E.g. parsing 'course' gives ['core', 'course'] and parsing 'core_message > message' gives ['core_message', 'message'].

Parameters
string$entitytypethe entity type
Return values
string[]with two elements, component and entity type.

◆ the_following_entities_exist()

behat_data_generators::the_following_entities_exist ( $entitytype,
TableNode $data )

Creates the specified elements.

See the class comment for an overview.

@Given /^the following "(?P<element_string>(?:[^"]|::")*)" exist:$/

Parameters
string$entitytypeThe name of the type entity to add
TableNode$data

◆ the_following_entity_exists()

behat_data_generators::the_following_entity_exists ( $entitytype,
TableNode $data )

Creates the specified (singular) element.

See the class comment for an overview.

@Given the following :entitytype exists:

Parameters
string$entitytypeThe name of the type entity to add
TableNode$data

◆ the_following_repeated_entities_exist()

behat_data_generators::the_following_repeated_entities_exist ( string $entitytype,
int $count,
TableNode $data )

Create multiple entities of one entity type.

@Given :count :entitytype exist with the following data:

Parameters
string$entitytypeThe name of the type entity to add
int$count
TableNode$data

Member Data Documentation

◆ $movedentitytypes

array behat_data_generators::$movedentitytypes
protected
Initial value:
= [
]

Convert legacy entity names to the new component-specific form.

In the past, there was no support for plugins, and everything that could be created was handled by the core generator. Now, we can support plugins, and so some thing should probably be moved.

For example, in the future we should probably add 'message contacts' => 'core_message > contact'] to this array, and move generation of message contact from core to core_message.

old entity type => new entity type.

◆ PAGE_READY_JS

const behat_session_interface::PAGE_READY_JS
inherited
Initial value:
= "document.readyState === 'complete' && " .
"(typeof M !== 'object' || typeof M.util !== 'object' || " .
"typeof M.util.pending_js === 'undefined' || M.util.pending_js.length === 0)"

The JS code to check that the page is ready.

The document must be complete and either M.util.pending_js must be empty, or it must not be defined at all.


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