You are here

function SimplenewsSourceTestCase::testSendMinimalSourceImplementation in Simplenews 7.2

Same name and namespace in other branches
  1. 7 tests/simplenews.test \SimplenewsSourceTestCase::testSendMinimalSourceImplementation()

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

File

tests/simplenews.test, line 2759
Simplenews test functions.

Class

SimplenewsSourceTestCase
Test cases for creating and sending newsletters.

Code

function testSendMinimalSourceImplementation() {

  // Create a basic plaintext test source and send it.
  $plain_source = new SimplenewsSourceTest('plain');
  simplenews_send_source($plain_source);
  $mails = $this
    ->drupalGetMails();
  $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_source
    ->getRecipient(), $mail['to']);
  $this
    ->assertEqual($plain_source
    ->getFromFormatted(), $mail['from']);
  $this
    ->assertEqual($plain_source
    ->getLanguage(), $mail['language']);
  $this
    ->assertTrue($mail['params']['plain']);
  $this
    ->assertFalse(isset($mail['params']['plaintext']));
  $this
    ->assertFalse(isset($mail['params']['attachments']));
  $this
    ->assertEqual($plain_source
    ->getSubject(), $mail['subject']);
  $this
    ->assertTrue(strpos($mail['body'], 'the plain body') !== FALSE);
  $this
    ->assertTrue(strpos($mail['body'], 'the plain footer') !== FALSE);
  $html_source = new SimplenewsSourceTest('html');
  simplenews_send_source($html_source);
  $mails = $this
    ->drupalGetMails();
  $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_source
    ->getRecipient(), $mail['to']);
  $this
    ->assertEqual($plain_source
    ->getFromFormatted(), $mail['from']);
  $this
    ->assertEqual($plain_source
    ->getLanguage(), $mail['language']);
  $this
    ->assertEqual(NULL, $mail['params']['plain']);
  $this
    ->assertTrue(isset($mail['params']['plaintext']));
  $this
    ->assertTrue(strpos($mail['params']['plaintext'], 'the plain body') !== FALSE);
  $this
    ->assertTrue(strpos($mail['params']['plaintext'], 'the plain footer') !== FALSE);
  $this
    ->assertTrue(isset($mail['params']['attachments']));
  $this
    ->assertEqual('example://test.png', $mail['params']['attachments'][0]['uri']);
  $this
    ->assertEqual($plain_source
    ->getSubject(), $mail['subject']);
  $this
    ->assertTrue(strpos($mail['body'], 'the body') !== FALSE);
  $this
    ->assertTrue(strpos($mail['body'], 'the footer') !== FALSE);
}