Adding more useful debugging output for emails with alot of styling

This commit is contained in:
Sriram Venkatesh 2014-06-11 11:29:52 +12:00
parent 1af1620fb4
commit fd20780345

View File

@ -121,12 +121,39 @@ class EmailContext extends BehatContext
$email = $this->lastMatchedEmail; $email = $this->lastMatchedEmail;
if($email->Content) { if($email->Content) {
assertContains($content, $email->Content); assertContains($content, $this->plaintext($email->Content));
} else { } else {
assertContains($content, $email->PlainContent); assertContains($content, $email->PlainContent);
} }
} }
/* $email->Content returns all the styles and scripts, this helper method
* strips all the scripts and tags to help debugging styled emails
* @param [type] $html [description]
* @return [type] [description]
* */
public function plaintext($html) {
// remove comments and any content found in the the comment area (strip_tags only removes the actual tags).
$plaintext = preg_replace('#<!--.*?-->#s', '', $html);
// put a space between list items (strip_tags just removes the tags).
$plaintext = preg_replace('#</li>#', ' </li>', $plaintext);
// remove all script and style tags
$plaintext = preg_replace('#<(script|style)\b[^>]*>(.*?)</(script|style)>#is', "", $plaintext);
// remove br tags (missed by strip_tags)
$plaintext = preg_replace("#<br[^>]*?>#", " ", $plaintext);
// remove all remaining html
$plaintext = strip_tags($plaintext);
// parse whitespace/spaces/linebreaks into a single line
$plaintext = preg_replace("/\s+/", ' ', $plaintext);
return $plaintext;
}
/** /**
* @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/ * @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/
*/ */