diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 932dec3a355..06c58b2bf0f 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -212,6 +212,31 @@ class behat_forms extends behat_base { } } + /** + * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. + * + * @Then /^the field with xpath "(?P(?:[^"]|\\")*)" matches value "(?P(?:[^"]|\\")*)"$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $fieldxpath + * @param string $value + * @return void + */ + public function the_field_with_xpath_matches_value($fieldxpath, $value) { + + // Get the field. + $fieldnode = $this->find('xpath', $fieldxpath); + $formfield = behat_field_manager::get_form_field($fieldnode, $this->getSession()); + + // Checks if the provided value matches the current field value. + if (!$formfield->matches($value)) { + $fieldvalue = $formfield->get_value(); + throw new ExpectationException( + 'The \'' . $fieldxpath . '\' value is \'' . $fieldvalue . '\', \'' . $value . '\' expected' , + $this->getSession() + ); + } + } + /** * Checks, the field does not match the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. *