You are here

public function SimplenewsSourceTest::testSendHidden in Simplenews 8.2

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

Send a issue with the newsletter set to hidden.

File

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

Class

SimplenewsSourceTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

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

  // Set the format to HTML.
  $this
    ->drupalGet('admin/config/services/simplenews');
  $this
    ->clickLink(t('Edit'));
  $edit = [
    'opt_inout' => 'hidden',
    // @todo: This shouldn't be necessary.
    'from_address' => $this
      ->randomEmail(),
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $edit = [
    'title[0][value]' => $this
      ->randomString(10),
    'body[0][value]' => "Mail token: <strong>[simplenews-subscriber:mail]</strong>",
    'simplenews_issue[target_id]' => 'default',
  ];
  $this
    ->drupalPostForm('node/add/simplenews_issue', $edit, 'Save');
  $this
    ->assertEqual(1, preg_match('|node/(\\d+)$|', $this
    ->getUrl(), $matches), 'Node created');
  $node = Node::load($matches[1]);

  // Add node to spool.
  \Drupal::service('simplenews.spool_storage')
    ->addIssue($node);

  // Send mails.
  \Drupal::service('simplenews.mailer')
    ->sendSpool();

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

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

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