Merge pull request #91 from jeffreyguo/pulls/email-from-to-titled

Find email by title then check the recipents
This commit is contained in:
Ingo Schommer 2016-01-08 10:43:29 +13:00
commit efd8f65c33
2 changed files with 58 additions and 0 deletions

View File

@ -709,6 +709,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)

View File

@ -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);
}
}
}