mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #79 from jeffreyguo/pulls/email-contains
Updated and added new step to check the email contains text
This commit is contained in:
commit
76145df1ae
25
README.md
25
README.md
@ -655,14 +655,39 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
||||
|
||||
Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/
|
||||
- Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
|
||||
|
||||
Given /^I assign (?:(an|a|the) )"(?<type>[^"]+)" "(?<value>[^"]+)" to (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)"$/
|
||||
- Example: I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1"
|
||||
|
||||
Given /^the CMS settings have the following data$/
|
||||
- Example: Given the CMS settings has the following data
|
||||
- Note: It only works with the SilverStripe CMS module installed
|
||||
|
||||
### Environment
|
||||
|
||||
Given /^the current date is "([^"]*)"$/
|
||||
Given /^the current time is "([^"]*)"$/
|
||||
|
||||
### Email
|
||||
|
||||
Given /^there should (not |)be an email (to|from) "([^"]*)"$/
|
||||
|
||||
Given /^there should (not |)be an email (to|from) "([^"]*)" titled "([^"]*)"$/
|
||||
|
||||
Given /^the email should (not |)contain "([^"]*)"$/
|
||||
- Example: Given the email should contain "Thank you for registering!"
|
||||
|
||||
When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/
|
||||
|
||||
When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)" titled "([^"]*)"$/
|
||||
|
||||
When /^I click on the "([^"]*)" link in the email"$/
|
||||
|
||||
Given /^I clear all emails$/
|
||||
|
||||
Then /^the email should (not |)contain the following data:$/
|
||||
Example: Then the email should contain the following data:
|
||||
|
||||
### Transformations
|
||||
|
||||
Behat [transformations](http://docs.behat.org/guides/2.definitions.html#step-argument-transformations)
|
||||
|
@ -107,23 +107,30 @@ class EmailContext extends BehatContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Given the email contains "Thank you for registering!".
|
||||
* Example: Given the email should contain "Thank you for registering!".
|
||||
* Assumes an email has been identified by a previous step,
|
||||
* e.g. through 'Given there should be an email to "test@test.com"'.
|
||||
*
|
||||
* @Given /^the email should contain "([^"]*)"$/
|
||||
* @Given /^the email should (not |)contain "([^"]*)"$/
|
||||
*/
|
||||
public function thereTheEmailContains($content)
|
||||
public function thereTheEmailContains($negate, $content)
|
||||
{
|
||||
if(!$this->lastMatchedEmail) {
|
||||
throw new \LogicException('No matched email found from previous step');
|
||||
}
|
||||
|
||||
$email = $this->lastMatchedEmail;
|
||||
$emailContent = null;
|
||||
if($email->Content) {
|
||||
assertContains($content, $email->Content);
|
||||
$emailContent = $email->Content;
|
||||
} else {
|
||||
assertContains($content, $email->PlainContent);
|
||||
$emailContent = $email->PlainContent;
|
||||
}
|
||||
|
||||
if(trim($negate)) {
|
||||
assertNotContains($content, $emailContent);
|
||||
} else {
|
||||
assertContains($content, $emailContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,4 +201,39 @@ class EmailContext extends BehatContext
|
||||
$this->lastMatchedEmail = null;
|
||||
return $this->mailer->clearEmails();
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Then the email should contain the following data:
|
||||
* | row1 |
|
||||
* | row2 |
|
||||
* Assumes an email has been identified by a previous step.
|
||||
* @Then /^the email should (not |)contain the following data:$/
|
||||
*/
|
||||
public function theEmailContainFollowingData($negate, TableNode $table) {
|
||||
if(!$this->lastMatchedEmail) {
|
||||
throw new \LogicException('No matched email found from previous step');
|
||||
}
|
||||
|
||||
$email = $this->lastMatchedEmail;
|
||||
$emailContent = null;
|
||||
if($email->Content) {
|
||||
$emailContent = $email->Content;
|
||||
} else {
|
||||
$emailContent = $email->PlainContent;
|
||||
}
|
||||
// Convert html content to plain text
|
||||
$emailContent = strip_tags($emailContent);
|
||||
$rows = $table->getRows();
|
||||
|
||||
// For "should not contain"
|
||||
if(trim($negate)) {
|
||||
foreach($rows as $row) {
|
||||
assertNotContains($row[0], $emailContent);
|
||||
}
|
||||
} else {
|
||||
foreach($rows as $row) {
|
||||
assertContains($row[0], $emailContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user