Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
behat_field_manager Class Reference

Helper to interact with form fields. More...

Static Public Member Functions

static get_field_instance ($type, NodeElement $fieldnode, Session $session)
 Returns the appropiate behat_form_field according to the provided type.
 
static get_form_field (NodeElement $fieldnode, Session $session)
 Gets an instance of the form field.
 
static get_form_field_from_label ($label, RawMinkContext $context)
 Gets an instance of the form field from it's label.
 
static guess_field_type (NodeElement $fieldnode, Session $session)
 Guesses a basic field type and returns it.
 

Static Protected Member Functions

static get_dom_elements_for_node (NodeElement $fieldnode, Session $session)
 Get the DOMDocument and DOMElement for a NodeElement.
 
static get_field_node_type (NodeElement $fieldnode, Session $session)
 Recursive method to find the field type.
 
static get_field_type (\DOMDocument $document, DOMElement $node, Session $session)
 Get the field type from the specified DOMElement.
 
static is_moodleform_field (NodeElement $fieldnode)
 Detects when the field is a moodleform field type.
 
static normalise_fieldtype (string $fieldtype)
 Normalise the field type.
 

Detailed Description

Helper to interact with form fields.

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

Member Function Documentation

◆ get_dom_elements_for_node()

static behat_field_manager::get_dom_elements_for_node ( NodeElement $fieldnode,
Session $session )
staticprotected

Get the DOMDocument and DOMElement for a NodeElement.

Parameters
NodeElement$fieldnode
Session$session
Return values
array

◆ get_field_instance()

static behat_field_manager::get_field_instance ( $type,
NodeElement $fieldnode,
Session $session )
static

Returns the appropiate behat_form_field according to the provided type.

It defaults to behat_form_field.

Parameters
string$typeThe field type (checkbox, date_selector, text...)
NodeElement$fieldnode
Session$sessionThe behat session
Return values
behat_form_field

◆ get_field_node_type()

static behat_field_manager::get_field_node_type ( NodeElement $fieldnode,
Session $session )
staticprotected

Recursive method to find the field type.

Depending on the field the felement class node is in a level or in another. We look recursively for a parent node with a 'felement' class to find the field type.

Parameters
NodeElement$fieldnodeThe current node.
Session$sessionThe behat browser session
Return values
null|stringA text description of the node type, or null if one could not be accurately determined

◆ get_field_type()

static behat_field_manager::get_field_type ( \DOMDocument $document,
DOMElement $node,
Session $session )
staticprotected

Get the field type from the specified DOMElement.

Parameters
DOMDocument$document
DOMElement$node
Session$session
Return values
null|string

◆ get_form_field()

static behat_field_manager::get_form_field ( NodeElement $fieldnode,
Session $session )
static

Gets an instance of the form field.

Not all the fields are part of a moodle form, in this cases it fallsback to the generic form field. Also note that this generic field type is using a generic setValue() method from the Behat API, which is not always good to set the value of form elements.

Parameters
NodeElement$fieldnode
Session$sessionThe behat browser session
Return values
behat_form_field

◆ get_form_field_from_label()

static behat_field_manager::get_form_field_from_label ( $label,
RawMinkContext $context )
static

Gets an instance of the form field from it's label.

Parameters
string$label
RawMinkContext$context
Return values
behat_form_field

◆ guess_field_type()

static behat_field_manager::guess_field_type ( NodeElement $fieldnode,
Session $session )
static

Guesses a basic field type and returns it.

This method is intended to detect HTML form fields when no moodleform-specific elements have been detected.

Parameters
NodeElement$fieldnode
Session$session
Return values
string|boolThe field type or false.

◆ is_moodleform_field()

static behat_field_manager::is_moodleform_field ( NodeElement $fieldnode)
staticprotected

Detects when the field is a moodleform field type.

Note that there are fields inside moodleforms that are not moodleform element; this method can not detect this, this will be managed by get_field_node_type, after failing to find the form element element type.

Parameters
NodeElement$fieldnode
Return values
bool

◆ normalise_fieldtype()

static behat_field_manager::normalise_fieldtype ( string $fieldtype)
staticprotected

Normalise the field type.

Parameters
string$fieldtype
Return values
string

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