Merge pull request #124 from jeffreyguo/pulls/click-http-link-inmail

Add new step to click the http link address in email
This commit is contained in:
Daniel Hensby 2016-08-31 17:35:36 +01:00 committed by GitHub
commit ce9f6c9403
2 changed files with 34 additions and 0 deletions

View File

@ -722,6 +722,9 @@ It's based on the `vendor/bin/behat -di @cms` output.
Then /^the email should (not |)be sent to "([^"]*)"$/
When /^I click on the http link "([^"]*)" in the email$/
- Example: When I click on the http link "http://localhost/changepassword" in the email
### Transformations
Behat [transformations](http://docs.behat.org/guides/2.definitions.html#step-argument-transformations)

View File

@ -313,4 +313,35 @@ class EmailContext extends BehatContext
assertContains($to, $match->To);
}
}
/**
* The link text is the link address itself which contains special characters
* e.g. http://localhost/Security/changepassword?m=199&title=reset
* Example: When I click on the http link "changepassword" in the email
* @When /^I click on the http link "([^"]*)" in the email$/
*/
public function iClickOnHttpLinkInEmail($httpText)
{
if (!$this->lastMatchedEmail) {
throw new \LogicException('No matched email found from previous step');
}
$email = $this->lastMatchedEmail;
$html = $email->Content;
$dom = new \DOMDocument();
$dom->loadHTML($html);
$tags = $dom->getElementsByTagName('a');
$href = null;
foreach ($tags as $tag) {
$linkText = $tag->nodeValue;
if (strpos($linkText, $httpText) !== false) {
$href = $linkText;
break;
}
}
assertNotNull($href);
return new Step\When(sprintf('I go to "%s"', $href));
}
}