You are here

protected function EasyEmailTestBase::getSentEmails in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/EasyEmailTestBase.php \Drupal\Tests\easy_email\Functional\EasyEmailTestBase::getSentEmails()

Get sent emails captured by the Test Mail Collector.

Parameters

array $params: Parameters to use for matching emails.

Return value

array

17 calls to EasyEmailTestBase::getSentEmails()
EasyEmailSendTest::testSaveWithoutSend in tests/src/Functional/EasyEmailSendTest.php
Tests email saving without sending.
EasyEmailSendTest::testSendDuplicateCheck in tests/src/Functional/EasyEmailSendTest.php
Tests email sending with a unique key to prevent duplicates
EasyEmailSendTest::testSendHtmlAndPlainText in tests/src/Functional/EasyEmailSendTest.php
Tests sending email with an HTML and Plain Text version
EasyEmailSendTest::testSendHtmlGeneratePlainText in tests/src/Functional/EasyEmailSendTest.php
Tests email sending with plain text version generated from HTML version
EasyEmailSendTest::testSendHtmlOnly in tests/src/Functional/EasyEmailSendTest.php
Tests email sending with HTML version only

... See full list

File

tests/src/Functional/EasyEmailTestBase.php, line 129

Class

EasyEmailTestBase
Class EasyEmailTestBase

Namespace

Drupal\Tests\easy_email\Functional

Code

protected function getSentEmails(array $params) {
  \Drupal::state()
    ->resetCache();
  $captured_emails = \Drupal::state()
    ->get('system.test_mail_collector');
  $matched_emails = [];
  if (!empty($captured_emails)) {
    foreach ($captured_emails as $email) {
      $is_match = [];
      foreach ($params as $key => $value) {
        $param_match = FALSE;
        if (isset($email[$key]) && is_string($email[$key]) && $email[$key] == $value) {
          $param_match = TRUE;
        }
        elseif (isset($email['params'][$key]) && is_string($email['params'][$key]) && $email['params'][$key] == $value) {
          $param_match = TRUE;
        }
        elseif (isset($email[$key]) && $email[$key] instanceof TranslatableMarkup && $email[$key]
          ->getUntranslatedString() == $value) {
          $param_match = TRUE;
        }
        elseif (isset($email['params'][$key]) && $email['params'][$key] instanceof TranslatableMarkup && $email['params'][$key]
          ->getUntranslatedString() == $value) {
          $param_match = TRUE;
        }
        $is_match[] = $param_match;
      }
      if (count($is_match) == count(array_filter($is_match))) {
        $matched_emails[] = $email;
      }
    }
  }
  return $matched_emails;
}