MDL-47410 behat: Move logic from guess_type() to a separate method
Moves the logic from guess_type() to a separate protected method get_field_instance_for_element(). This would be quite useful for form field classes as they can now use this method when there is a need to determine the type of a given node element.
This commit is contained in:
@@ -173,17 +173,28 @@ class behat_form_field implements behat_session_interface {
|
||||
* @return behat_form_field
|
||||
*/
|
||||
private function guess_type() {
|
||||
return $this->get_field_instance_for_element($this->field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate form field object for a given node element.
|
||||
*
|
||||
* @param NodeElement $element The node element
|
||||
* @return behat_form_field
|
||||
*/
|
||||
protected function get_field_instance_for_element(NodeElement $element): behat_form_field {
|
||||
global $CFG;
|
||||
|
||||
// We default to the text-based field if nothing was detected.
|
||||
if (!$type = behat_field_manager::guess_field_type($this->field, $this->session)) {
|
||||
if (!$type = behat_field_manager::guess_field_type($element, $this->session)) {
|
||||
$type = 'text';
|
||||
}
|
||||
|
||||
$classname = 'behat_form_' . $type;
|
||||
$classpath = $CFG->dirroot . '/lib/behat/form_field/' . $classname . '.php';
|
||||
require_once($classpath);
|
||||
return new $classname($this->session, $this->field);
|
||||
|
||||
return new $classname($this->session, $element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user