Merge pull request #10089 from silverstripe/pulls/4.9/test-mailer-sanitise-from-as-well

BUG When asserting an email was sent, sanitise both the To and From field
This commit is contained in:
Steve Boyd 2021-09-10 10:07:23 +12:00 committed by GitHub
commit 575637612a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,17 +103,18 @@ class TestMailer implements Mailer
foreach ($this->emailsSent as $email) {
$matched = true;
foreach (['To', 'From', 'Subject', 'Content'] as $field) {
// Loop all our Email fields
foreach ($compare as $field => $value) {
$emailValue = $email[$field];
if ($value = $compare[$field]) {
if ($field == 'To') {
if ($value) {
if (in_array($field, ['To', 'From'])) {
$emailValue = $this->normaliseSpaces($emailValue);
$value = $this->normaliseSpaces($value);
}
if ($value[0] == '/') {
if ($value[0] === '/') {
$matched = preg_match($value, $emailValue);
} else {
$matched = ($value == $emailValue);
$matched = ($value === $emailValue);
}
if (!$matched) {
break;