You are here

public function SimplenewsSourceTest::testSendMinimalSourceImplementation in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Functional/SimplenewsSourceTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSourceTest::testSendMinimalSourceImplementation()

Tests that sending a minimal implementation of the source interface works.

File

tests/src/Functional/SimplenewsSourceTest.php, line 75

Class

SimplenewsSourceTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testSendMinimalSourceImplementation() {

  // Create a basic plaintext test source and send it.
  $plain_mail = new MailTest('plain');
  \Drupal::service('simplenews.mailer')
    ->sendMail($plain_mail);
  $mails = $this
    ->getMails();
  $mail = $mails[0];

  // Assert resulting mail.
  $this
    ->assertEqual('simplenews_node', $mail['id']);
  $this
    ->assertEqual('simplenews', $mail['module']);
  $this
    ->assertEqual('node', $mail['key']);
  $this
    ->assertEqual($plain_mail
    ->getRecipient(), $mail['to']);
  $this
    ->assertEqual($plain_mail
    ->getFromAddress(), $mail['from']);
  $this
    ->assertEqual($plain_mail
    ->getFromFormatted(), $mail['reply-to']);
  $this
    ->assertEqual($plain_mail
    ->getLanguage(), $mail['langcode']);
  $this
    ->assertTrue($mail['params']['plain']);
  $this
    ->assertFalse(isset($mail['params']['plaintext']));
  $this
    ->assertFalse(isset($mail['params']['attachments']));
  $this
    ->assertEqual($plain_mail
    ->getSubject(), $mail['subject']);
  $this
    ->assertTrue(strpos($mail['body'], 'the plain body') !== FALSE);
  $html_mail = new MailTest('html');
  \Drupal::service('simplenews.mailer')
    ->sendMail($html_mail);
  $mails = $this
    ->getMails();
  $mail = $mails[1];

  // Assert resulting mail.
  $this
    ->assertEqual('simplenews_node', $mail['id']);
  $this
    ->assertEqual('simplenews', $mail['module']);
  $this
    ->assertEqual('node', $mail['key']);
  $this
    ->assertEqual($plain_mail
    ->getRecipient(), $mail['to']);
  $this
    ->assertEqual($plain_mail
    ->getFromAddress(), $mail['from']);
  $this
    ->assertEqual($plain_mail
    ->getFromFormatted(), $mail['reply-to']);
  $this
    ->assertEqual($plain_mail
    ->getLanguage(), $mail['langcode']);
  $this
    ->assertEqual(NULL, $mail['params']['plain']);
  $this
    ->assertTrue(isset($mail['params']['plaintext']));
  $this
    ->assertTrue(strpos($mail['params']['plaintext'], 'the plain body') !== FALSE);
  $this
    ->assertTrue(isset($mail['params']['attachments']));
  $this
    ->assertEqual('example://test.png', $mail['params']['attachments'][0]['uri']);
  $this
    ->assertEqual($plain_mail
    ->getSubject(), $mail['subject']);
  $this
    ->assertTrue(strpos($mail['body'], 'the body') !== FALSE);
}