You are here

function SimplenewsSourceTestCase::testSendHidden in Simplenews 7

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

Send a newsletter with the category set to hidden.

File

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

Class

SimplenewsSourceTestCase
Test cases for creating and sending newsletters.

Code

function testSendHidden() {
  $this
    ->setUpSubscribers(5);

  // Set the format to HTML.
  $this
    ->drupalGet('admin/config/services/simplenews');
  $this
    ->clickLink(t('edit newsletter category'));
  $edit = array(
    'opt_inout' => 'hidden',
    // @todo: This shouldn't be necessary.
    'from_address' => $this
      ->randomEmail(),
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $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);

  // Send mails.
  simplenews_mail_spool();

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

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

    // Verify the footer is not displayed for hidden newsletters.
    $this
      ->assertFalse(strpos($mail['body'], t('Unsubscribe from this newsletter')));
  }
}