mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
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:
commit
ce9f6c9403
@ -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)
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user