You are here

function SimplenewsSourceTestCase::testSendNoCaching in Simplenews 7

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

Test with disabled caching.

File

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

Class

SimplenewsSourceTestCase
Test cases for creating and sending newsletters.

Code

function testSendNoCaching() {
  $this
    ->setUpSubscribers(100);

  // Disable caching.
  $edit = array(
    'simplenews_source_cache' => 'SimplenewsSourceCacheNone',
  );
  $this
    ->drupalPost('admin/config/services/simplenews/settings/mail', $edit, t('Save configuration'));
  $edit = array(
    'title' => $this
      ->randomName(),
    'body[und][0][value]' => "Mail token: <strong>[simplenews-subscriber:mail]</strong>",
  );
  $this
    ->drupalPost('node/add/simplenews', $edit, 'Save');
  $this
    ->assertTrue(preg_match('|node/(\\d+)$|', $this
    ->getUrl(), $matches), 'Node created');
  $node = node_load($matches[1]);

  // Add node to spool.
  simplenews_add_node_to_spool($node);
  $before = microtime(TRUE);
  simplenews_mail_spool();
  $after = microtime(TRUE);

  // Make sure that 100 mails have been sent.
  $this
    ->assertEqual(100, count($this
    ->drupalGetMails()));

  // Test that tokens are correctly replaced.
  foreach (array_slice($this
    ->drupalGetMails(), 0, 3) as $mail) {

    // Make sure that the same mail was used in the body token as it has been
    // sent to. Also verify that the mail is plaintext.
    $this
      ->assertTrue(strpos($mail['body'], '*' . $mail['to'] . '*') !== FALSE);
    $this
      ->assertFalse(strpos($mail['body'], '<strong>'));

    // Make sure the body is only attached once.
    $this
      ->assertEqual(1, preg_match_all('/Mail token/', $mail['body'], $matches));
  }

  // Report time. @todo: Find a way to actually do some assertions here.
  $this
    ->pass(t('Mails have been sent in @sec seconds with caching disabled.', array(
    '@sec' => round($after - $before, 3),
  )));
}