MDL-66550 behat: Transform fields to search in a fieldset

This commit is contained in:
Andrew Nicols
2019-09-10 21:24:20 +08:00
parent 0c7478e4fa
commit 85b30e2ac5
+23
View File
@@ -27,6 +27,7 @@ require_once(__DIR__ . '/exact_named_selector.php');
require_once(__DIR__ . '/partial_named_selector.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Element\Element;
/**
* Moodle selectors manager.
@@ -93,4 +94,26 @@ class behat_selectors {
behat_context_helper::escape($locator),
];
}
/**
* Transform the selector for a field.
*
* @param string $label The label to find
* @param Element $container The container to look within
* @return array The selector, locator, and container to search within
*/
public static function transform_find_for_field(behat_base $context, string $label, Element $container): array {
$hasfieldset = strpos($label, '>');
if (false !== $hasfieldset) {
list($containerlabel, $label) = explode(">", $label, 2);
$container = $context->find_fieldset(trim($containerlabel), $container);
$label = trim($label);
}
return [
'selector' => 'named_partial',
'locator' => self::normalise_named_selector('field', $label),
'container' => $container,
];
}
}