mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
make matched email simple
This commit is contained in:
parent
1201cded6e
commit
64c4819e68
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user