make matched email simple

This commit is contained in:
Jeffrey Guo 2015-07-21 16:27:09 +12:00
parent 1201cded6e
commit 64c4819e68
2 changed files with 58 additions and 0 deletions

View File

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

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