diff --git a/README.md b/README.md index 1db2c84..baf3f9f 100644 --- a/README.md +++ b/README.md @@ -701,6 +701,12 @@ It's based on the `vendor/bin/behat -di @cms` output. Then /^the email should (not |)contain the following data:$/ Example: Then the email should contain the following data: + Then /^there should (not |)be an email titled "([^"]*)"$/ + + Then /^the email should (not |)be sent from "([^"]*)"$/ + + Then /^the email should (not |)be sent to "([^"]*)"$/ + ### Transformations Behat [transformations](http://docs.behat.org/guides/2.definitions.html#step-argument-transformations) diff --git a/src/SilverStripe/BehatExtension/Context/EmailContext.php b/src/SilverStripe/BehatExtension/Context/EmailContext.php index b6b815d..b1736db 100644 --- a/src/SilverStripe/BehatExtension/Context/EmailContext.php +++ b/src/SilverStripe/BehatExtension/Context/EmailContext.php @@ -236,4 +236,56 @@ class EmailContext extends BehatContext } } } + + /** + * @Then /^there should (not |)be an email titled "([^"]*)"$/ + */ + public function thereIsAnEmailTitled($negate, $subject) + { + $match = $this->mailer->findEmail(null, null, $subject); + if(trim($negate)) { + assertNull($match); + } else { + $msg = sprintf( + 'Could not find email titled "%s".', + $subject + ); + assertNotNull($match,$msg); + } + $this->lastMatchedEmail = $match; + } + + /** + * @Then /^the email should (not |)be sent from "([^"]*)"$/ + */ + public function theEmailSentFrom($negate, $from) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $match = $this->lastMatchedEmail; + if(trim($negate)) { + assertNotContains($from, $match->From); + } else { + assertContains($from, $match->From); + } + } + + /** + * @Then /^the email should (not |)be sent to "([^"]*)"$/ + */ + public function theEmailSentTo($negate, $to) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $match = $this->lastMatchedEmail; + if(trim($negate)) { + assertNotContains($to, $match->To); + } else { + assertContains($to, $match->To); + } + } }