diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index ce0065cb4d8..99054049c55 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -681,4 +681,28 @@ class behat_general extends behat_base { $this->getSession()); } } + + /** + * Checks that the attribute on the given element does not contain the specified text. + * + * @Then /^the "(?P[^"]*)" attribute of "(?P(?:[^"]|\\")*)" "(?P[^"]*)" should not contain "(?P(?:[^"]|\\")*)"$/ + * @throws ExpectationException + * @param string $attribute Name of attribute + * @param string $element The locator of the specified selector + * @param string $selectortype The selector type + * @param string $text Expected substring + */ + public function the_attribute_of_should_not_contain($attribute, $element, $selectortype, $text) { + // Get the container node (exception if it doesn't exist). + $containernode = $this->get_selected_node($selectortype, $element); + $value = $containernode->getAttribute($attribute); + if ($value == null) { + throw new ExpectationException('The attribute "' . $attribute. '" does not exist', + $this->getSession()); + } else if (strpos($value, $text) !== false) { + throw new ExpectationException('The attribute "' . $attribute . + '" contains "' . $text . '" (value: "' . $value . '")', + $this->getSession()); + } + } }