Updated and added new step to check the email contains text

add text to readme for pull request 3635 in framework
This commit is contained in:
Jeffrey Guo 2014-11-14 11:47:17 +13:00
parent 752abd4447
commit 9a51b32196
2 changed files with 84 additions and 17 deletions

View File

@ -655,13 +655,38 @@ It's based on the `vendor/bin/behat -di @cms` output.
Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/ 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" - 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>[^"]+)"$/ 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" - 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 ### Environment
Given /^the current date is "([^"]*)"$/ Given /^the current date is "([^"]*)"$/
Given /^the current time 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 ### Transformations

View File

@ -107,25 +107,32 @@ 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, * Assumes an email has been identified by a previous step,
* e.g. through 'Given there should be an email to "test@test.com"'. * 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) { if(!$this->lastMatchedEmail) {
throw new \LogicException('No matched email found from previous step'); throw new \LogicException('No matched email found from previous step');
} }
$email = $this->lastMatchedEmail; $email = $this->lastMatchedEmail;
if($email->Content) { $emailContent = null;
assertContains($content, $email->Content); if($email->Content) {
} else { $emailContent = $email->Content;
assertContains($content, $email->PlainContent); } else {
} $emailContent = $email->PlainContent;
} }
if(trim($negate)) {
assertNotContains($content, $emailContent);
} else {
assertContains($content, $emailContent);
}
}
/** /**
* @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/ * @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/
@ -194,4 +201,39 @@ class EmailContext extends BehatContext
$this->lastMatchedEmail = null; $this->lastMatchedEmail = null;
return $this->mailer->clearEmails(); 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);
}
}
}
} }