Permalink
Browse files

Merge pull request #171 from proofek/GH-169

Gh 169 Added 2 new steps to verify that text matching specified pattern appears or not appears on a page
  • Loading branch information...
2 parents f8cde50 + 094bfc7 commit 588f6807226e4adec5dc825b853505b762ff1cde @everzet everzet committed Jan 22, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 src/Behat/Mink/Behat/Context/BaseMinkContext.php
@@ -362,6 +362,40 @@ public function assertPageNotContainsText($text)
}
/**
+ * Checks, that page contains text matching specified pattern.
+ *
+ * @Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/
+ */
+ public function assertPageMatchesText($pattern)
+ {
+ $actual = $this->getSession()->getPage()->getText();
+
+ try {
+ assertRegExp($pattern, $actual);
+ } catch (AssertException $e) {
+ $message = sprintf('The pattern %s was not found anywhere in the text of the current page.', $pattern);
+ throw new ResponseTextException($message, $this->getSession(), $e);
+ }
+ }
+
+ /**
+ * Checks, that page doesn't contain text matching specified pattern.
+ *
+ * @Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/
+ */
+ public function assertPageNotMatchesText($pattern)
+ {
+ $actual = $this->getSession()->getPage()->getText();
+
+ try {
+ assertNotRegExp($pattern, $actual);
+ } catch (AssertException $e) {
+ $message = sprintf('The pattern %s was found in the text of the current page, but it should not.', $pattern);
+ throw new ResponseTextException($message, $this->getSession(), $e);
+ }
+ }
+
+ /**
* Checks, that HTML response contains specified string.
*
* @Then /^the response should contain "(?P<text>(?:[^"]|\\")*)"$/

0 comments on commit 588f680

Please sign in to comment.