From 117c1ef662aa0175e5789c61c72d74b19d6e78da Mon Sep 17 00:00:00 2001 From: Jeffrey Guo Date: Thu, 2 Jul 2015 14:12:10 +1200 Subject: [PATCH] email contains plain text --- .../BehatExtension/Context/EmailContext.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/SilverStripe/BehatExtension/Context/EmailContext.php b/src/SilverStripe/BehatExtension/Context/EmailContext.php index b6b815d..dc873a6 100644 --- a/src/SilverStripe/BehatExtension/Context/EmailContext.php +++ b/src/SilverStripe/BehatExtension/Context/EmailContext.php @@ -134,6 +134,28 @@ class EmailContext extends BehatContext } } + /** + * Example: Given the email contains "Thank you for registering!". + * Then the email should contain plain text "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 plain text "([^"]*)"$/ + */ + public function thereTheEmailContainsPlainText($content) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $email = $this->lastMatchedEmail; + $emailContent = ($email->Content) ? ($email->Content) : ($email->PlainContent); + $emailPlainText = strip_tags($emailContent); + $emailPlainText = preg_replace("/\h+/", " ", $emailPlainText); + + assertContains($content, $emailPlainText); + } + /** * @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/ */ @@ -223,6 +245,7 @@ class EmailContext extends BehatContext } // Convert html content to plain text $emailContent = strip_tags($emailContent); + $emailContent = preg_replace("/\h+/", " ", $emailContent); $rows = $table->getRows(); // For "should not contain"