Skip to content

Commit

Permalink
MDL-33671 behat: Check current fieldtype and parent
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 5, 2020
1 parent ff1a103 commit 0e09bc9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/behat/behat_field_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ protected static function get_field_node_type(NodeElement $fieldnode, Session $s
// 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]'))) {
Expand All @@ -236,6 +233,12 @@ protected static function get_field_node_type(NodeElement $fieldnode, Session $s
// 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) {
Expand All @@ -252,6 +255,20 @@ protected static function get_field_node_type(NodeElement $fieldnode, Session $s
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.
*
Expand Down

0 comments on commit 0e09bc9

Please sign in to comment.