Skip to content

Commit

Permalink
Add fieldValueMatches / fieldValueNotMatches
Browse files Browse the repository at this point in the history
Would be hand to allow pattern assertions on field values like on the page text.
This was mentioned here #696 but: "PR got lost in the sands of time" :)
  • Loading branch information
das-peter authored May 24, 2019
1 parent 6d637f7 commit 8050501
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/WebAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,44 @@ public function fieldValueNotEquals($field, $value, TraversableElement $containe
$this->assert(!preg_match($regex, $actual), $message);
}

/**
* Checks that specific field matches provided regex.
*
* @param string $field field id|name|label|value
* @param string $regex pattern
* @param TraversableElement $container document to check against
*
* @throws ExpectationException
*/
public function fieldValueMatches($field, $regex, TraversableElement $container = null)
{
$node = $this->fieldExists($field, $container);
$actual = $node->getValue();

$message = sprintf('The pattern "%s" was not found in the value "%s" of field "%s".', $regex, $actual, $field);

$this->assert((bool) preg_match($regex, $actual), $message);
}

/**
* Checks that specific field have provided value.
*
* @param string $field field id|name|label|value
* @param string $regex pattern
* @param TraversableElement $container document to check against
*
* @throws ExpectationException
*/
public function fieldValueNotMatches($field, $regex, TraversableElement $container = null)
{
$node = $this->fieldExists($field, $container);
$actual = $node->getValue();

$message = sprintf('The pattern "%s" was found in the value "%s" of field "%s", but it should not.', $regex, $actual, $field);

$this->assert((bool) preg_match($regex, $actual), $message);
}

/**
* Checks that specific checkbox is checked.
*
Expand Down

0 comments on commit 8050501

Please sign in to comment.