diff --git a/lib/behat/behat_field_manager.php b/lib/behat/behat_field_manager.php index 8e4e6d4f4a8..6d9b4c7a7ea 100644 --- a/lib/behat/behat_field_manager.php +++ b/lib/behat/behat_field_manager.php @@ -223,10 +223,7 @@ class behat_field_manager { // If the type is explictly set on the element pointed to by the label - use it. $fieldtype = $fieldnode->getAttribute('data-fieldtype'); if ($fieldtype) { - if ($fieldtype == 'tags') { - return 'autocomplete'; - } - return $fieldtype; + return self::normalise_fieldtype($fieldtype); } if (!empty($fieldnode->find('xpath', '/ancestor::*[@data-passwordunmaskid]'))) { @@ -236,6 +233,12 @@ class behat_field_manager { // Fetch the parentnode only once. $parentnode = $fieldnode->getParent(); + // Check the parent fieldtype before we check classes. + $fieldtype = $parentnode->getAttribute('data-fieldtype'); + if ($fieldtype) { + return self::normalise_fieldtype($fieldtype); + } + // We look for a parent node with 'felement' class. if ($class = $parentnode->getAttribute('class')) { if (strstr($class, 'felement') != false) { @@ -252,6 +255,20 @@ class behat_field_manager { return self::get_field_node_type($parentnode, $session); } + /** + * Normalise the field type. + * + * @param string $fieldtype + * @return string + */ + protected static function normalise_fieldtype(string $fieldtype): string { + if ($fieldtype === 'tags') { + return 'autocomplete'; + } + + return $fieldtype; + } + /** * Gets an instance of the form field. *