Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 403]

Generic moodleforms field.

Copyright: 2012 David MonllaĆ³
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 329 lines (11 kb)
Included or required: 6 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

behat_form_field:: (14 methods):
  getSession()
  __construct()
  set_value()
  get_value()
  key_press()
  matches()
  get_attribute()
  guess_type()
  get_field_instance_for_element()
  running_javascript()
  wait_for_pending_js()
  get_internal_field_id()
  text_matches()
  get_field_locator()


Class: behat_form_field  - X-Ref

Representation of a form field.

Basically an interface with Mink session.

getSession($name = null)   X-Ref
Returns the Mink session.

return: \Behat\Mink\Session
param: string|null $name name of the session OR active session will be used

__construct(Session $session, NodeElement $fieldnode)   X-Ref
General constructor with the node and the session to interact with.

return: void
param: Session $session Reference to Mink session to traverse/modify the page DOM.
param: NodeElement $fieldnode The field DOM node

set_value($value)   X-Ref
Sets the value to a field.

return: void
param: string $value

get_value()   X-Ref
Returns the current value of the select element.

return: string

key_press($char, $modifier = null)   X-Ref
Presses specific keyboard key.

param: mixed  $char     could be either char ('b') or char-code (98)
param: string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')

matches($expectedvalue)   X-Ref
Generic match implementation

Will work well with text-based fields, extension required
for most of the other cases.

return: bool The provided value matches the field value?
param: string $expectedvalue

get_attribute($name)   X-Ref
Get the value of an attribute set on this field.

return: string The attribute value
param: string $name The attribute name

guess_type()   X-Ref
Guesses the element type we are dealing with in case is not a text-based element.

This class is the generic field type, behat_field_manager::get_form_field()
should be able to find the appropiate class for the field type, but
in cases like moodle form group elements we can not find the type of
the field through the DOM so we also need to take care of the
different field types from here. If we need to deal with more complex
moodle form elements we will need to refactor this simple HTML elements
guess method.

return: behat_form_field

get_field_instance_for_element(NodeElement $element)   X-Ref
Returns the appropriate form field object for a given node element.

return: behat_form_field
param: NodeElement $element The node element

running_javascript()   X-Ref
Returns whether the scenario is running in a browser that can run Javascript or not.

return: bool

wait_for_pending_js()   X-Ref
Waits for all the JS activity to be completed.

return: bool Whether any JS is still pending completion.

get_internal_field_id()   X-Ref
Gets the field internal id used by selenium wire protocol.

Only available when running_javascript().

return: int

text_matches($expectedvalue, ?string $actualvalue = null)   X-Ref
Checks if the provided text matches the field value.

return: bool
param: string $expectedvalue
param: string|null $actualvalue The actual value. If not specified, this will be fetched from $this->get_value().

get_field_locator($locatortype = false)   X-Ref
Gets the field locator.

Defaults to the field label but you can
specify other locators if you are interested.

Public visibility as in most cases will be hard to
use this method in a generic way, as fields can
be selected using multiple ways (label, id, name...).

return: string
param: string $locatortype