Merge pull request #2756 from madmatt/pulls/behat-form-context

Update theHtmlFieldShouldContain step to include negation.
This commit is contained in:
Ingo Schommer 2014-01-30 18:09:55 -08:00
commit 91b363b141

View File

@ -89,20 +89,32 @@ class CmsFormsContext extends BehatContext {
}
/**
* @Then /^the "(?P<locator>([^"]*))" HTML field should contain "(?P<html>.*)"$/
* @Then /^the "(?P<locator>([^"]*))" HTML field should(?P<negative> not? |\s*)contain "(?P<html>.*)"$/
*/
public function theHtmlFieldShouldContain($locator, $html) {
public function theHtmlFieldShouldContain($locator, $negative, $html) {
$page = $this->getSession()->getPage();
$element = $page->findField($locator);
assertNotNull($element, sprintf('HTML field "%s" not found', $locator));
$actual = $element->getValue();
$regex = '/'.preg_quote($html, '/').'/ui';
$failed = false;
if(trim($negative)) {
if (preg_match($regex, $actual)) {
$failed = true;
}
} else {
if (!preg_match($regex, $actual)) {
$failed = true;
}
}
if($failed) {
$message = sprintf(
'The string "%s" was not found in the HTML of the element matching %s "%s". Actual content: "%s"',
'The string "%s" should%sbe found in the HTML of the element matching name "%s". Actual content: "%s"',
$html,
'named',
$negative,
$locator,
$actual
);