You are here

class MailTest in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Mail/MailTest.php \Drupal\simplenews\Mail\MailTest
  2. 8 src/Mail/MailTest.php \Drupal\simplenews\Mail\MailTest

Example mail implementation used for tests.

Hierarchy

Expanded class hierarchy of MailTest

1 file declares its use of MailTest
SimplenewsSourceTest.php in tests/src/Functional/SimplenewsSourceTest.php

File

src/Mail/MailTest.php, line 10

Namespace

Drupal\simplenews\Mail
View source
class MailTest implements MailInterface {

  /**
   * The mail format.
   *
   * @var string
   */
  protected $format;

  /**
   * MailTest constructor.
   *
   * @param string $format
   *   The mail format as string, either 'plain' or 'html'.
   */
  public function __construct($format) {
    $this->format = $format;
  }

  /**
   * {@inheritdoc}
   */
  public function getAttachments() {
    return [
      [
        'uri' => 'example://test.png',
        'filemime' => 'x-example',
        'filename' => 'test.png',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getBody() {
    return $this
      ->getFormat() == 'plain' ? $this
      ->getPlainBody() : 'the body';
  }

  /**
   * {@inheritdoc}
   */
  public function getFormat() {
    return $this->format;
  }

  /**
   * {@inheritdoc}
   */
  public function getFromAddress() {
    return 'simpletest@example.com';
  }

  /**
   * {@inheritdoc}
   */
  public function getFromFormatted() {
    return 'Test <simpletest@example.com>';
  }

  /**
   * {@inheritdoc}
   */
  public function getHeaders(array $headers) {
    $headers['X-Simplenews-Test'] = 'OK';
    return $headers;
  }

  /**
   * {@inheritdoc}
   */
  public function getKey() {
    return 'node';
  }

  /**
   * {@inheritdoc}
   */
  public function setKey($key) {
  }

  /**
   * {@inheritdoc}
   */
  public function getLanguage() {
    return 'en';
  }

  /**
   * {@inheritdoc}
   */
  public function getPlainBody() {
    return 'the plain body';
  }

  /**
   * {@inheritdoc}
   */
  public function getRecipient() {
    return 'recipient@example.org';
  }

  /**
   * {@inheritdoc}
   */
  public function getSubject() {
    return 'the subject';
  }

  /**
   * {@inheritdoc}
   */
  public function getTokenContext() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getIssue() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getSubscriber() {
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MailTest::$format protected property The mail format.
MailTest::getAttachments public function Returns an array of attachments for this newsletter mail. Overrides MailInterface::getAttachments
MailTest::getBody public function Returns the mail body. Overrides MailInterface::getBody
MailTest::getFormat public function Returns the mail format. Overrides MailInterface::getFormat
MailTest::getFromAddress public function Returns the plain mail address. Overrides MailInterface::getFromAddress
MailTest::getFromFormatted public function Returns the formatted from mail address. Overrides MailInterface::getFromFormatted
MailTest::getHeaders public function Returns the mail headers. Overrides MailInterface::getHeaders
MailTest::getIssue public function Returns the newsletter issue entity. Overrides MailInterface::getIssue
MailTest::getKey public function Returns the mail key to be used for mails. Overrides MailInterface::getKey
MailTest::getLanguage public function The language that should be used for this newsletter mail. Overrides MailInterface::getLanguage
MailTest::getPlainBody public function Returns the plaintext body. Overrides MailInterface::getPlainBody
MailTest::getRecipient public function Returns the recipient of this newsletter mail. Overrides MailInterface::getRecipient
MailTest::getSubject public function Returns the mail subject. Overrides MailInterface::getSubject
MailTest::getSubscriber public function Returns the subscriber object. Overrides MailInterface::getSubscriber
MailTest::getTokenContext public function Returns the token context to be used with token replacements. Overrides MailInterface::getTokenContext
MailTest::setKey public function Set the mail key. Overrides MailInterface::setKey
MailTest::__construct public function MailTest constructor.