Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401] [Versions 401 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: 7 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.

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

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

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

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

param: string $value
return: void

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.

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

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

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

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.

param: NodeElement $element The node element
return: behat_form_field

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.

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

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...).

param: string $locatortype
return: string